Skip to content

test: Add unit tests for ParseNumberFromBrackets - #3878

Open
damansingh1313 wants to merge 1 commit into
apache:mainfrom
damansingh1313:test-parse-number-from-brackets
Open

test: Add unit tests for ParseNumberFromBrackets#3878
damansingh1313 wants to merge 1 commit into
apache:mainfrom
damansingh1313:test-parse-number-from-brackets

Conversation

@damansingh1313

Copy link
Copy Markdown

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?

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.
@damansingh1313

Copy link
Copy Markdown
Author

Hi @kevinjqliu, @Fokko
Could you please review the PR.



def test_match_reads_multi_digit_values() -> None:
assert ParseNumberFromBrackets("fixed").match("fixed[1024]") == 1024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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]")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we verify the exception message?

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