0%

Capstone: A Practice Report Tool · capstone

Capstone project: Capstone: Finish and Prove the Tool

This is the last piece of building. Everything after it is handing the project over.

Finish practice_report.py so every part connects: the cache with its contract, freshness from an injected time, the six-row selection table, the summary and the report, and the boundary that decides what gets written and in what order.

Then run both suites:

python -m pytest -q

Both should collect and pass. tests/test_api_catalog.py came with you from Chapter 12 and should not have changed; tests/test_practice_report.py is the one you wrote.

Prove it survives being moved

This lesson has no network access. The site runtime already supplies the pinned Requests and pytest, so use its python to check a copied source tree without installing packages. Chapter 12 taught a fresh environment rebuild; the next lesson repeats that part on your own computer.

Copy the ten authored files into a new folder with a space and non-ASCII text in its name, then run the tests and offline mode there:

mkdir -p "/tmp/Fresh Café Report Project/tests"
mkdir -p "/tmp/Fresh Café Report Project/data"
cp API_CONTRACT.md README.md api_catalog.py practice_report.py pl_check.py \
   requirements.txt requirements-dev.txt "/tmp/Fresh Café Report Project/"
cp data/offline-page.json "/tmp/Fresh Café Report Project/data/"
cp tests/test_api_catalog.py tests/test_practice_report.py "/tmp/Fresh Café Report Project/tests/"
cd "/tmp/Fresh Café Report Project"
python -m pytest -q
python practice_report.py report.txt --offline-source data/offline-page.json
cd /workspace

Those commands run the suite again and produce an offline report from the copied root. Both should behave exactly as they did at home. If either does not, something in your code depends on where it lives, and that is worth finding now rather than after you send it to someone.

Try the paths that are easy to get wrong

Run the offline path in this network-free session:

python practice_report.py report.txt --offline-source data/offline-page.json
cat report.txt

The report should say source: offline and fetched_at: none. The command must neither create nor alter a cache file. An existing cache from earlier work stays as it was.

Use your fake-HTTP tests for the remaining selection rows. A fresh cache should record zero calls; a missing cache should record one; a stale cache should fall back only on the documented failures; and --refresh must fetch once without falling back. Inject now_epoch so the freshness result cannot change while a test runs. A live refresh cannot succeed in this lesson’s network-free session.

Clean up before you submit

Delete generated cache and report files from the saved workspace. The copied root lives under /tmp and is discarded with the session; .venv, __pycache__, and .pytest_cache are derived state and do not belong in the authored tree.

The saved project should contain exactly ten authored files and nothing else:

API_CONTRACT.md
README.md
api_catalog.py
practice_report.py
pl_check.py
requirements.txt
requirements-dev.txt
data/offline-page.json
tests/test_api_catalog.py
tests/test_practice_report.py

A generated cache is not evidence that the tool works. It is a leftover. The ten files above are the project; everything else is something the project makes.

Press Check my work when the suites are green and the tree is clean.

If a test fails and you cannot see why, ask Monty to read the failing assertion and tell you which of the six selection rows it is exercising. Naming the row usually names the bug.

Task

Finish the exact cache/time/source/report/ contract and make the complete fake-HTTP suite pass from a clean root without retaining generated outputs.