Skip to content

Tests: inc-site attribute extension construct path + memoized reference target - #1468

Open
rly wants to merge 2 commits into
devfrom
tests/extended-attrs-construct-and-ref
Open

Tests: inc-site attribute extension construct path + memoized reference target#1468
rly wants to merge 2 commits into
devfrom
tests/extended-attrs-construct-and-ref

Conversation

@rly

@rly rly commented May 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes the test gaps PR #283 flagged but never landed:

  • Construct (read) round-trip for inc-site added attributesTestBuildGroupAddedAttr.test_construct_added_attr and TestBuildDatasetAddedAttrs.test_construct_added_attr build a holder containing an extended Bar / BarData with an inc-site ext_attr, then construct from the resulting builder and assert the attribute round-trips. Required adding @ObjectMapper.constructor_arg('ext_attr') to ExtBarMapper / ExtBarDataMapper so the inner mapper can recover an inc-site attribute that is not in its def-site spec.
  • Reference + memoization positive testTestBuildDatasetAddedAttrsWithRef.test_build_added_attr_with_ref builds a holder where the direct extended bar_data field and a sibling typed reference dataset (BarRefDataset) both point at the same BarData instance, and asserts (a) the BarData builder carries the inc-site ext_attr and (b) the reference dataset's ReferenceBuilder resolves to that same memoized builder. Modern code only had the negative-case TestBuildDatasetOfReferencesUnbuiltTarget.

Also uncomments TestBuildGroupRefinedAttr.test_build_refined_attr_wrong_type (the attribute counterpart of TestBuildDatasetRefinedDtype.test_build_refined_dtype_convert — verifies build silently converts int -> int64 when the inc-site spec refines the dtype). The inline TODO is preserved noting that ideally a DtypeConversionWarning would be emitted, mirroring the dataset case.

The four touched mixin / test setUps were refactored to use tests.unit.helpers.utils.create_test_type_map instead of hand-rolling SpecCatalog / SpecNamespace / NamespaceCatalog / TypeMap.

Notes on design choices

PR #283 used a named-untyped dataset with dtype=RefSpec directly holding a Container value. Modern convert_dtype requires a ReferenceBuilder for that path, so the with-ref test instead uses a typed Data subclass (BarRefDataset) holding object references — the canonical "container of references" pattern (mirrors Baz in test_io_map_data.py).

These tests do not move statement / branch coverage numbers (the underlying code paths are already exercised by other tests). They add behavioral guarantees at the inc-site-extension boundary that PR #283 was worried about.

Test plan

  • pytest tests/unit/build_tests/mapper_tests/test_build.py -> 20 passed
  • pytest tests/ -> 1891 passed, 22 skipped, 1 xfailed

🤖 Generated with Claude Code

…d reference target

Closes the gaps PR #283 (#283) flagged but never landed: round-trip construct
coverage for inc-site added attributes (group + dataset) and a positive test
that inc-site attributes are applied when the same dataset is also reachable
through a typed reference dataset.

Also uncomments TestBuildGroupRefinedAttr.test_build_refined_attr_wrong_type
(the attribute counterpart of TestBuildDatasetRefinedDtype.test_build_refined_dtype_convert)
and refactors the BuildGroupExtAttrsMixin / BuildDatasetExtAttrsMixin /
BuildDatasetShapeMixin / TestBuildDatasetAddedAttrsWithRef setUps to use
create_test_type_map.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented May 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.22%. Comparing base (b4e27c5) to head (e9524b4).
⚠️ Report is 1 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #1468   +/-   ##
=======================================
  Coverage   93.22%   93.22%           
=======================================
  Files          41       41           
  Lines       10219    10219           
  Branches     2114     2114           
=======================================
  Hits         9527     9527           
  Misses        415      415           
  Partials      277      277           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rly rly mentioned this pull request May 2, 2026
@rly
rly marked this pull request as ready for review July 13, 2026 13:34
@rly
rly requested a review from Copilot July 13, 2026 13:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds/extends unit test coverage around inc-site spec extensions (added attributes) to ensure correct build + construct round-trips and correct behavior when the extended target is also reachable via typed object references with memoization. This also refactors multiple test setups to use the shared create_test_type_map helper.

Changes:

  • Add construct (read) round-trip tests for inc-site added attribute ext_attr on both group (Bar) and dataset (BarData) cases.
  • Add a positive test ensuring a typed reference dataset resolves to the same memoized builder as a directly-reachable extended dataset container.
  • Refactor several test setup blocks to use create_test_type_map, and re-enable the refined-attribute wrong-type conversion test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

def ext_attr_carg(self, builder, manager):
# ext_attr lives on the inc-site spec, so it is not in BarMapper's def-site spec. Read it
# straight from the builder's attributes when constructing a Bar inside an extended context.
return builder.attributes.get('ext_attr')
def ext_attr_carg(self, builder, manager):
# ext_attr lives on the inc-site spec, so it is not in BarDataMapper's def-site spec. Read it
# straight from the builder's attributes when constructing a BarData inside an extended context.
return builder.attributes.get('ext_attr')

@ObjectMapper.constructor_arg('ext_attr')
def ext_attr_carg(self, builder, manager):
return builder.attributes.get('ext_attr')
},
)

# TODO build should raise a conversion warning for converting 10 (int32) to np.int64
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