Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee48023

Browse files
committed
TST: Remove extra dummy Axis classes
1 parent 22fd053 commit ee48023

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -662,25 +662,20 @@ def test_fallback(self):
662662
np.arange(101, 102.01, 0.1))
663663

664664
def test_symmetrizing(self):
665-
class DummyAxis:
666-
bounds = (-1, 1)
667-
@classmethod
668-
def get_view_interval(cls): return cls.bounds
669-
670665
lctr = mticker.AsinhLocator(linear_width=1, numticks=3,
671666
symthresh=0.25, base=0)
672-
lctr.axis = DummyAxis
667+
lctr.create_dummy_axis()
673668

674-
DummyAxis.bounds = (-1, 2)
669+
lctr.axis.set_view_interval(-1, 2)
675670
assert_almost_equal(lctr(), [-1, 0, 2])
676671

677-
DummyAxis.bounds = (-1, 0.9)
672+
lctr.axis.set_view_interval(-1, 0.9)
678673
assert_almost_equal(lctr(), [-1, 0, 1])
679674

680-
DummyAxis.bounds = (-0.85, 1.05)
675+
lctr.axis.set_view_interval(-0.85, 1.05)
681676
assert_almost_equal(lctr(), [-1, 0, 1])
682677

683-
DummyAxis.bounds = (1, 1.1)
678+
lctr.axis.set_view_interval(1, 1.1)
684679
assert_almost_equal(lctr(), [1, 1.05, 1.1])
685680

686681
def test_base_rounding(self):
@@ -897,16 +892,6 @@ def test_empty_locs(self):
897892
assert sf(0.5) == ''
898893

899894

900-
class FakeAxis:
901-
"""Allow Formatter to be called without having a "full" plot set up."""
902-
def __init__(self, vmin=1, vmax=10):
903-
self.vmin = vmin
904-
self.vmax = vmax
905-
906-
def get_view_interval(self):
907-
return self.vmin, self.vmax
908-
909-
910895
class TestLogFormatterExponent:
911896
param_data = [
912897
(True, 4, np.arange(-3, 4.0), np.arange(-3, 4.0),
@@ -928,7 +913,8 @@ def test_basic(self, labelOnlyBase, base, exponent, locs, positions,
928913
expected):
929914
formatter = mticker.LogFormatterExponent(base=base,
930915
labelOnlyBase=labelOnlyBase)
931-
formatter.axis = FakeAxis(1, base**exponent)
916+
formatter.create_dummy_axis()
917+
formatter.axis.set_view_interval(1, base**exponent)
932918
vals = base**locs
933919
labels = [formatter(x, pos) for (x, pos) in zip(vals, positions)]
934920
expected = [label.replace('-', '\N{Minus Sign}') for label in expected]
@@ -937,7 +923,8 @@ def test_basic(self, labelOnlyBase, base, exponent, locs, positions,
937923
def test_blank(self):
938924
# Should be a blank string for non-integer powers if labelOnlyBase=True
939925
formatter = mticker.LogFormatterExponent(base=10, labelOnlyBase=True)
940-
formatter.axis = FakeAxis()
926+
formatter.create_dummy_axis()
927+
formatter.axis.set_view_interval(1, 10)
941928
assert formatter(10**0.1) == ''
942929

943930

@@ -1197,14 +1184,16 @@ def test_sublabel(self):
11971184
def test_LogFormatter_call(self, val):
11981185
# test _num_to_string method used in __call__
11991186
temp_lf = mticker.LogFormatter()
1200-
temp_lf.axis = FakeAxis()
1187+
temp_lf.create_dummy_axis()
1188+
temp_lf.axis.set_view_interval(1, 10)
12011189
assert temp_lf(val) == str(val)
12021190

12031191
@pytest.mark.parametrize('val', [1e-323, 2e-323, 10e-323, 11e-323])
12041192
def test_LogFormatter_call_tiny(self, val):
12051193
# test coeff computation in __call__
12061194
temp_lf = mticker.LogFormatter()
1207-
temp_lf.axis = FakeAxis()
1195+
temp_lf.create_dummy_axis()
1196+
temp_lf.axis.set_view_interval(1, 10)
12081197
temp_lf(val)
12091198

12101199

lib/matplotlib/ticker.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
from collections.abc import Callable, Sequence
2+
from typing import Any, Literal
3+
14
from matplotlib.axis import Axis
25
from matplotlib.transforms import Transform
36
from matplotlib.projections.polar import _AxisWrapper
47

5-
from collections.abc import Callable, Sequence
6-
from typing import Any, Literal
78
import numpy as np
89

910
class _DummyAxis:

0 commit comments

Comments
 (0)