feat: Set up Python testing infrastructure with Poetry and pytest #65
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Python Testing Infrastructure
Summary
This PR sets up a comprehensive testing infrastructure for the pointer-summarizer project using Poetry as the package manager and pytest as the testing framework. The setup provides a solid foundation for writing and running tests with proper coverage reporting and organization.
Changes Made
Package Management
pyproject.toml
with Poetry package management configurationpytest
(^7.4.0) - Core testing frameworkpytest-cov
(^4.1.0) - Coverage reporting pluginpytest-mock
(^3.11.0) - Mocking utilitiesTesting Configuration
pytest Settings:
test_*.py
and*_test.py
filesunit
,integration
, andslow
Coverage Settings:
data_util
andtraining_ptr_gen
data_util/data.py
) temporarilyDirectory Structure
Shared Fixtures (conftest.py)
Created comprehensive fixtures for common testing needs:
temp_dir
- Temporary directory managementmock_config
- Mock configuration dictionarysample_vocab
- Mock vocabulary objectsample_batch_data
- Sample batch data for model testingdevice
- PyTorch device detectionreset_random_seeds
- Reproducible test runsmock_data_path
,mock_model_path
,mock_log_path
- Mock directory structuresDevelopment Workflow
.gitignore
with testing artifacts, virtual environments, and IDE filespoetry.lock
is NOT gitignored to ensure reproducible buildsHow to Use
Installation
Running Tests
Both commands work identically:
Test Options
All standard pytest options are available:
Coverage Reports
After running tests, coverage reports are available:
htmlcov/index.html
coverage.xml
Notes
Python Version: The project appears to have some Python 2 syntax (e.g.,
data_util/data.py
). These files are temporarily excluded from coverage until migrated.pyrouge Dependency: The original
pyrouge
package is not available on PyPI. It needs to be installed separately following its specific installation instructions.Coverage Threshold: Currently set to 0% to allow the infrastructure setup to complete. This should be increased (e.g., to 80%) as actual tests are added.
Validation Tests: The PR includes validation tests that verify the testing infrastructure is working correctly. These are not unit tests for the actual codebase.
Next Steps
With this testing infrastructure in place, developers can now: