11import pytest
2- from vision_agents .core .instructions import Instructions
2+ from vision_agents .core .instructions import Instructions , InstructionsReadError
33
44
55class TestInstructions :
@@ -28,40 +28,29 @@ def test_parse_not_a_file(self, tmp_path):
2828 file_path = tmp_path / "file1.md"
2929 file_path .mkdir ()
3030 input_text = "read @file1.md"
31- instructions = Instructions (input_text = input_text , base_dir = tmp_path )
32- assert instructions .input_text == input_text
33- assert (
34- instructions .full_reference
35- == f"{ input_text } \n \n \n ## Referenced Documentation:\n \n ### file1.md\n *(File not found or could not be read)*"
36- )
31+ with pytest .raises (InstructionsReadError , match = "reason - path is not a file" ):
32+ Instructions (input_text = input_text , base_dir = tmp_path )
3733
3834 def test_parse_file_doesnt_exist (self , tmp_path ):
3935 input_text = "read @file1.md"
40- instructions = Instructions (input_text = input_text , base_dir = tmp_path )
41- assert instructions .input_text == input_text
42- assert (
43- instructions .full_reference
44- == f"{ input_text } \n \n \n ## Referenced Documentation:\n \n ### file1.md\n *(File not found or could not be read)*"
45- )
36+ with pytest .raises (InstructionsReadError , match = "reason - file not found" ):
37+ Instructions (input_text = input_text , base_dir = tmp_path )
4638
4739 def test_parse_file_not_md (self , tmp_path ):
4840 input_text = "read @file1.txt"
4941 file_path = tmp_path / "file1.txt"
5042 file_path .write_text ("abcdef" , encoding = "utf-8" )
51- instructions = Instructions (input_text = input_text , base_dir = tmp_path )
52- assert instructions .input_text == input_text
53- assert instructions .full_reference == input_text
43+ with pytest .raises (InstructionsReadError , match = "reason - file is not .md" ):
44+ Instructions (input_text = input_text , base_dir = tmp_path )
5445
5546 def test_parse_file_hidden (self , tmp_path ):
5647 input_text = "read @.file1.md"
5748 file_path = tmp_path / ".file1.md"
5849 file_path .write_text ("abcdef" , encoding = "utf-8" )
59- instructions = Instructions (input_text = input_text , base_dir = tmp_path )
60- assert instructions .input_text == input_text
61- assert (
62- instructions .full_reference
63- == f"{ input_text } \n \n \n ## Referenced Documentation:\n \n ### .file1.md\n *(File not found or could not be read)*"
64- )
50+ with pytest .raises (
51+ InstructionsReadError , match = 'reason - filename cannot start with "."'
52+ ):
53+ Instructions (input_text = input_text , base_dir = tmp_path )
6554
6655 def test_parse_file_outside_base_dir (self , tmp_path ):
6756 file_path1 = tmp_path / "file1.md"
@@ -73,9 +62,7 @@ def test_parse_file_outside_base_dir(self, tmp_path):
7362 file_path1 .write_text ("abcdef" , encoding = "utf-8" )
7463 file_path2 .write_text ("abcdef" , encoding = "utf-8" )
7564
76- instructions = Instructions (input_text = input_text , base_dir = base_dir )
77- assert instructions .input_text == input_text
78- assert (
79- instructions .full_reference
80- == f"{ input_text } \n \n \n ## Referenced Documentation:\n \n ### { file_path1 } \n *(File not found or could not be read)*"
81- )
65+ with pytest .raises (
66+ InstructionsReadError , match = "reason - path outside the base directory"
67+ ):
68+ Instructions (input_text = input_text , base_dir = base_dir )
0 commit comments