Skip to content

Commit

Permalink
Fix mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
coretl committed Dec 18, 2023
1 parent 3fa32f8 commit 06156a4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/scanspec/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
from matplotlib import colors, patches
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import proj3d
from mpl_toolkits.mplot3d import Axes3D, proj3d
from scipy import interpolate

from .core import Path
Expand Down Expand Up @@ -105,7 +105,7 @@ def plot_spec(spec: Spec[Any]):
# Setup axes
if ndims > 2:
plt.figure(figsize=(6, 6))
plt_axes = plt.axes(projection="3d")
plt_axes: Axes3D = plt.axes(projection="3d")
plt_axes.grid(False)
plt_axes.set_zlabel(axes[-3])
plt_axes.set_ylabel(axes[-2])
Expand Down Expand Up @@ -143,7 +143,7 @@ def plot_spec(spec: Spec[Any]):
height = region.y_radius * 2
angle = region.angle
plt_axes.add_patch(
patches.Ellipse(xy, width, height, angle, fill=False)
patches.Ellipse(xy, width, height, angle=angle, fill=False)
)
elif isinstance(region, Polygon):
# *xy_verts* is a numpy array with shape Nx2.
Expand Down
40 changes: 22 additions & 18 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import pathlib
import subprocess
import sys
from typing import List, cast
from unittest.mock import patch

import matplotlib.pyplot as plt
import numpy as np
import pytest
from click.testing import CliRunner
from matplotlib.patches import Rectangle
from matplotlib.text import Annotation

from scanspec import __version__, cli
from scanspec.plot import _Arrow3D
Expand Down Expand Up @@ -58,9 +61,9 @@ def test_plot_1D_line() -> None:
# End
assert_min_max_2d(lines[3], 2.5, 2.5, 0, 0)
# Arrows
texts = axes.texts
texts = cast(List[Annotation], axes.texts)
assert len(texts) == 1
assert texts[0].xy == (0.5, 0)
assert tuple(texts[0].xy) == (0.5, 0)


def test_plot_1D_line_snake_repeat() -> None:
Expand All @@ -83,10 +86,10 @@ def test_plot_1D_line_snake_repeat() -> None:
# End
assert_min_max_2d(lines[4], 1, 1, 0, 0)
# Arrows
texts = axes.texts
texts = cast(List[Annotation], axes.texts)
assert len(texts) == 2
assert texts[0].xy == (1, 0)
assert texts[1].xy == pytest.approx([2, 0])
assert tuple(texts[0].xy) == (1, 0)
assert tuple(texts[1].xy) == pytest.approx([2, 0])


def test_plot_1D_step() -> None:
Expand All @@ -107,9 +110,9 @@ def test_plot_1D_step() -> None:
# End
assert_min_max_2d(lines[3], 2, 2, 0, 0)
# Arrows
texts = axes.texts
texts = cast(List[Annotation], axes.texts)
assert len(texts) == 1
assert texts[0].xy == (2, 0)
assert tuple(texts[0].xy) == (2, 0)


def test_plot_2D_line() -> None:
Expand All @@ -134,10 +137,10 @@ def test_plot_2D_line() -> None:
# End
assert_min_max_2d(lines[6], 0.5, 0.5, 3, 3)
# Arrows
texts = axes.texts
texts = cast(List[Annotation], axes.texts)
assert len(texts) == 2
assert texts[0].xy == (0.5, 2)
assert texts[1].xy == pytest.approx([2.5, 3])
assert tuple(texts[0].xy) == (0.5, 2)
assert tuple(texts[1].xy) == pytest.approx([2.5, 3])


def test_plot_2D_line_rect_region() -> None:
Expand All @@ -161,18 +164,19 @@ def test_plot_2D_line_rect_region() -> None:
# End
assert_min_max_2d(lines[5], 1.5, 1.5, 2, 2)
# Arrows
texts = axes.texts
texts = cast(List[Annotation], axes.texts)
assert len(texts) == 2
assert texts[0].xy == (-0.5, 1.5)
assert texts[1].xy == (-0.5, 2)
assert tuple(texts[0].xy) == (-0.5, 1.5)
assert tuple(texts[1].xy) == (-0.5, 2)
# Regions
patches = axes.patches
assert len(patches) == 1
assert type(patches[0]).__name__ == "Rectangle"
assert patches[0].xy == (0, 1.1)
assert patches[0].get_height() == 1.0
assert patches[0].get_width() == 1.5
assert patches[0].angle == 30
p = patches[0]
assert isinstance(p, Rectangle)
assert p.get_xy() == (0, 1.1)
assert p.get_height() == 1.0
assert p.get_width() == 1.5
assert p.angle == 30


def test_plot_3D_line() -> None:
Expand Down

0 comments on commit 06156a4

Please sign in to comment.