Skip to content

Fix bug in IntegerValidator when an array contains both strings and integers, and add tests for IntegerValidator extras #4693

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
merged 6 commits into from
Jul 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def validator_max():
def validator_aok(request):
return IntegerValidator("prop", "parent", min=-2, max=10, array_ok=True)

@pytest.fixture
def validator_extras():
return IntegerValidator("prop", "parent", extras=['normal', 'bold'])

# ### Acceptance ###
@pytest.mark.parametrize("val", [1, -19, 0, -1234])
Expand All @@ -56,6 +59,18 @@ def test_rejection_by_value(val, validator):
def test_acceptance_min_max(val, validator_min_max):
assert validator_min_max.validate_coerce(val) == approx(val)

# With extras
@pytest.mark.parametrize("val", ['normal', 'bold'])
Copy link
Contributor

@archmoj archmoj Jul 26, 2024

Choose a reason for hiding this comment

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

Thanks @marthacryan for the PR.
Could you please clarify which of these 3 cases we are testing here?
PR_diff
This is from https://github.com/plotly/plotly.py/pull/4612/files.

BTW I prefer to test all 3 cases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

def test_acceptance_extras(val, validator_extras):
assert validator_extras.validate_coerce(val) == val

# Test rejection by extras
@pytest.mark.parametrize("val", ['italic', 'bolditalic'])
def test_rejection_extras(val, validator_extras):
with pytest.raises(ValueError) as validation_failure:
validator_extras.validate_coerce(val)

assert "Invalid value" in str(validation_failure.value)

@pytest.mark.parametrize(
"val", [-1.01, -10, 2.1, 3, np.iinfo(int).max, np.iinfo(int).min]
Expand Down