-
Notifications
You must be signed in to change notification settings - Fork 1
Fix/100, 98, 78 #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Fix/100, 98, 78 #118
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d215ecf
workaround for issue 78
swhume 2df6065
comment update
swhume 8c0d90b
resolves issue 100: nested subclasses
swhume 9d8c8ae
Merge remote-tracking branch 'origin/main'
swhume 861047e
resolves issue 98: origin as a list
swhume 9d3e92e
updates sig dig fix and adds tests
swhume 2373901
fixes small typo in comment
swhume 77c7229
origin tests improvement
swhume File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
8,491 changes: 8,490 additions & 1 deletion
8,491
src/generators/define/tests/fixtures/define-360i.xml
Large diffs are not rendered by default.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| """ | ||
| Unit tests for Items._add_optional_itemdef_attributes, focused on the | ||
| displayFormat -> SignificantDigits/Length fallback (the issue-78 workaround). | ||
|
|
||
| The fallback parses obj['displayFormat'] (e.g. "8.3") into a Length / | ||
| SignificantDigits pair when the study JSON omits them. The hardened version must: | ||
| * never raise when the format lacks exactly one dot (the old split(".") | ||
| unpack raised ValueError for "8", "1.2.3", etc.), and | ||
| * yield ints, matching the type of values that arrive straight from the JSON | ||
| (the old code left the derived values as strings). | ||
| """ | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def add_attrs(): | ||
| import items | ||
| return items.Items._add_optional_itemdef_attributes | ||
|
|
||
|
|
||
| class TestExplicitValuesWin: | ||
| def test_explicit_significant_digits_preserved_as_int(self, add_attrs): | ||
| # An explicit significantDigits short-circuits the displayFormat fallback. | ||
| attr = {} | ||
| add_attrs(attr, {"significantDigits": 2, "dataType": "float", "displayFormat": "8.3"}) | ||
| assert attr["SignificantDigits"] == 2 | ||
| assert isinstance(attr["SignificantDigits"], int) | ||
|
|
||
| def test_explicit_length_not_overridden_by_displayformat(self, add_attrs): | ||
| attr = {} | ||
| add_attrs(attr, {"dataType": "float", "length": 10, "displayFormat": "8.3"}) | ||
| assert attr["Length"] == 10 # explicit length wins | ||
| assert attr["SignificantDigits"] == 3 # sig digits still derived from format | ||
| assert isinstance(attr["SignificantDigits"], int) | ||
|
|
||
|
|
||
| class TestDisplayFormatFallback: | ||
| def test_float_displayformat_yields_int_significant_digits_and_length(self, add_attrs): | ||
| attr = {} | ||
| add_attrs(attr, {"dataType": "float", "displayFormat": "8.3"}) | ||
| # Core regression: derived values must be ints, not the strings the old | ||
| # split(".") branch produced. | ||
| assert attr["SignificantDigits"] == 3 | ||
| assert isinstance(attr["SignificantDigits"], int) | ||
| assert attr["Length"] == 8 | ||
| assert isinstance(attr["Length"], int) | ||
|
|
||
| def test_displayformat_without_dot_does_not_raise(self, add_attrs): | ||
| # "8" has no dot; old split(".") -> single element -> ValueError on unpack. | ||
| attr = {} | ||
| add_attrs(attr, {"dataType": "float", "displayFormat": "8"}) | ||
| assert "SignificantDigits" not in attr | ||
| # The whole-number portion is still recovered into the placeholder slot. | ||
| assert attr["Length"] == 8 | ||
| assert isinstance(attr["Length"], int) | ||
|
|
||
| def test_displayformat_with_multiple_dots_does_not_raise(self, add_attrs): | ||
| # "1.2.3" -> old split(".") -> three elements -> ValueError on unpack. | ||
| attr = {} | ||
| add_attrs(attr, {"dataType": "float", "displayFormat": "1.2.3"}) | ||
| # "2.3" is not a pure digit string, so no SignificantDigits is derived. | ||
| assert "SignificantDigits" not in attr | ||
| assert attr["Length"] == 1 | ||
|
|
||
| def test_non_numeric_displayformat_leaves_placeholder(self, add_attrs): | ||
| attr = {} | ||
| add_attrs(attr, {"dataType": "float", "displayFormat": "DATE9."}) | ||
| assert "SignificantDigits" not in attr | ||
| assert attr["Length"] == "__PLACEHOLDER__" # nothing numeric to recover | ||
| assert attr["DisplayFormat"] == "DATE9." | ||
|
|
||
| def test_fallback_only_applies_to_float_datatype(self, add_attrs): | ||
| attr = {} | ||
| add_attrs(attr, {"dataType": "text", "displayFormat": "8.3"}) | ||
| assert "SignificantDigits" not in attr | ||
| assert attr["DisplayFormat"] == "8.3" |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.