Skip to content

Commit a1796fc

Browse files
committed
initial pytest setup with initial TestYamlParser tests
1 parent 9b21777 commit a1796fc

File tree

5 files changed

+124
-0
lines changed

5 files changed

+124
-0
lines changed

pytest.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[tool:pytest]
2+
testpaths = tests
3+
python_files = test_*.py
4+
python_classes = Test*
5+
python_functions = test_*
6+
addopts = -v --tb=short

requirements-test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pytest==8.4.2

tests/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Python Tests
2+
3+
based on pytest.
4+
5+
## Running Tests
6+
7+
Make sure to install test dependencies: `pip install -r requirements-test.txt`.
8+
9+
### All Tests
10+
11+
```bash
12+
pytest
13+
```
14+
15+
16+
### Specific Test File
17+
```bash
18+
pytest tests/test_yaml_parser.py -v
19+
```
20+
21+
### Specific Test Class
22+
```bash
23+
pytest tests/test_yaml_parser.py::TestYamlParser -v
24+
```
25+
26+
### Specific Test Function
27+
```bash
28+
pytest tests/test_yaml_parser.py::TestYamlParser::test_yaml_parser_basic_functionality -v
29+
```
30+
31+
## Test Configuration
32+
33+
See `pytest.ini` in the root directory.

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# this file makes the tests directory a Python package

tests/test_yaml_parser.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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

Comments
 (0)