Skip to main content

Generate test scaffolds from Code2Logic output files

Project description

Logic2Test - Test Generation from Logic Files

PyPI version Python 3.9+ License: Apache 2.0 Code style: black

Generate test scaffolds from Code2Logic output files.

Reads YAML, Hybrid YAML, or TOON format files and produces pytest-compatible test suites.

✨ Features

  • 🧪 Unit tests - Test scaffolds for classes and functions
  • 🔗 Integration tests - Cross-module interaction tests
  • 📊 Property tests - Hypothesis-based property testing
  • 🎯 Smart mocking - Auto-generated mocks based on type hints
  • 📝 Pytest style - Ready-to-run pytest test files

🚀 Installation

pip install logic2test

Or with optional dependencies:

pip install logic2test[hypothesis]  # Property testing support

📖 Quick Start

CLI

# Show what can be generated
logic2test out/code2logic/project.c2l.yaml --summary

# Generate unit tests
logic2test out/code2logic/project.c2l.yaml -o out/logic2test/tests/

# Generate all test types
logic2test out/code2logic/project.c2l.yaml -o out/logic2test/tests/ --type all

# Include private methods
logic2test out/code2logic/project.c2l.yaml -o out/logic2test/tests/ --include-private

Python API

from logic2test import TestGenerator

# Create generator
generator = TestGenerator('out/code2logic/project.c2l.yaml')

# Get summary
summary = generator.summary()
print(f"Classes: {summary['testable_classes']}")
print(f"Functions: {summary['testable_functions']}")

# Generate unit tests
result = generator.generate_unit_tests('out/logic2test/tests/')
print(f"Generated {result.tests_generated} tests")

# Generate all test types
result = generator.generate_all('out/logic2test/tests/')

📋 Generated Test Structure

tests/
├── unit/
│   ├── test_analyzer.py
│   ├── test_parsers.py
│   └── test_generators.py
├── integration/
│   └── test_integration.py
└── property/
    └── test_properties.py

Example Generated Test

def test_analyze_project():
    """Test analyze_project function."""
    # Arrange
    path = "/tmp/test_path"
    use_treesitter = Mock()
    verbose = False

    # Act
    # result = analyze_project(path, use_treesitter, verbose)

    # Assert
    assert result is not None  # TODO: Add specific assertion

🖥️ CLI Reference

Option Description
-o, --output DIR Output directory for tests
-t, --type TYPE Test type: unit, integration, property, all
--framework FW Test framework: pytest, unittest
--include-private Include private methods
--include-dunder Include dunder methods
--summary Show summary without generating
-v, --verbose Verbose output

⚙️ Configuration

from logic2test import TestGenerator, GeneratorConfig

config = GeneratorConfig(
    framework='pytest',
    include_private=False,
    include_dunder=False,
    max_tests_per_file=50,
    output_prefix='test_',
    generate_class_tests=True,
    generate_function_tests=True,
    generate_dataclass_tests=True,
)

generator = TestGenerator('project.c2l.yaml', config)

📥 Supported Input Formats

Format Extension Description
YAML .yaml Standard Code2Logic output
Hybrid .hybrid.yaml Compact YAML with metadata
TOON .toon Token-Oriented Object Notation

🧰 Monorepo (code2logic) workflow

If you use logic2test inside the code2logic monorepo, you can manage all packages from the repository root:

make test-all
make build-subpackages
make publish-all

See: docs/19-monorepo-workflow.md.

🧪 Development

# Install dev dependencies
make install-dev

# Run tests
make test

# Format code
make format

# Lint
make lint

# Build package
make build

# Publish to PyPI
make publish

📄 License

Apache 2.0 License - see LICENSE for details.

🔗 Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

logic2test-0.1.6.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logic2test-0.1.6-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file logic2test-0.1.6.tar.gz.

File metadata

  • Download URL: logic2test-0.1.6.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for logic2test-0.1.6.tar.gz
Algorithm Hash digest
SHA256 ea9506034ee6452cbfc8fd6ff62179f67cd6a36d3244128abd89d91494561827
MD5 4bbfc08f0fe55daff037536a5bb73379
BLAKE2b-256 14c0b6eaee76e530c19adde52f225899a3df840304dc5a18fd06ce681afd1e93

See more details on using hashes here.

File details

Details for the file logic2test-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: logic2test-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for logic2test-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 d8325b8f2ab5a6cd7bda16627b2a2b17392ea2e12fae2477f516ae21a7f399d1
MD5 20d775bb6136d5dbaf702ef7a7f2c589
BLAKE2b-256 0f01730335e327ce492871bf978e1840394a61c3f4a9f1f2459c0625c0dc6baf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page