|
| 1 | +import re |
| 2 | + |
1 | 3 | from matplotlib.backend_bases import ( |
2 | 4 | FigureCanvasBase, LocationEvent, RendererBase) |
3 | 5 | import matplotlib.pyplot as plt |
@@ -71,22 +73,26 @@ def test_non_gui_warning(): |
71 | 73 | in str(rec[0].message)) |
72 | 74 |
|
73 | 75 |
|
74 | | -def test_location_event_position(): |
75 | | - # LocationEvent should cast its x and y arguments |
76 | | - # to int unless it is None |
77 | | - fig = plt.figure() |
| 76 | +@pytest.mark.parametrize( |
| 77 | + "x, y", [(42, 24), (None, 42), (None, None), (200, 100.01), (205.75, 2.0)]) |
| 78 | +def test_location_event_position(x, y): |
| 79 | + # LocationEvent should cast its x and y arguments to int unless it is None. |
| 80 | + fig, ax = plt.subplots() |
78 | 81 | canvas = FigureCanvasBase(fig) |
79 | | - test_positions = [(42, 24), (None, 42), (None, None), |
80 | | - (200, 100.01), (205.75, 2.0)] |
81 | | - for x, y in test_positions: |
82 | | - event = LocationEvent("test_event", canvas, x, y) |
83 | | - if x is None: |
84 | | - assert event.x is None |
85 | | - else: |
86 | | - assert event.x == int(x) |
87 | | - assert isinstance(event.x, int) |
88 | | - if y is None: |
89 | | - assert event.y is None |
90 | | - else: |
91 | | - assert event.y == int(y) |
92 | | - assert isinstance(event.y, int) |
| 82 | + event = LocationEvent("test_event", canvas, x, y) |
| 83 | + if x is None: |
| 84 | + assert event.x is None |
| 85 | + else: |
| 86 | + assert event.x == int(x) |
| 87 | + assert isinstance(event.x, int) |
| 88 | + if y is None: |
| 89 | + assert event.y is None |
| 90 | + else: |
| 91 | + assert event.y == int(y) |
| 92 | + assert isinstance(event.y, int) |
| 93 | + if x is not None and y is not None: |
| 94 | + assert re.match( |
| 95 | + "x={} +y={}".format(ax.format_xdata(x), ax.format_ydata(y)), |
| 96 | + ax.format_coord(x, y)) |
| 97 | + ax.fmt_xdata = ax.fmt_ydata = lambda x: "foo" |
| 98 | + assert re.match("x=foo +y=foo", ax.format_coord(x, y)) |
0 commit comments