speech-driven-animation
speech-driven-animation copied to clipboard
feat: Set up comprehensive Python testing infrastructure with Poetry
Set Up Python Testing Infrastructure
Summary
This PR establishes a comprehensive testing infrastructure for the SDA (Speech-Driven Animations) project using Poetry as the package manager and pytest as the testing framework. The setup provides a solid foundation for developers to write and run tests efficiently.
Changes Made
Package Management Migration
- Migrated from setup.py to Poetry: Created
pyproject.tomlwith all existing dependencies migrated fromsetup.py - Poetry Configuration: Set up Poetry as the modern Python package manager with proper dependency management
- Lock File Policy: Configured
.gitignoreto trackpoetry.lockfor reproducible builds
Testing Framework Setup
- Testing Dependencies: Added as development dependencies:
pytest(^7.4.0) - Core testing frameworkpytest-cov(^4.1.0) - Coverage reportingpytest-mock(^3.12.0) - Mocking utilities
Testing Configuration
-
Pytest Configuration in
pyproject.toml:- Strict markers and configuration enforcement
- Coverage reporting with HTML and XML output formats
- 80% coverage threshold requirement
- Custom test markers:
unit,integration,slow - Test discovery patterns for
test_*.pyand*_test.py
-
Coverage Configuration:
- Source tracking for the
sdapackage - Exclusions for test files, migrations, and boilerplate code
- Multiple report formats (terminal, HTML, XML)
- Source tracking for the
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared pytest fixtures
├── test_setup_validation.py # Validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Test Fixtures (conftest.py)
Created comprehensive fixtures for common testing needs:
temp_dir: Temporary directory managementsample_audio_data: NumPy array audio datasample_image_data: NumPy array image datasample_tensor: PyTorch tensor samplesmock_config: Configuration dictionariessample_model_weights: Model weight filessample_audio_file: WAV file creationsample_image_file: PNG file creationreset_random_seeds: Automatic seed resettinggpu_available: GPU availability checkmock_env_vars: Environment variable mockingcapture_logs: Log message capturing
Development Experience
- Poetry Scripts: Run tests with either:
poetry run testpoetry run tests
- Standard pytest options: All pytest CLI options remain available
- Coverage Reports: Generated in
htmlcov/directory andcoverage.xml
Other Changes
- Updated .gitignore: Added entries for:
- Testing artifacts (
.pytest_cache/,.coverage,htmlcov/, etc.) - Virtual environments
- IDE files
- Claude-specific directories (
.claude/*) - Temporary files and OS-specific files
- Testing artifacts (
Running Tests
-
Install dependencies:
poetry install -
Run all tests:
poetry run test # or poetry run tests -
Run specific test markers:
poetry run pytest -m unit # Run only unit tests poetry run pytest -m integration # Run only integration tests poetry run pytest -m "not slow" # Skip slow tests -
View coverage report:
# After running tests, open the HTML report open htmlcov/index.html # macOS xdg-open htmlcov/index.html # Linux
Notes
- The validation tests confirm that all testing infrastructure components work correctly
- Coverage is currently at 0% as no actual source code tests have been written yet
- The 80% coverage threshold is configured but developers should write tests to meet this requirement
- All dependencies from the original
setup.pyhave been preserved in the Poetry configuration - The
poetry.lockfile should be committed to ensure reproducible builds across environments
Next Steps
Developers can now:
- Write unit tests in the
tests/unit/directory - Write integration tests in the
tests/integration/directory - Use the provided fixtures in
conftest.pyfor common testing scenarios - Run tests locally before committing changes