Skip to content

test(catalog): add 31 tests for merge-curated-fields and text normalization - #2547

Merged
jsboige merged 1 commit into
mainfrom
test/catalog-merge-curated-fields
Jun 6, 2026
Merged

jsboige merged 1 commit into
mainfrom
test/catalog-merge-curated-fields

Conversation

@jsboige

@jsboige jsboige commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Summary

Add test coverage for 4 previously-untested pure functions in generate_catalog.py:

Test results

166 passed in 0.44s (135 -> 166, +31 new tests)
Full suite: 2227 passed, 2 failed (pre-existing, fixed in #2541), 18 skipped

Files changed

  • scripts/tests/test_generate_catalog.py -- +249 lines (4 new test classes)

…t, papermill/comment detection

- TestMergeCuratedFields (13 tests): critical stale-catalog poison prevention,
  verifies curated git fields (last_validation, last_validator, issue_pr_associee)
  are preserved from origin/main for unchanged entries
- TestNormalizeText (7 tests): accent stripping, code fence removal, apostrophe norm
- TestIsPapermillInjected (5 tests): Papermill parameter cell detection
- TestIsCommentOnlyCell (6 tests): comment-only code cell detection

Total: 166 catalog tests (135 -> 166)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@clusterManager-Myia

Copy link
Copy Markdown
Collaborator

[NanoClaw]

Solid test addition — 32 tests across 4 new test classes covering _merge_curated_fields, _normalize_text, _is_papermill_injected, and _is_comment_only_cell. No secrets, no always-pass patterns, import convention matches the existing file.

_merge_curated_fields (12 tests) — thorough

The core merge logic is well-exercised: empty/None main catalog, empty entries, blank-field fill, non-empty preservation, mixed fill+keep, missing-key-as-empty, no-match-in-main, multiple entries, non-curated-field isolation, in-place mutation check, and the CURATED_GIT_FIELDS constant assertion. Tests align with the actual implementation at line 633 — the early-return on not main_catalog, the per-field not current_val gate, and the in-place mutation pattern are all verified.

One minor note: test_curated_git_fields_constant (asserting the exact 3-tuple) is a coupling point — if someone adds a fourth curated field, this test breaks instead of guiding. Acceptable as a regression gate, but worth knowing.

_normalize_text (8 tests) — good, one weak assertion

Covers lowercase, accent stripping, curly-to-straight apostrophe, fenced code removal (both single-tag and generic multiline), empty string, and content preservation. All match the implementation at line 264.

test_strips_accents uses "synthese" in result rather than an exact equality check. Since _normalize_text also lowercases and strips accents, the exact output is deterministic — assert _normalize_text("synthèse") == "synthese" would be stricter and catch regressions where accent-stripping breaks silently (e.g. returning an empty string). Currently if the function returned "xyz", the test would still fail, but if it returned "synthese " with a trailing space, it would pass despite a bug.

_is_papermill_injected (5 tests) — complete

For a one-liner (line 321), this is exhaustive: injected tag present, no tags, wrong tags, empty tags list, and no metadata at all.

_is_comment_only_cell (7 tests) — strong

Covers the key edge cases well: pure comments, code+comment mix, empty source, whitespace-only, mixed comments+blank lines, actual code, and the triple-quoted string case (important since the function checks startswith("#") not AST, so """docstring""" correctly returns False). Aligns with line 326 implementation.

Minor nits

  • PR title says 31 tests, actual count is 32 (12+8+5+7). Off by one — no impact, just a title mismatch.
  • No test for _normalize_text with input containing both fenced code and accented text simultaneously — not a gap that matters in practice since the regex removal runs before normalization, but a combined edge case would be the cherry on top.

Overall: clean, well-structured, meaningful assertions. LGTM with the minor note on test_strips_accents exact-match improvement.

@jsboige
jsboige merged commit 8305630 into main Jun 6, 2026
2 checks passed
@jsboige
jsboige deleted the test/catalog-merge-curated-fields branch June 6, 2026 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants