1+ """ 
2+ Basic tests for YAML parsing functionality in the taskflow agent. 
3+ 
4+ Simple parsing + parsing of example taskflows. 
5+ """ 
6+ 
7+ import  pytest 
8+ import  tempfile 
9+ from  pathlib  import  Path 
10+ import  yaml 
11+ from  yaml_parser  import  YamlParser 
12+ 
13+ 
14+ class  TestYamlParser :
15+     """Test suite for YamlParser class.""" 
16+ 
17+     def  test_yaml_parser_basic_functionality (self ):
18+         """Test basic YAML parsing functionality.""" 
19+         # create a temporary directory with test yaml files 
20+         with  tempfile .TemporaryDirectory () as  temp_dir :
21+             test_yaml_content  =  {
22+                 'seclab-taskflow-agent' : {
23+                     'type' : 'taskflow' ,
24+                     'version' : 1 
25+                 },
26+                 'taskflow' : [
27+                     {
28+                         'task' : {
29+                             'agents' : ['assistant' ],
30+                             'user_prompt' : 'Test prompt' 
31+                         }
32+                     }
33+                 ]
34+             }
35+             
36+             test_file  =  Path (temp_dir ) /  'test_taskflow.yaml' 
37+             with  open (test_file , 'w' ) as  f :
38+                 yaml .dump (test_yaml_content , f )
39+             
40+             # Test parsing 
41+             parser  =  YamlParser (temp_dir )
42+             result  =  parser .get_yaml_dict (recurse = False )
43+             
44+             assert  'test_taskflow'  in  result 
45+             assert  result ['test_taskflow' ]['seclab-taskflow-agent' ]['type' ] ==  'taskflow' 
46+             assert  len (result ['test_taskflow' ]['taskflow' ]) ==  1 
47+             assert  result ['test_taskflow' ]['taskflow' ][0 ]['task' ]['agents' ] ==  ['assistant' ]
48+ 
49+ 
50+ class  TestRealTaskflowFiles :
51+     """Test parsing of actual taskflow files in the project.""" 
52+ 
53+     def  test_parse_example_taskflows (self ):
54+         """Test parsing the actual example taskflow files.""" 
55+         # this test uses the actual taskflows in the project 
56+         parser  =  YamlParser ('taskflows/examples' )
57+         result  =  parser .get_yaml_dict ()
58+         
59+         # should contain example files 
60+         assert  len (result ) >  0 
61+ 
62+         # check that example.yaml is parsed correctly 
63+         example_task_flow  =  result ['example' ]
64+         assert  'taskflow'  in  example_task_flow 
65+         assert  isinstance (example_task_flow ['taskflow' ], list )
66+         assert  len (example_task_flow ['taskflow' ]) ==   4  # 4 tasks in taskflow 
67+         assert  example_task_flow ['taskflow' ][0 ]['task' ]['max_steps' ] ==  20 
68+ 
69+     def  test_parse_all_taskflows (self ):
70+         """Test parsing all example taskflow files in the project.""" 
71+         parser  =  YamlParser ('taskflows' )
72+         result  =  parser .get_yaml_dict (recurse = True , dir_namespace = True )
73+         
74+         # should contain all taskflow files (including subdirs) 
75+         assert  len (result ) ==  13 
76+         
77+         # check access for files with namespacing 
78+         example_files  =  [key  for  key  in  result .keys () if  key .startswith ('examples/' )]
79+         assert  len (example_files ) >  0 
80+ 
81+ 
82+ if  __name__  ==  '__main__' :
83+     pytest .main ([__file__ , '-v' ])
0 commit comments