From a654f604f0b520f4710a267e376ba2567058baeb Mon Sep 17 00:00:00 2001 From: Dan Redding <125183946+dangotbanned@users.noreply.github.com> Date: Thu, 16 Jan 2025 14:54:53 +0000 Subject: [PATCH] chore(ruff): Fix `0.9.2` lints (#3771) --- altair/utils/schemapi.py | 2 +- tests/__init__.py | 2 +- tests/utils/test_utils.py | 2 +- tests/vegalite/v5/test_renderers.py | 24 +++++++++++++----------- tools/schemapi/schemapi.py | 2 +- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/altair/utils/schemapi.py b/altair/utils/schemapi.py index 3a49b928d..e7708f0d7 100644 --- a/altair/utils/schemapi.py +++ b/altair/utils/schemapi.py @@ -58,7 +58,7 @@ from typing import Never, Self else: from typing_extensions import Never, Self - _OptionalModule: TypeAlias = "ModuleType | None" # noqa: TC008 + _OptionalModule: TypeAlias = "ModuleType | None" ValidationErrorList: TypeAlias = list[jsonschema.exceptions.ValidationError] GroupedValidationErrors: TypeAlias = dict[str, ValidationErrorList] diff --git a/tests/__init__.py b/tests/__init__.py index 706f6d181..617cfca80 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -22,7 +22,7 @@ from _pytest.mark import ParameterSet MarksType: TypeAlias = ( - "pytest.MarkDecorator | Collection[pytest.MarkDecorator | pytest.Mark]" # noqa: TC008 + "pytest.MarkDecorator | Collection[pytest.MarkDecorator | pytest.Mark]" ) diff --git a/tests/utils/test_utils.py b/tests/utils/test_utils.py index 23120e616..e6b75f4f2 100644 --- a/tests/utils/test_utils.py +++ b/tests/utils/test_utils.py @@ -30,7 +30,7 @@ def _check(arr, typ): _check(nulled, "quantitative") _check(["a", "b", "c"], "nominal") - with pytest.warns(UserWarning): + with pytest.warns(UserWarning, match=r"infer vegalite type"): _check([], "nominal") diff --git a/tests/vegalite/v5/test_renderers.py b/tests/vegalite/v5/test_renderers.py index d8b35308b..426f9114f 100644 --- a/tests/vegalite/v5/test_renderers.py +++ b/tests/vegalite/v5/test_renderers.py @@ -35,7 +35,7 @@ def chart(): return alt.Chart("data.csv").mark_point() -def test_html_renderer_embed_options(chart, renderer="html"): +def test_html_renderer_embed_options(chart): """Test that embed_options in renderer metadata are correctly manifest in html.""" # Short of parsing the javascript, it's difficult to parse out the # actions. So we use string matching @@ -45,7 +45,7 @@ def assert_has_options(chart, **opts): for key, val in opts.items(): assert json.dumps({key: val})[1:-1] in html - with alt.renderers.enable(renderer): + with alt.renderers.enable("html"): assert_has_options(chart, mode="vega-lite") with alt.renderers.enable(embed_options={"actions": {"export": True}}): @@ -55,11 +55,13 @@ def assert_has_options(chart, **opts): assert_has_options(chart, mode="vega-lite", actions=True) -def test_mimetype_renderer_embed_options(chart, renderer="mimetype"): +def test_mimetype_renderer_embed_options(chart): # check that metadata is passed appropriately - mimetype = alt.display.VEGALITE_MIME_TYPE + from altair.vegalite.v5.display import VEGALITE_MIME_TYPE + + mimetype = VEGALITE_MIME_TYPE spec = chart.to_dict() - with alt.renderers.enable(renderer): + with alt.renderers.enable("mimetype"): # Sanity check: no metadata specified bundle, metadata = chart._repr_mimebundle_(None, None) assert bundle[mimetype] == spec @@ -71,11 +73,11 @@ def test_mimetype_renderer_embed_options(chart, renderer="mimetype"): assert metadata == {mimetype: {"embed_options": {"actions": False}}} -def test_json_renderer_embed_options(chart, renderer="json"): +def test_json_renderer_embed_options(chart): """Test that embed_options in renderer metadata are correctly manifest in html.""" mimetype = "application/json" spec = chart.to_dict() - with alt.renderers.enable(renderer): + with alt.renderers.enable("json"): # Sanity check: no options specified bundle, metadata = chart._repr_mimebundle_(None, None) assert bundle[mimetype] == spec @@ -89,12 +91,12 @@ def test_json_renderer_embed_options(chart, renderer="json"): @skip_requires_vl_convert -def test_renderer_with_none_embed_options(chart, renderer="mimetype"): +def test_renderer_with_none_embed_options(chart): # Check that setting embed_options to None doesn't crash from altair.utils.mimebundle import spec_to_mimebundle spec = chart.to_dict() - with alt.renderers.enable(renderer, embed_options=None): + with alt.renderers.enable("mimetype", embed_options=None): bundle = spec_to_mimebundle( spec=spec, mode="vega-lite", @@ -105,9 +107,9 @@ def test_renderer_with_none_embed_options(chart, renderer="mimetype"): @jupyter_marks -def test_jupyter_renderer_mimetype(chart, renderer="jupyter") -> None: +def test_jupyter_renderer_mimetype(chart) -> None: """Test that we get the expected widget mimetype when the jupyter renderer is enabled.""" - with alt.renderers.enable(renderer): + with alt.renderers.enable("jupyter"): assert ( "application/vnd.jupyter.widget-view+json" in chart._repr_mimebundle_(None, None)[0] diff --git a/tools/schemapi/schemapi.py b/tools/schemapi/schemapi.py index 0b926ec69..60e8182a7 100644 --- a/tools/schemapi/schemapi.py +++ b/tools/schemapi/schemapi.py @@ -56,7 +56,7 @@ from typing import Never, Self else: from typing_extensions import Never, Self - _OptionalModule: TypeAlias = "ModuleType | None" # noqa: TC008 + _OptionalModule: TypeAlias = "ModuleType | None" ValidationErrorList: TypeAlias = list[jsonschema.exceptions.ValidationError] GroupedValidationErrors: TypeAlias = dict[str, ValidationErrorList]