Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reliable measurement workflow

This repository contains a small collection of helpers from a laboratory measurement workflow. The tests pass, but several less obvious inputs reveal shared state and silently altered data.

Work through the checkpoints in order. Each one is small and can be tested independently.

Set up and establish the baseline

Create or activate a Python environment and install the development tools:

python -m pip install -r requirements-dev.txt
python -m pytest

The initial tests should pass. Read measurement_workflow.py before changing it, and predict which inputs might behave unexpectedly.

Checkpoint 1: shared state and numerical tests

Call record_warning twice without supplying a list. Predict the result, then add a test that proves each call should start with an independent collection. Fix the mutable default argument without changing how callers use the function.

Next, add a test that checks the sum of measurements with values 0.1 and 0.2, using the function total_value. The scientific requirement is that the result is approximately 0.3; express that with pytest.approx instead of exact floating-point equality.

Run only your new tests while working, for example:

python -m pytest -k "warning or total"

Choose descriptive test names of your own. The autograder checks whether the tests detect the problematic behaviors; it does not require the names used in the instructor solution.

Checkpoint 2: missing is not the same as falsy

In effective_tolerance, the value 0.0 is a valid request for an exact tolerance. Add a test for it, then fix effective_tolerance so that only None selects the default.

Checkpoint 3: keep failures visible

parse_measurement currently turns every parsing failure into 0.0. That makes malformed input look like a real measurement. Add a test using an invalid value such as "not-a-number" and check that it raises ValueError. Then remove the broad exception handling and let the original parsing error propagate.

Do not silently invent a replacement measurement. The original ValueError already identifies the invalid text and preserves the useful traceback.

Verify and submit

Run all project checks:

python -m pytest
python -m ruff format --check .
python -m ruff check .

Inspect the changes before committing them:

git diff
git status
git add measurement_workflow.py tests/test_measurement_workflow.py
git commit -m "Make the measurement workflow safer"
gh student submit

The automated checks are feedback, not the purpose of the exercise. If a checkpoint takes too long, continue with the next one and compare approaches with another participant or the reference solution afterward.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages