Skip to content

Commit

Permalink
test: add ignores for PT011 on existing tests
Browse files Browse the repository at this point in the history
Probably useful to enforce on new code, https://docs.astral.sh/ruff/rules/pytest-raises-too-broad/
  • Loading branch information
dangotbanned committed Jun 10, 2024
1 parent 70e8e95 commit 8bbb78e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion tests/utils/test_dataframe_interchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_duration_raises():
df = pd.DataFrame(td).reset_index()
df.columns = ["id", "timedelta"]
pa_table = pa.table(df)
with pytest.raises(ValueError) as e:
with pytest.raises(ValueError) as e: # noqa: PT011
to_values(pa_table)

# Check that exception mentions the duration[ns] type,
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/test_mimebundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def test_spec_to_vegalite_mimebundle(vegalite_spec):

def test_spec_to_vega_mimebundle(vega_spec):
# ValueError: mode must be 'vega-lite'
with pytest.raises(ValueError):
with pytest.raises(ValueError): # noqa: PT011
spec_to_mimebundle(
spec=vega_spec,
mode="vega",
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/test_schemapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def test_class_with_no_schema():
class BadSchema(SchemaBase):
pass

with pytest.raises(ValueError) as err:
with pytest.raises(ValueError) as err: # noqa: PT011
BadSchema(4)
assert str(err.value).startswith("Cannot instantiate object")

Expand Down
4 changes: 2 additions & 2 deletions tests/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,14 @@ def test_sanitize_dataframe_colnames():

# Test that non-string columns result in an error
df.columns = [4, "foo", "bar"]
with pytest.raises(ValueError) as err:
with pytest.raises(ValueError) as err: # noqa: PT011
sanitize_dataframe(df)
assert str(err.value).startswith("Dataframe contains invalid column name: 4.")


def test_sanitize_dataframe_timedelta():
df = pd.DataFrame({"r": pd.timedelta_range(start="1 day", periods=4)})
with pytest.raises(ValueError) as err:
with pytest.raises(ValueError) as err: # noqa: PT011
sanitize_dataframe(df)
assert str(err.value).startswith('Field "r" has type "timedelta')

Expand Down
14 changes: 7 additions & 7 deletions tests/vegalite/v5/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,12 @@ def test_save(format, engine, basic_chart):

if format in {"svg", "png", "pdf", "bogus"} and engine == "vl-convert":
if format == "bogus":
with pytest.raises(ValueError) as err:
with pytest.raises(ValueError) as err: # noqa: PT011
basic_chart.save(out, format=format, engine=engine)
assert f"Unsupported format: '{format}'" in str(err.value)
return
elif vlc is None:
with pytest.raises(ValueError) as err:
with pytest.raises(ValueError) as err: # noqa: PT011
basic_chart.save(out, format=format, engine=engine)
assert "vl-convert-python" in str(err.value)
return
Expand Down Expand Up @@ -953,34 +953,34 @@ def test_layer_errors():

simple_chart = alt.Chart("data.txt").mark_point()

with pytest.raises(ValueError) as err:
with pytest.raises(ValueError) as err: # noqa: PT011
toplevel_chart + simple_chart
assert str(err.value).startswith(
'Objects with "config" attribute cannot be used within LayerChart.'
)

with pytest.raises(ValueError) as err:
with pytest.raises(ValueError) as err: # noqa: PT011
alt.hconcat(simple_chart) + simple_chart
assert (
str(err.value)
== "Concatenated charts cannot be layered. Instead, layer the charts before concatenating."
)

with pytest.raises(ValueError) as err:
with pytest.raises(ValueError) as err: # noqa: PT011
repeat_chart + simple_chart
assert (
str(err.value)
== "Repeat charts cannot be layered. Instead, layer the charts before repeating."
)

with pytest.raises(ValueError) as err:
with pytest.raises(ValueError) as err: # noqa: PT011
facet_chart1 + simple_chart
assert (
str(err.value)
== "Faceted charts cannot be layered. Instead, layer the charts before faceting."
)

with pytest.raises(ValueError) as err:
with pytest.raises(ValueError) as err: # noqa: PT011
alt.layer(simple_chart) + facet_chart2
assert (
str(err.value)
Expand Down

0 comments on commit 8bbb78e

Please sign in to comment.