Skip to content

Test Suite Organization

Overview

The test suite for yaml-workflow is organized into multiple layers, each focusing on different aspects of the system. This organization helps maintain clear boundaries between components and makes it easier to understand and maintain the test suite.

Test Structure

Core Layer: Template Engine Tests

File: tests/test_template.py

Tests the fundamental template engine implementation (TemplateEngine class), focusing on: - Template compilation and caching mechanisms - Variable resolution and type information handling - Error handling and reporting - Cache management - Basic template processing operations

Example:

def test_process_template(template_engine, variables):
    """Test processing a template."""
    template = "Input: {{ args.input_file }}, Output: {{ args.output_file }}"
    result = template_engine.process_template(template, variables)
    assert result == "Input: input.txt, Output: output.txt"

Integration Layer: Workflow Engine Template Tests

File: tests/test_engine_template.py

Tests the integration between the workflow engine and template system, covering: - Template resolution within workflow context - Step input resolution - Error message templating - Workflow-specific template operations

Example:

def test_resolve_template_simple(engine):
    """Test simple template resolution."""
    result = engine.resolve_template("File: {{ args.input_file }}")
    assert result == "File: test.txt"

Task Layer: Template Tasks Tests

File: tests/test_template_tasks.py

Tests the high-level template task handlers that users interact with directly: - Template rendering to files - Complex template features (loops, conditionals) - Template filters and modifiers - File-based templates - Whitespace control - Template includes (planned feature)

Example:

def test_template_with_loops(temp_workspace, template_context):
    """Test template rendering with loops."""
    step = {
        "template": """Items:
{% for item in items %}
- {{ item }}
{% endfor %}""",
        "output": "items.txt",
    }
    result = render_template(step, template_context, temp_workspace)

Test Categories

Our tests are organized into several categories:

  1. Unit Tests
  2. Test individual components in isolation
  3. Focus on specific functionality
  4. Fast execution
  5. High coverage

  6. Integration Tests

  7. Test component interactions
  8. Verify system behavior
  9. End-to-end workflow testing

  10. Error Handling Tests

  11. Verify error conditions
  12. Test error messages
  13. Validate error recovery

  14. Performance Tests

  15. Test caching mechanisms
  16. Verify resource usage
  17. Check execution time

Running Tests

Basic Test Execution

# Run all tests
pytest tests/

# Run specific test file
pytest tests/test_template.py

# Run with coverage
pytest tests/ --cov=yaml_workflow

Test Options

  • -v: Verbose output
  • -k "test_name": Run tests matching pattern
  • --pdb: Debug on test failure
  • --cov-report html: Generate HTML coverage report

Writing New Tests

When adding new tests:

  1. Choose the Right Layer
  2. Core layer for fundamental operations
  3. Integration layer for component interactions
  4. Task layer for user-facing features

  5. Follow Naming Conventions

  6. Use descriptive test names
  7. Group related tests together
  8. Include both positive and negative test cases

  9. Use Fixtures

  10. Create reusable test data
  11. Share common setup code
  12. Keep tests focused and clean

  13. Document Test Purpose

  14. Add clear docstrings
  15. Explain test scenarios
  16. Document expected behavior

Test Dependencies

The test suite requires additional dependencies, which can be installed using:

pip install -e ".[test]"

Key test dependencies include: - pytest: Testing framework - pytest-cov: Coverage reporting - pytest-mock: Mocking support

Future Improvements

Planned enhancements to the test suite:

  1. Template Features
  2. Add support for template includes
  3. Enhance error reporting
  4. Add more complex template scenarios

  5. Performance Testing

  6. Add benchmarks
  7. Test large template processing
  8. Measure memory usage

  9. Integration Testing

  10. Add more end-to-end tests
  11. Test external integrations
  12. Add stress testing