Skip to content

TST: Remove extra dummy Axis classes #26393

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

Merged
merged 1 commit into from
Jul 27, 2023
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
37 changes: 13 additions & 24 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,25 +662,20 @@ def test_fallback(self):
np.arange(101, 102.01, 0.1))

def test_symmetrizing(self):
class DummyAxis:
bounds = (-1, 1)
@classmethod
def get_view_interval(cls): return cls.bounds

lctr = mticker.AsinhLocator(linear_width=1, numticks=3,
symthresh=0.25, base=0)
lctr.axis = DummyAxis
lctr.create_dummy_axis()

DummyAxis.bounds = (-1, 2)
lctr.axis.set_view_interval(-1, 2)
assert_almost_equal(lctr(), [-1, 0, 2])

DummyAxis.bounds = (-1, 0.9)
lctr.axis.set_view_interval(-1, 0.9)
assert_almost_equal(lctr(), [-1, 0, 1])

DummyAxis.bounds = (-0.85, 1.05)
lctr.axis.set_view_interval(-0.85, 1.05)
assert_almost_equal(lctr(), [-1, 0, 1])

DummyAxis.bounds = (1, 1.1)
lctr.axis.set_view_interval(1, 1.1)
assert_almost_equal(lctr(), [1, 1.05, 1.1])

def test_base_rounding(self):
Expand Down Expand Up @@ -897,16 +892,6 @@ def test_empty_locs(self):
assert sf(0.5) == ''


class FakeAxis:
"""Allow Formatter to be called without having a "full" plot set up."""
def __init__(self, vmin=1, vmax=10):
self.vmin = vmin
self.vmax = vmax

def get_view_interval(self):
return self.vmin, self.vmax


class TestLogFormatterExponent:
param_data = [
(True, 4, np.arange(-3, 4.0), np.arange(-3, 4.0),
Expand All @@ -928,7 +913,8 @@ def test_basic(self, labelOnlyBase, base, exponent, locs, positions,
expected):
formatter = mticker.LogFormatterExponent(base=base,
labelOnlyBase=labelOnlyBase)
formatter.axis = FakeAxis(1, base**exponent)
formatter.create_dummy_axis()
formatter.axis.set_view_interval(1, base**exponent)
vals = base**locs
labels = [formatter(x, pos) for (x, pos) in zip(vals, positions)]
expected = [label.replace('-', '\N{Minus Sign}') for label in expected]
Expand All @@ -937,7 +923,8 @@ def test_basic(self, labelOnlyBase, base, exponent, locs, positions,
def test_blank(self):
# Should be a blank string for non-integer powers if labelOnlyBase=True
formatter = mticker.LogFormatterExponent(base=10, labelOnlyBase=True)
formatter.axis = FakeAxis()
formatter.create_dummy_axis()
formatter.axis.set_view_interval(1, 10)
assert formatter(10**0.1) == ''


Expand Down Expand Up @@ -1197,14 +1184,16 @@ def test_sublabel(self):
def test_LogFormatter_call(self, val):
# test _num_to_string method used in __call__
temp_lf = mticker.LogFormatter()
temp_lf.axis = FakeAxis()
temp_lf.create_dummy_axis()
temp_lf.axis.set_view_interval(1, 10)
assert temp_lf(val) == str(val)

@pytest.mark.parametrize('val', [1e-323, 2e-323, 10e-323, 11e-323])
def test_LogFormatter_call_tiny(self, val):
# test coeff computation in __call__
temp_lf = mticker.LogFormatter()
temp_lf.axis = FakeAxis()
temp_lf.create_dummy_axis()
temp_lf.axis.set_view_interval(1, 10)
temp_lf(val)


Expand Down
5 changes: 3 additions & 2 deletions lib/matplotlib/ticker.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from collections.abc import Callable, Sequence
from typing import Any, Literal

from matplotlib.axis import Axis
from matplotlib.transforms import Transform
from matplotlib.projections.polar import _AxisWrapper

from collections.abc import Callable, Sequence
from typing import Any, Literal
import numpy as np

class _DummyAxis:
Expand Down