feat: Add comprehensive Python testing infrastructure with Poetry #29
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 complete testing infrastructure for the recommender systems evaluation project using Poetry as the package manager and pytest as the testing framework.
Changes Made
Package Management
pyproject.toml
with Poetry as the package managerrequirements.txt
with flexible version constraintsTesting Setup
Directory Structure:
tests/
directory withunit/
andintegration/
subdirectories__init__.py
files for proper Python package structurePytest Configuration:
unit
,integration
,slow
Shared Fixtures (
tests/conftest.py
):temp_dir
: Temporary directory managementmock_config
: Configuration dictionary for testingsample_data_dir
: Sample CSV files for data testingsample_sparse_matrix
: Sparse matrix for recommender testingsample_dataframe
: Pandas DataFrame fixturemock_recommender
: Mock recommender objectmock_evaluator
: Mock evaluator objectmock_data_reader
: Mock data readercapture_logs
: Log capture fixturereset_random_seed
: Automatic random seed resetValidation Tests: Created comprehensive tests to verify the infrastructure works correctly
Commands
poetry run test
- Run all testspoetry run tests
- Alternative command (both work)Instructions for Running Tests
Install dependencies:
Run all tests:
poetry run test
Run specific test file:
Run with coverage:
Run only unit tests:
Notes
Dependency Compatibility
The original
requirements.txt
contains legacy dependencies (TensorFlow 1.13.1, Keras 2.2.4, etc.) that require Python <=3.7. The testing infrastructure uses flexible version constraints to work with modern Python versions. For projects requiring the exact legacy versions:pip install -r requirements.txt
Coverage Configuration
htmlcov/
coverage.xml
--cov-fail-under
Next Steps
Developers can now immediately start writing tests for the codebase. The infrastructure provides all necessary tools and configurations for comprehensive testing.