Logic2Test - Test Generation from Logic Files
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
Metadata
Release files for logic2test 0.1.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| logic2test-0.1.10.tar.gz | 4.3 kB | Without provenance | Details for logic2test-0.1.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| logic2test-0.1.10-py3-none-any.whl | Python 3 | none | any | Details for logic2test-0.1.10-py3-none-any.whl |
Total release size: 7.8 kB
Release files / logic2test-0.1.10.tar.gz
| Download URL | logic2test-0.1.10.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3894ca51a9056af8f86fa3bb4cc0f3b15b8230371427aa531cb17ba34baa3e5a
|
|
BLAKE2b-256 checksum How to use checksums |
166954df722afcc24ca06c3b91fe5b5bca69609d143b7c350b8f08fdf5bec139
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / logic2test-0.1.10-py3-none-any.whl
| Download URL | logic2test-0.1.10-py3-none-any.whl |
|---|---|
| Size | 3.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
92737bf62589c52ba096689c195a89955387aa4a6d03a00221e22a711361897b
|
|
BLAKE2b-256 checksum How to use checksums |
0e587f6c76fbc0deddd95e36dc16c9c71a55e744dc71e994dc327c6f2710cda4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for logic2test 0.1.10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.