test: Add unit tests for ParseNumberFromBrackets - #3878
Open
damansingh1313 wants to merge 1 commit into
Open
Conversation
pyiceberg/utils/parsing.py was the only module under pyiceberg/utils without a dedicated test. ParseNumberFromBrackets backs parsing of bucket[N], truncate[N] and fixed[L], so cover its match behaviour and the ValidationError raised on malformed input.
Author
|
Hi @kevinjqliu, @Fokko |
ebyhr
reviewed
Aug 31, 2026
|
|
||
|
|
||
| def test_match_reads_multi_digit_values() -> None: | ||
| assert ParseNumberFromBrackets("fixed").match("fixed[1024]") == 1024 |
Member
There was a problem hiding this comment.
The multi digit is already covered by test_match_returns_the_bracketed_number, right?
Comment on lines
+34
to
+41
| def test_match_ignores_text_around_the_prefix() -> None: | ||
| # the implementation searches for the pattern, so surrounding text is tolerated | ||
| assert ParseNumberFromBrackets("fixed").match(" fixed[5] ") == 5 | ||
| assert ParseNumberFromBrackets("bucket").match("transform=bucket[4]") == 4 | ||
|
|
||
|
|
||
| def test_match_returns_the_first_occurrence() -> None: | ||
| assert ParseNumberFromBrackets("bucket").match("bucket[3] bucket[7]") == 3 |
Member
There was a problem hiding this comment.
That's true today, but I'm curious if that should be the expected behavior. Raising an exception for such cases is standard practice for me.
Comment on lines
+50
to
+63
| def test_match_raises_when_brackets_are_missing() -> None: | ||
| with pytest.raises(ValidationError): | ||
| ParseNumberFromBrackets("fixed").match("fixed") | ||
|
|
||
|
|
||
| def test_match_raises_for_a_non_numeric_argument() -> None: | ||
| with pytest.raises(ValidationError): | ||
| ParseNumberFromBrackets("truncate").match("truncate[abc]") | ||
|
|
||
|
|
||
| def test_match_raises_for_a_negative_number() -> None: | ||
| # the pattern only accepts digits, so a leading minus sign does not match | ||
| with pytest.raises(ValidationError): | ||
| ParseNumberFromBrackets("truncate").match("truncate[-1]") |
Member
There was a problem hiding this comment.
Can we verify the exception message?
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.
pyiceberg/utils/parsing.py was the only module under pyiceberg/utils without a dedicated test. ParseNumberFromBrackets backs parsing of bucket[N], truncate[N] and fixed[L], so cover its match behaviour and the ValidationError raised on malformed input.
Rationale for this change
Are these changes tested?
It is a unit tests which are tested in local console.
Are there any user-facing changes?