Skip to content

Commit

Permalink
✅ Fix optional dependencies in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathïs Fédérico committed Jan 22, 2024
1 parent 4741795 commit 5b3b588
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion tests/examples/minecraft/test_behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from pathlib import Path
from typing import TYPE_CHECKING

import matplotlib.pyplot as plt
import pytest
import pytest_check as check

Expand All @@ -26,6 +25,7 @@

if TYPE_CHECKING:
from unified_planning.io import PDDLWriter
import matplotlib.pyplot

WOODEN_PICKAXE = MC_TOOLS_BY_TYPE_AND_MATERIAL[ToolType.PICKAXE][Material.WOOD]
STONE_PICKAXE = MC_TOOLS_BY_TYPE_AND_MATERIAL[ToolType.PICKAXE][Material.STONE]
Expand Down Expand Up @@ -158,6 +158,7 @@ def test_graph_rolled(self):
)

def test_graph_draw(self):
plt: "matplotlib.pyplot" = pytest.importorskip("matplotlib.pyplot")
fig, ax = plt.subplots()
self.pickaxe_behavior.graph.draw(ax)
plt.close(fig)
Expand Down
9 changes: 6 additions & 3 deletions tests/examples/test_common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import Type
from typing import TYPE_CHECKING, Type

import pytest
import pytest_check as check
Expand All @@ -17,7 +17,9 @@
MiniHCraftUnlockPickup,
)
from hcraft.env import HcraftEnv
from hcraft.requirements import apply_color_theme

if TYPE_CHECKING:
import matplotlib.pyplot


@pytest.mark.slow
Expand Down Expand Up @@ -108,7 +110,7 @@ def test_requirements_graph(env_class: Type[HcraftEnv], mocker: MockerFixture):
requirements_dir = Path("docs", "images", "requirements_graphs")

if draw_plt:
import matplotlib.pyplot as plt
plt: "matplotlib.pyplot" = pytest.importorskip("matplotlib.pyplot")

width = max(requirements.depth, 10)
height = max(9 / 16 * width, requirements.width / requirements.depth * width)
Expand All @@ -127,6 +129,7 @@ def test_requirements_graph(env_class: Type[HcraftEnv], mocker: MockerFixture):
plt.close()

if draw_html:
pytest.importorskip("pyvis")
mocker.patch("pyvis.network.webbrowser.open")
requirements_dir.mkdir(exist_ok=True)
filepath = requirements_dir / f"{env.name}_requirements_graph.html"
Expand Down

0 comments on commit 5b3b588

Please sign in to comment.