Skip to content
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

fix: mypy 1.12.0 errors #3632

Merged
merged 1 commit into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 12 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@
https://github.com/vega/vl-convert
"""

skip_requires_vegafusion: pytest.MarkDecorator = pytest.mark.skipif(
find_spec("vegafusion") is None, reason="`vegafusion` not installed."
)
"""
``pytest.mark.skipif`` decorator.

Applies when `vegafusion`_ import would fail.

.. _vegafusion:
https://github.com/vega/vegafusion
"""


skip_requires_pyarrow: pytest.MarkDecorator = pytest.mark.skipif(
find_spec("pyarrow") is None, reason="`pyarrow` not installed."
Expand Down
18 changes: 4 additions & 14 deletions tests/utils/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
import pytest

from altair import Chart, vegalite_compilers

try:
import vl_convert as vlc
except ImportError:
vlc = None
from tests import skip_requires_vl_convert


@pytest.fixture
Expand All @@ -30,27 +26,21 @@ def assert_is_vega_spec(vega_spec):
assert "axes" in vega_spec


@skip_requires_vl_convert
def test_vegalite_compiler(chart):
if vlc is None:
pytest.skip("vl_convert is not installed")

vegalite_spec = chart.to_dict()
vega_spec = vegalite_compilers.get()(vegalite_spec)
assert_is_vega_spec(vega_spec)


@skip_requires_vl_convert
def test_to_dict_with_format_vega(chart):
if vlc is None:
pytest.skip("vl_convert is not installed")

vega_spec = chart.to_dict(format="vega")
assert_is_vega_spec(vega_spec)


@skip_requires_vl_convert
def test_to_json_with_format_vega(chart):
if vlc is None:
pytest.skip("vl_convert is not installed")

json_spec = chart.to_json(format="vega")
assert isinstance(json_spec, str)
spec = json.loads(json_spec)
Expand Down
19 changes: 4 additions & 15 deletions tests/utils/test_mimebundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,7 @@
import altair as alt
from altair import VEGA_VERSION
from altair.utils.mimebundle import spec_to_mimebundle

try:
import vl_convert as vlc
except ImportError:
vlc = None

try:
import vegafusion as vf # type: ignore
except ImportError:
vf = None
from tests import skip_requires_vegafusion, skip_requires_vl_convert


@pytest.fixture
Expand Down Expand Up @@ -168,10 +159,8 @@ def vega_spec():
}


@skip_requires_vl_convert
def test_vegalite_to_vega_mimebundle(vegalite_spec, vega_spec):
if vlc is None:
pytest.skip("vl_convert not importable; cannot run mimebundle tests")

bundle = spec_to_mimebundle(
spec=vegalite_spec,
format="vega",
Expand Down Expand Up @@ -233,7 +222,7 @@ def check_pre_transformed_vega_spec(vega_spec):
assert len(data_0.get("transform", [])) == 0


@pytest.mark.skipif(vf is None, reason="vegafusion is not installed")
@skip_requires_vegafusion
def test_vegafusion_spec_to_vega_mime_bundle(vegalite_spec):
with alt.data_transformers.enable("vegafusion"):
bundle = spec_to_mimebundle(
Expand All @@ -246,7 +235,7 @@ def test_vegafusion_spec_to_vega_mime_bundle(vegalite_spec):
check_pre_transformed_vega_spec(vega_spec)


@pytest.mark.skipif(vf is None, reason="vegafusion is not installed")
@skip_requires_vegafusion
def test_vegafusion_chart_to_vega_mime_bundle(vegalite_spec):
chart = alt.Chart.from_dict(vegalite_spec)
with alt.data_transformers.enable("vegafusion"), alt.renderers.enable("json"):
Expand Down
8 changes: 2 additions & 6 deletions tests/vegalite/v5/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import tempfile
from datetime import date, datetime
from importlib.metadata import version as importlib_version
from importlib.util import find_spec
from typing import TYPE_CHECKING

import ibis
Expand All @@ -26,11 +27,6 @@
from altair.utils.schemapi import Optional, SchemaValidationError, Undefined
from tests import skip_requires_vl_convert, slow

try:
import vl_convert as vlc
except ImportError:
vlc = None

if TYPE_CHECKING:
from altair.vegalite.v5.api import _Conditional, _Conditions
from altair.vegalite.v5.schema._typing import Map
Expand Down Expand Up @@ -833,7 +829,7 @@ def test_save(format, engine, basic_chart):
basic_chart.save(out, format=format, engine=engine)
assert f"Unsupported format: '{format}'" in str(err.value)
return
elif vlc is None:
elif find_spec("vl_convert") is None:
with pytest.raises(ValueError) as err: # noqa: PT011
basic_chart.save(out, format=format, engine=engine)
assert "vl-convert-python" in str(err.value)
Expand Down
10 changes: 2 additions & 8 deletions tests/vegalite/v5/test_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
from packaging.version import Version

import altair.vegalite.v5 as alt

try:
import vl_convert as vlc
except ImportError:
vlc = None
from tests import skip_requires_vl_convert

try:
import anywidget
Expand Down Expand Up @@ -92,10 +88,8 @@ def test_json_renderer_embed_options(chart, renderer="json"):
assert metadata == {mimetype: {"option": "foo"}}


@skip_requires_vl_convert
def test_renderer_with_none_embed_options(chart, renderer="mimetype"):
if vlc is None:
pytest.skip("vl_convert not importable; cannot run this test")

# Check that setting embed_options to None doesn't crash
from altair.utils.mimebundle import spec_to_mimebundle

Expand Down