Level 3 / Project 12 - Parser With Fixtures¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| — | This project | — | — | Flashcards | — | Browser |
Estimated time: 55 minutes
Focus¶
- test fixtures and parser stability
Why this project exists¶
This project gives you level-appropriate practice in a realistic operations context. Goal: run the baseline, alter behavior, break one assumption, recover safely, and explain the fix.
Run (copy/paste)¶
Use <repo-root> as the folder containing this repository's README.md.
cd <repo-root>/projects/level-3/12-parser-with-fixtures
python project.py data/sample_input.txt
python project.py data/sample_input.txt --format ini --json
pytest -q
Expected terminal output¶
Expected artifacts¶
- Parsed output on stdout
- Passing tests with fixture-generated files
- Updated
notes.md
Checkpoint: Baseline code runs and all tests pass. Commit your work before continuing.
Alter it (required) — Extension¶
- Add a YAML-like parser (indentation-based key: value pairs).
- Add
--validateflag that checks all sections have at least one entry. - Add line number tracking to each parsed record for error reporting.
Break it (required) — Core¶
- Parse an INI file with duplicate section names — what happens?
- Parse a CSV with quoted fields containing commas — does simple split work?
- Auto-detect format on ambiguous input (e.g.,
a=b,c=d) — which parser wins?
Fix it (required) — Core¶
- Handle duplicate sections by merging entries (or warning).
- Document that the CSV parser doesn't handle quoted fields (limitation).
- Add a
--formatoverride so users can bypass auto-detection.
Checkpoint: All modifications done, tests still pass. Good time to review your changes.
Explain it (teach-back)¶
- What is a pytest fixture and how does it differ from setup/teardown?
- Why do the fixtures use
tmp_pathinstead of real files? - How does
detect_formatuse heuristics to guess the file type? - What is the registry pattern (
PARSERSdict) and why use it?
Mastery check¶
You can move on when you can: - write pytest fixtures that create temporary test data, - build parsers for multiple text formats, - use a registry pattern to dispatch to the right parser, - auto-detect file formats from content.
Related Concepts¶
| ← Prev | Home | Next → |
|---|---|---|