Contributing to behave-model¶
Thank you for your interest in contributing! This guide covers everything you need to get started.
Development setup¶
git clone https://github.com/MathiasPaulenko/behave-model.git
cd behave-model
pip install -e ".[dev]"
This installs behave-model with all development dependencies:
pytestandpytest-cov— testing and coverageruff— linting and formattingmkdocsandmkdocs-material— documentation buildingbuildandtwine— package building and validation
Running tests¶
# Run all tests
python -m pytest tests/ -v
# Run with coverage
python -m pytest tests/ --cov=behave_model --cov-report=term-missing
# Run a specific test file
python -m pytest tests/test_model.py -v
# Run only rule tests
python -m pytest tests/test_rules.py -v
Linting and formatting¶
# Check linting
ruff check behave_model/ tests/
# Auto-fix linting issues
ruff check --fix behave_model/ tests/
# Check formatting
ruff format --check behave_model/ tests/
# Apply formatting
ruff format behave_model/ tests/
Building documentation¶
# Serve docs locally with live reload
mkdocs serve
# Build static site
mkdocs build
# Build and view in browser
mkdocs serve --dev-addr 127.0.0.1:8000
Building the package¶
Project structure¶
behave-model/
├── behave_model/ # Source code
│ ├── __init__.py # Public API exports
│ ├── exceptions.py # Exception hierarchy
│ ├── model/ # Domain model classes
│ ├── parser/ # Parser adapter
│ ├── visitors/ # Visitor pattern
│ ├── queries.py # Query functions
│ ├── serializers/ # Dict, JSON, PrettyPrinter
│ ├── transformations/ # In-place mutations
│ └── validation/ # Validation framework
├── tests/ # Test suite
├── examples/ # Example .feature files
├── docs/ # MkDocs documentation
├── .github/workflows/ # CI/CD workflows
├── pyproject.toml # Package configuration
├── mkdocs.yml # Documentation configuration
└── Makefile # Common tasks
Adding a new validation rule¶
- Create a class extending
ValidationRuleinbehave_model/validation/ - Implement the
check(project)method returninglist[ValidationIssue] - Add it to the default rules in
Validator.__init__if it should be on by default - Add tests in
tests/test_validation.py - Update
CHANGELOG.md
from behave_model import ValidationRule, ValidationIssue
class MyCustomRule(ValidationRule):
name = "MyCustomRule"
severity = "warning"
def check(self, project):
issues = []
# ... your logic ...
return issues
Adding a new serializer¶
- Create a new serializer class in
behave_model/serializers/ - Follow the pattern of
DictSerializerorJsonSerializer - Export it from
behave_model/serializers/__init__.pyandbehave_model/__init__.py - Add tests
- Update
CHANGELOG.md
Adding a new transformation¶
- Add the function in
behave_model/transformations/ - Export it from
__init__.pyfiles - Add tests in
tests/test_transformation.py - Update
CHANGELOG.md
Adding a new model class¶
- Create the dataclass in
behave_model/model/ - Add
Locationandaccept(visitor)if it should be visitable - Add a
visit_*method to the baseVisitor - Update
CountingVisitorandCollectingVisitor - Update serializers and pretty printer
- Export from
behave_model/__init__.py - Add tests
- Update
CHANGELOG.md
Pull request checklist¶
- [ ] Tests pass (
pytest tests/ -v) - [ ] Coverage remains above 90%
- [ ] Linting passes (
ruff check behave_model/ tests/) - [ ] Formatting passes (
ruff format --check behave_model/ tests/) - [ ]
CHANGELOG.mdupdated - [ ] Documentation updated if needed
Reporting bugs¶
Please use GitHub Issues to report bugs. Include:
- Python version
- Behave version
- Minimal reproduction case
- Expected vs actual behavior