88import tempfile
99from pathlib import Path
1010import yaml
11- from yaml_parser import YamlParser
12-
11+ from available_tools import AvailableToolType , AvailableTools
1312
1413class TestYamlParser :
1514 """Test suite for YamlParser class."""
1615
1716 def test_yaml_parser_basic_functionality (self ):
1817 """Test basic YAML parsing functionality."""
19- # create a temporary directory with test yaml files
20- with tempfile .TemporaryDirectory () as temp_dir :
21- temp_path = Path (temp_dir )
22- test_yaml_content = {
23- 'seclab-taskflow-agent' : {
24- 'type' : 'taskflow' ,
25- 'version' : 1
26- },
27- 'taskflow' : [
28- {
29- 'task' : {
30- 'agents' : ['assistant' ],
31- 'user_prompt' : 'Test prompt'
32- }
33- }
34- ]
35- }
36-
37- test_file = temp_path / 'test_taskflow.yaml'
38- with open (test_file , 'w' ) as f :
39- yaml .dump (test_yaml_content , f )
40-
41- parser = YamlParser (temp_path )
42- # get all yaml files in the directory
43- yaml_files = temp_path .glob ('*.yaml' )
44- result = parser .get_yaml_dict (yaml_files )
45-
46- assert 'test_taskflow.yaml' in result
47- assert result ['test_taskflow.yaml' ]['seclab-taskflow-agent' ]['type' ] == 'taskflow'
48- assert len (result ['test_taskflow.yaml' ]['taskflow' ]) == 1
49- assert result ['test_taskflow.yaml' ]['taskflow' ][0 ]['task' ]['agents' ] == ['assistant' ]
50-
18+ available_tools = AvailableTools ()
19+ personality000 = available_tools .get_personality (
20+ "tests.data.test_yaml_parser_personality000" )
21+
22+ assert personality000 ['seclab-taskflow-agent' ]['version' ] == 1
23+ assert personality000 ['seclab-taskflow-agent' ]['filetype' ] == 'personality'
24+ assert personality000 ['personality' ] == 'You are a helpful assistant.\n '
25+ assert personality000 ['task' ] == 'Answer any question.\n '
5126
5227class TestRealTaskflowFiles :
5328 """Test parsing of actual taskflow files in the project."""
5429
5530 def test_parse_example_taskflows (self ):
56- """Test parsing the actual example taskflow files."""
31+ """Test parsing example taskflow files."""
5732 # this test uses the actual taskflows in the project
58- examples_path = Path ('taskflows/examples' ).absolute ()
59- parser = YamlParser (examples_path )
60-
61- # Get all YAML files in the examples directory
62- yaml_files = examples_path .glob ('*.yaml' )
63- result = parser .get_yaml_dict (yaml_files )
64-
65- # should contain example files
66- assert len (result ) > 0
33+ available_tools = AvailableTools ()
6734
6835 # check that example.yaml is parsed correctly
69- example_task_flow = result ['example.yaml' ]
36+ example_task_flow = available_tools .get_taskflow (
37+ "taskflows.examples.example" )
7038 assert 'taskflow' in example_task_flow
7139 assert isinstance (example_task_flow ['taskflow' ], list )
7240 assert len (example_task_flow ['taskflow' ]) == 4 # 4 tasks in taskflow
7341 assert example_task_flow ['taskflow' ][0 ]['task' ]['max_steps' ] == 20
7442
75- def test_parse_all_taskflows (self ):
76- """Test parsing all example taskflow files in the project."""
77- taskflows_path = Path ('taskflows' ).absolute ()
78- parser = YamlParser (taskflows_path )
79-
80- yaml_files = taskflows_path .rglob ('*.yaml' )
81- result = parser .get_yaml_dict (yaml_files )
82-
83- # should contain all taskflow files (including subdirs)
84- assert len (result ) == 13
85-
86- # check access for files with directory structure in names
87- example_files = [key for key in result .keys () if 'examples/' in key ]
88- assert len (example_files ) > 0
89-
90-
9143if __name__ == '__main__' :
92- pytest .main ([__file__ , '-v' ])
44+ pytest .main ([__file__ , '-v' ])
0 commit comments