Comprehensive test suite for the mpBAX framework.
Tests are organized by component for better maintainability:
- test_data_handler.py - DataHandler: add/get data, loop tracking, save/load, multi-output
- test_evaluator.py - Evaluator: oracle evaluation, shape validation, eval counting
- test_model.py - Models: DummyModel, custom models, train/predict, save/load
- test_algorithm.py - Algorithms: RandomSampling, GreedySampling, proposals
- test_checkpoint.py - CheckpointManager: save/load/rollback, oracle naming
- test_engine.py - Engine integration: instance/string configs, multi-oracle, finetune/retrain modes
With installation (recommended):
First, install mpBAX in development mode with test dependencies:
cd /path/to/mpBAX
pip install -e ".[dev]"Then run tests:
# Run all tests
pytest tests/ -v
# Run specific test file
pytest tests/test_engine.py -v
# Or run individual files directly
python tests/test_data_handler.py
python tests/test_evaluator.pyWithout installation:
Set PYTHONPATH and run tests:
export PYTHONPATH=/path/to/mpBAX:$PYTHONPATH
# With pytest
pytest tests/ -v
# Or directly
python tests/test_engine.pyTests cover:
- ✓ Core components (DataHandler, Evaluator, Model, Algorithm, CheckpointManager)
- ✓ Engine end-to-end integration
- ✓ Instance-based config (Python API)
- ✓ String-based config (YAML compatibility)
- ✓ Multi-oracle optimization
- ✓ Multi-output oracles
- ✓ Finetune vs retrain modes
- ✓ Loop tracking and metadata
- ✓ Checkpoint/resume/rollback functionality
- ✓ Shape validation and error handling
When adding functionality to mpBAX:
- Add test to appropriate test file (or create new file if needed)
- Follow existing test patterns: clear names, assertions, print statements
- Test both success and error cases
- Run full test suite to ensure no regressions
Example:
def test_my_feature():
"""Test description."""
print("Testing my feature...")
# Test code here
assert something == expected
print(" ✓ My feature tests passed")- Simple and direct: Each test function tests one thing
- Instance-based: Use direct instances, not string imports (easier to test)
- Isolated: Each test is independent, uses temp directories
- Clear output: Print statements show progress and what passed