This repository contains a small utility used to summarize laboratory sample volumes. Its default execution path works, and the initial tests pass, but that does not mean every possible path is correct.
Your task is to use mypy and pytest together to find and fix two different problems.
Create or activate a Python environment and install the development tools:
python -m pip install -r requirements-dev.txtRun the program and the existing tests:
python sample_summary.py
python -m pytestBoth should succeed. They currently exercise only the default data and a typical tolerance value.
Now run the static type checker:
python -m mypy .Read each diagnostic before changing the code. Determine which message concerns a missing function annotation and which concerns a value that does not match a declared return type.
Extend tests/test_sample_summary.py with a test expressing this requirement:
- A measured value exactly one tolerance away from its target is accepted. For example,
9.5is within a tolerance of0.5around10.0.
Run pytest again. The new tests should expose behavior that the initial tests missed.
Fix sample_summary.py so that:
- every function has a simple, accurate type signature;
- CSV text is converted to floating-point values;
- the tolerance comparison includes its boundary.
Run the same checks again:
python -m pytest
python -m mypy .Inspect and commit your changes:
git diff
git status
git add sample_summary.py tests/test_sample_summary.py
git commit -m "Validate sample volumes with tests and types"
gh student submit