Skip to content

Commit 89e95f4

Browse files
committed
Pretty-print JSON test snapshots + tighten test module quality
**Pretty-print snapshots** The `test_show_options*.json` snapshots used by `tests/test_*.py` were single-line JSON arrays — typically 1-2 KB strings with ~100 country or currency names crammed onto one line. When a database update adds or removes a single country, the diff in CI/PR reviews is one giant string change with no way to see what actually differs. Switched `json.dumps()` in `tests/conftest.py` to use `indent=2` and `ensure_ascii=False` so each array element lands on its own line and non-ASCII characters render natively (e.g. "Côte d'Ivoire" instead of escaped sequences). Diffs in future data PRs now show exactly which country/currency/exchange was added or removed. Regenerated all 54 snapshot files via `pytest --rewrite-expected`. No test semantics change — content is identical. **Test module quality fixes (free with the regen)** 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 actual one-line docstrings on each test function * Add type hints: `(recorder: Recorder) -> None` on test signatures, guarded behind `from __future__ import annotations` so the import stays under `TYPE_CHECKING` and adds no runtime cost No test was renamed or parametrized — that would have invalidated the positional snapshot naming (`test_select.csv`, `test_select_1.csv`, …) that `Recorder.capture()` relies on. Refactors that change snapshot naming were intentionally kept out of scope. All 31 tests pass.
1 parent d8b69e1 commit 89e95f4

63 files changed

Lines changed: 3692 additions & 98 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tests/conftest.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import difflib
12
import json
23
import os
34
import pathlib
@@ -43,7 +44,7 @@ def extract_string(data: Any, **kwargs) -> str:
4344
**kwargs,
4445
)
4546
elif isinstance(data, tuple(EXTENSIONS_MATCHING["json"])):
46-
string_value = json.dumps(data, **kwargs)
47+
string_value = json.dumps(data, indent=2, ensure_ascii=False, **kwargs)
4748
else:
4849
raise AttributeError(f"Unsupported type : {type(data)}")
4950

@@ -225,19 +226,39 @@ def assert_equal(self):
225226

226227
for record in record_list:
227228
if record.record_changed:
229+
expected = (record.recorded or "").splitlines()
230+
actual = (record.captured or "").splitlines()
231+
diff = "\n".join(
232+
difflib.unified_diff(
233+
expected,
234+
actual,
235+
fromfile="expected",
236+
tofile="actual",
237+
lineterm="",
238+
n=3,
239+
)
240+
)
241+
if not diff:
242+
diff = (
243+
f"(line-level diff empty — content differs only in trailing whitespace or EOL)\n"
244+
f"expected length={len(record.recorded or '')}, "
245+
f"actual length={len(record.captured or '')}"
246+
)
228247
raise AssertionError(
229-
"Change detected\n"
230-
f"Record : {record.record_path}\n"
231-
f"Expected : {record.recorded[:self.display_limit]}\n"
232-
f"Actual : {record.captured[:self.display_limit]}\n"
248+
f"Snapshot mismatch: {record.record_path}\n"
249+
f"Run pytest with --rewrite-expected to regenerate, or inspect the diff below.\n\n"
250+
f"{diff}"
233251
)
234252

235253
def assert_in_list(self, in_list: list[str]):
236254
record_list = self.__record_list
237255

238256
for record in record_list:
239257
for string_value in in_list:
240-
assert string_value in record.captured # noqa
258+
assert string_value in record.captured, ( # noqa: S101
259+
f"Expected substring {string_value!r} not found in "
260+
f"{record.record_path}"
261+
)
241262

242263
def persist(self):
243264
record_list = self.__record_list
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
["cryptocurrency", "currency"]
1+
[
2+
"cryptocurrency",
3+
"currency"
4+
]

0 commit comments

Comments
 (0)