Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[tool:pytest]
testpaths = tests
python_files = test_*.py
python_classes = Test*
python_functions = test_*
addopts = -v --tb=short
1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest==8.4.2
33 changes: 33 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Python Tests

based on pytest.

## Running Tests

Make sure to install test dependencies: `pip install -r requirements-test.txt`.

### All Tests

```bash
pytest
```


### Specific Test File
```bash
pytest tests/test_yaml_parser.py -v
```

### Specific Test Class
```bash
pytest tests/test_yaml_parser.py::TestYamlParser -v
```

### Specific Test Function
```bash
pytest tests/test_yaml_parser.py::TestYamlParser::test_yaml_parser_basic_functionality -v
```

## Test Configuration

See `pytest.ini` in the root directory.
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# this file makes the tests directory a Python package
92 changes: 92 additions & 0 deletions tests/test_yaml_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
"""
Basic tests for YAML parsing functionality in the taskflow agent.

Simple parsing + parsing of example taskflows.
"""

import pytest
import tempfile
from pathlib import Path
import yaml
from yaml_parser import YamlParser


class TestYamlParser:
"""Test suite for YamlParser class."""

def test_yaml_parser_basic_functionality(self):
"""Test basic YAML parsing functionality."""
# create a temporary directory with test yaml files
with tempfile.TemporaryDirectory() as temp_dir:
temp_path = Path(temp_dir)
test_yaml_content = {
'seclab-taskflow-agent': {
'type': 'taskflow',
'version': 1
},
'taskflow': [
{
'task': {
'agents': ['assistant'],
'user_prompt': 'Test prompt'
}
}
]
}

test_file = temp_path / 'test_taskflow.yaml'
with open(test_file, 'w') as f:
yaml.dump(test_yaml_content, f)

parser = YamlParser(temp_path)
# get all yaml files in the directory
yaml_files = temp_path.glob('*.yaml')
result = parser.get_yaml_dict(yaml_files)

assert 'test_taskflow.yaml' in result
assert result['test_taskflow.yaml']['seclab-taskflow-agent']['type'] == 'taskflow'
assert len(result['test_taskflow.yaml']['taskflow']) == 1
assert result['test_taskflow.yaml']['taskflow'][0]['task']['agents'] == ['assistant']


class TestRealTaskflowFiles:
"""Test parsing of actual taskflow files in the project."""

def test_parse_example_taskflows(self):
"""Test parsing the actual example taskflow files."""
# this test uses the actual taskflows in the project
examples_path = Path('taskflows/examples').absolute()
parser = YamlParser(examples_path)

# Get all YAML files in the examples directory
yaml_files = examples_path.glob('*.yaml')
result = parser.get_yaml_dict(yaml_files)

# should contain example files
assert len(result) > 0

# check that example.yaml is parsed correctly
example_task_flow = result['example.yaml']
assert 'taskflow' in example_task_flow
assert isinstance(example_task_flow['taskflow'], list)
assert len(example_task_flow['taskflow']) == 4 # 4 tasks in taskflow
assert example_task_flow['taskflow'][0]['task']['max_steps'] == 20

def test_parse_all_taskflows(self):
"""Test parsing all example taskflow files in the project."""
taskflows_path = Path('taskflows').absolute()
parser = YamlParser(taskflows_path)

yaml_files = taskflows_path.rglob('*.yaml')
result = parser.get_yaml_dict(yaml_files)

# should contain all taskflow files (including subdirs)
assert len(result) == 13

# check access for files with directory structure in names
example_files = [key for key in result.keys() if 'examples/' in key]
assert len(example_files) > 0


if __name__ == '__main__':
pytest.main([__file__, '-v'])