Tests: inc-site attribute extension construct path + memoized reference target - #1468
Open
rly wants to merge 2 commits into
Open
Tests: inc-site attribute extension construct path + memoized reference target#1468rly wants to merge 2 commits into
rly wants to merge 2 commits into
Conversation
…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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
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_attron 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the test gaps PR #283 flagged but never landed:
TestBuildGroupAddedAttr.test_construct_added_attrandTestBuildDatasetAddedAttrs.test_construct_added_attrbuild a holder containing an extended Bar / BarData with an inc-siteext_attr, then construct from the resulting builder and assert the attribute round-trips. Required adding@ObjectMapper.constructor_arg('ext_attr')toExtBarMapper/ExtBarDataMapperso the inner mapper can recover an inc-site attribute that is not in its def-site spec.TestBuildDatasetAddedAttrsWithRef.test_build_added_attr_with_refbuilds a holder where the direct extendedbar_datafield and a sibling typed reference dataset (BarRefDataset) both point at the sameBarDatainstance, and asserts (a) the BarData builder carries the inc-siteext_attrand (b) the reference dataset'sReferenceBuilderresolves to that same memoized builder. Modern code only had the negative-caseTestBuildDatasetOfReferencesUnbuiltTarget.Also uncomments
TestBuildGroupRefinedAttr.test_build_refined_attr_wrong_type(the attribute counterpart ofTestBuildDatasetRefinedDtype.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 aDtypeConversionWarningwould be emitted, mirroring the dataset case.The four touched mixin / test setUps were refactored to use
tests.unit.helpers.utils.create_test_type_mapinstead of hand-rolling SpecCatalog / SpecNamespace / NamespaceCatalog / TypeMap.Notes on design choices
PR #283 used a named-untyped dataset with
dtype=RefSpecdirectly holding a Container value. Modernconvert_dtyperequires aReferenceBuilderfor that path, so the with-ref test instead uses a typedDatasubclass (BarRefDataset) holding object references — the canonical "container of references" pattern (mirrorsBazintest_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 passedpytest tests/-> 1891 passed, 22 skipped, 1 xfailed🤖 Generated with Claude Code