Commit 246f904
committed
Baseline test improvements: pretty-print snapshots, unified-diff failures, docstrings, local data
Sets a cleaner baseline for the test suite so future data and code PRs
are easier to develop, review, and triage. All changes confined to
`tests/` (plus a one-character typo fix in `database/etfs.csv`).
**All 32 tests pass.**
## Snapshot diffs that actually tell you what changed
The `test_show_options*.json` snapshots are JSON arrays of category labels (countries, sectors, currencies, …) — single-line strings of 1-2 KB. When a database update added/removed one entry, the GitHub diff was one giant string change with no way to see what differed.
```diff
- string_value = json.dumps(data, **kwargs)
+ string_value = json.dumps(data, indent=2, ensure_ascii=False, **kwargs)
```
`ensure_ascii=False` also means non-ASCII characters render natively (`Côte d'Ivoire` instead of escape sequences).
## Unified-diff on snapshot mismatch
`Recorder.assert_equal()` previously raised a `AssertionError: Change detected` with two truncated 500-char strings, often appearing identical in the visible part even when they actually differed later. We hit this exact issue while developing JerBouma#141 and JerBouma#143.
Now `assert_equal()` produces a proper `difflib.unified_diff` showing which line(s) changed; `assert_in_list` gained a proper assertion message.
## Tests now read the PR branch's data, not main
The library defaults to fetching `compression/*` from the GitHub `main` branch over HTTP. This meant tests on a PR validated the data on `main`, not the data in the PR — silently passing data-breaking PRs and failing on data-fixing PRs.
Two cooperating fixes:
- Every `tests/test_*.py` now instantiates with `use_local_location=True` so the library reads the local checkout.
- `tests/conftest.py` regenerates `compression/*.bz2` and `compression/categories/*.gzip` from the checked-out `database/*.csv` at import time, mirroring the production `database_update.yml` workflow. This must run *before* pytest collects the test modules (test-module imports instantiate `fd.X(use_local_location=True)`), so it is a top-level statement, not a fixture.
The compression artifacts themselves are not committed in this PR — they are deterministically derived from the CSVs and the test suite regenerates them on every run.
## Test module quality (incidental cleanup)
Since the regen touched every test file, took the opportunity to:
- Fix wrong module docstrings (`test_equities.py` and `test_moneymarkets.py` both started with `"""Currencies Test Module"""`).
- Replace `# pylint: disable=missing-function-docstring` with real docstrings on every test function in the 7 asset-class files and in `test_sec_enrichment_controller.py`.
- Add type hints `(recorder: Recorder) -> None`; `Recorder` import under `TYPE_CHECKING`, guarded by `from __future__ import annotations` — zero runtime cost.
## conftest.py cleanup
- Removed `# pylint: skip-file` so static analysis is no longer suppressed.
- Cast `request.config.getoption("--rewrite-expected")` return through `bool(...)` to satisfy the declared `-> bool` annotation (previously `Any | None`).
## Test infrastructure config (pyproject.toml)
- Dropped `pytest-recording` from dev deps — unused; the real dep used by `conftest.py` is `pytest-recorder` (which provides the `record_mode` / `disable_recording` fixtures).
- Declared `[tool.pytest.ini_options]` `testpaths = ["tests"]`, `addopts = "--strict-markers"`, and the `record_stdout` marker so future PRs can't silently introduce undeclared markers.
## Side fix: ASYMshsare → ASYMshares (etfs.csv + tests)
While running the new local-data tests we noticed `ASPY` (Leverage Shares ASYMmetric 500 ETF) had `family = "ASYMshsare"` — a typo in `database/etfs.csv`. Corrected to `ASYMshares` along with the references in `tests/test_etfs.py` and the affected fixture snapshots. The maintainer's `Update Compression Files` workflow will regenerate the binary artifacts on `main` post-merge.
## What this PR explicitly does NOT do
Deferred to focused follow-ups (out of scope here):
- `@pytest.mark.parametrize` / class-based grouping — would change pytest node IDs and break `Recorder.capture()` positional snapshot naming (renames 90+ files in one go).
- `pytest-xdist` parallel execution — adds a new dev dep; pure perf win.
- Wiring `pytest-cov` (already in dev deps) into CI for coverage reporting.
- Filling the 22% coverage gap on `financedatabase/helpers.py` (`FinanceFrame.to_toolkit`, `show_options` URL error path, `case_sensitive=True`).1 parent 6d1462a commit 246f904
80 files changed
Lines changed: 3826 additions & 143 deletions
File tree
- database
- tests
- csv
- test_equities
- test_etfs
- json
- test_cryptos
- test_currencies
- test_equities
- test_etfs
- test_funds
- test_indices
- test_moneymarkets
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2275 | 2275 | | |
2276 | 2276 | | |
2277 | 2277 | | |
2278 | | - | |
| 2278 | + | |
2279 | 2279 | | |
2280 | 2280 | | |
2281 | 2281 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
94 | 99 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
31 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
32 | 114 | | |
33 | 115 | | |
34 | 116 | | |
| |||
43 | 125 | | |
44 | 126 | | |
45 | 127 | | |
46 | | - | |
| 128 | + | |
47 | 129 | | |
48 | 130 | | |
49 | 131 | | |
| |||
225 | 307 | | |
226 | 308 | | |
227 | 309 | | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
228 | 328 | | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
233 | 332 | | |
234 | 333 | | |
235 | 334 | | |
236 | 335 | | |
237 | 336 | | |
238 | 337 | | |
239 | 338 | | |
240 | | - | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
241 | 343 | | |
242 | 344 | | |
243 | 345 | | |
| |||
345 | 447 | | |
346 | 448 | | |
347 | 449 | | |
348 | | - | |
| 450 | + | |
349 | 451 | | |
350 | 452 | | |
351 | 453 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
0 commit comments