DINE
DINE copied to clipboard
feat: Set up comprehensive Python testing infrastructure
Python Testing Infrastructure Setup
Summary
This PR establishes a comprehensive testing infrastructure for the DINE domain adaptation project using Poetry as the package manager and pytest as the testing framework.
Changes Made
Package Management
- Poetry Configuration: Created
pyproject.tomlwith Poetry configuration - Dependencies: Added core dependencies (PyTorch, NumPy, SciPy, scikit-learn, tqdm)
- Dev Dependencies: Added testing tools (
pytest,pytest-cov,pytest-mock)
Testing Framework
-
Directory Structure:
tests/ ├── __init__.py ├── conftest.py ├── test_infrastructure.py ├── unit/ │ └── __init__.py └── integration/ └── __init__.py -
Configuration: Comprehensive pytest configuration in
pyproject.tomlincluding:- Test discovery patterns
- Coverage settings (80% threshold, HTML/XML reports)
- Custom markers (
unit,integration,slow) - Strict mode for markers and configuration
Coverage Reporting
- Reports: HTML, XML, and terminal coverage reports
- Threshold: 80% minimum coverage requirement
- Exclusions: Proper exclusions for test files and boilerplate code
Fixtures and Utilities
- Comprehensive fixtures in
conftest.py:temp_dir: Temporary directory managementsample_config: Mock configuration dictionariesmock_args: Command line argument mockssample_tensor,sample_labels: PyTorch test datamock_dataloader,mock_model: PyTorch component mockssetup_test_environment: Complete test environment setupset_deterministic_behavior: Reproducible test behavior
Validation
- Infrastructure tests: Created
test_infrastructure.pyto validate:- All dependencies are correctly installed
- Custom fixtures work properly
- Project structure is correct
- Deterministic behavior is enforced
- Custom markers function correctly
Running Tests
After this PR is merged, you can run tests using any of these commands:
# Install dependencies
poetry install
# Run all tests
poetry run pytest
# Run with verbose output
poetry run pytest -v
# Run specific test types
poetry run pytest -m unit # Unit tests only
poetry run pytest -m integration # Integration tests only
poetry run pytest -m "not slow" # Skip slow tests
# Run with coverage
poetry run pytest --cov=. --cov-report=html
# Alternative commands
poetry run test # Shortcut for pytest
poetry run tests # Alternative shortcut
Coverage Reports
The setup generates multiple coverage report formats:
- Terminal: Shows missing line numbers during test runs
- HTML: Available in
htmlcov/directory for detailed browsing - XML: Generated as
coverage.xmlfor CI/CD integration
Notes
- Poetry Scripts: Both
poetry run testandpoetry run testsare available as shortcuts - Deterministic Testing: All tests run with fixed random seeds for reproducibility
- Comprehensive Fixtures: Ready-to-use fixtures for common testing scenarios
- Ready for CI/CD: Configuration is optimized for continuous integration environments
Testing the Setup
The infrastructure has been validated with a comprehensive test suite that verifies:
- ✅ All dependencies are available and working
- ✅ PyTorch, NumPy, SciPy, scikit-learn integration
- ✅ Custom fixtures functionality
- ✅ Project structure integrity
- ✅ Marker system operation
- ✅ Deterministic behavior enforcement
This testing infrastructure provides a solid foundation for implementing comprehensive test coverage across the DINE project.