🧪 test_fields: assert structure, not repr - #7453
Conversation
The field regression tests compared `repr()` of each `QbField` against a
YAML reference file, which pinned the formatting of `__repr__` rather
than the field schema.
`__repr__` renders `backend_key`, which folds `is_attribute` into an
`attributes.` prefix, so the flag was never recorded and the encoding is
not injective: a field with key `exception` and `is_attribute=True` and
one with key `attributes.exception` and `is_attribute=False` render
identically. The reference files could not tell them apart.
It was also version-sensitive, since `repr()` of `typing` constructs is
not stable across releases, which is what forced the `skipif < 3.14`
guard. And it tied the files to a presentation detail: changing
`__repr__` rewrites all 46 references, which discourages fixing it.
Build the description in the test instead. The field key is dropped from
it, being the mapping key already, and `backend_key`, `is_attribute` and
`root` are emitted only where they carry information, which keeps the
files roughly the size they were:
levelname: QbStrField(dtype=str, doc='The name of the log level')
exception: QbStrField(backend_key=attributes.exception,
is_attribute=True, dtype=str | None, root=str, doc='...')
`backend_key` differs from the key exactly when `is_attribute` is set,
since a non-attribute field may not be aliased, so both appear together
or not at all.
Dtypes go through `format_dtype`, stable across 3.10-3.14 by
construction rather than by whatever `typing` does this release. Its
`get_origin` guard is load-bearing: `isinstance(dict[str, Any], type)`
is `True` on 3.10 alone, which would render a bare `dict` there and
`dict[str, Any]` from 3.11 on.
`root` pins `extract_root_type`, previously covered only through the
`QbField` subclass it selects. Breaking its union branch now reports
`root=int -> root=Union` beside the class change rather than leaving the
cause to be inferred.
Regenerate all 46 reference files. The diff is large but mechanical: no
field changed, only how it is described.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7453 +/- ##
==========================================
- Coverage 80.61% 80.60% -0.01%
==========================================
Files 580 580
Lines 46722 46722
==========================================
- Hits 37662 37657 -5
- Misses 9060 9065 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Closing this for now, in favor of work on #7461. |
Possible follow-up to #7448.
#7448 re-enabled the node field fixtures, which a filter had been silently excluding from
test_all_node_fields, and regenerated the eight files it had orphaned. Doing that showed they had drifted, and that__repr__lost some field information along the way:is_attributeis no longer in it, and it printsbackend_keywhere__init__takeskey, soQbStrField('exception', is_attribute=True)andQbStrField('attributes.exception', is_attribute=False)come out identical. Pinningrepr()oftypingconstructs is also what forced theskipif < 3.14guard.