8000 Fixed tests for python3 compatibility. Added test for LinearLocator. · matplotlib/matplotlib@5cf67df · GitHub
[go: up one dir, main page]

Skip to content

Commit 5cf67df

Browse files
committed
Fixed tests for python3 compatibility. Added test for LinearLocator.
1 parent 02ba826 commit 5cf67df

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def test_AutoMinorLocator():
5252

5353
def test_LogLocator():
5454
loc = mticker.LogLocator(numticks=5)
55-
5655
assert_raises(ValueError, loc.tick_values, 0, 1000)
5756

5857
test_value = np.array([1.00000000e-05, 1.00000000e-03, 1.00000000e-01,
@@ -65,6 +64,17 @@ def test_LogLocator():
6564
assert_almost_equal(loc.tick_values(1, 100), test_value)
6665

6766

67+
def test_LinearLocator_set_params():
68+
"""
69+
Create linear locator with presets={}, numticks=2 and change it to
70+
something else. See if change was successful. Should not exception.
71+
"""
72+
loc = mticker.LinearLocator(numticks=2)
73+
loc.set_params(numticks=8, presets={(0, 1): []})
74+
nose.tools.assert_equal(loc.numticks, 8)
75+
nose.tools.assert_equal(loc.presets, {(0, 1): []})
76+
77+
6878
def test_LogLocator_set_params():
6979
"""
7080
Create log locator with default value, base=10.0, subs=[1.0], numdecs=4,
@@ -86,7 +96,7 @@ def test_NullLocator_set_params():
8696
Should not exception, and should raise a warning.
8797
"""
8898
loc = mticker.NullLocator()
89-
with warnings.catch_warnings(True) as w:
99+
with warnings.catch_warnings(record=True) as w:
90100
loc.set_params()
91101
nose.tools.assert_equal(len(w), 1)
92102

lib/matplotlib/ticker.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,10 @@ def tick_values(self, vmin, vmax):
956956
raise NotImplementedError('Derived must override')
957957

958958
def set_params(self, **kwargs):
959+
"""
960+
Do nothing, and rase a warning. Any locator class not supporting the
961+
set_params() function will call this.
962+
"""
959963
warnings.warn("'set_params()' not defined for locator of type " +
960964
str(type(self)))
961965

@@ -1032,6 +1036,7 @@ def __init__(self, base, offset):
10321036
self.offset = offset
10331037

10341038
def set_params(self, base=None, offset=None):
1039+
"""Set parameters within this locator"""
10351040
if base is not None:
10361041
self.base = base
10371042
if offset is not None:
@@ -1065,8 +1070,9 @@ def __init__(self, locs, nbins=None):
10651070
self.nbins = max(self.nbins, 2)
10661071

10671072
def set_params(self, nbins=None):
1073+
"""Set parameters within this locator."""
10681074
if nbins is not None:
1069-
self.nbins=nbins
1075+
self.nbins = nbins
10701076

10711077
def __call__(self):
10721078
return self.tick_values(None, None)
@@ -1133,12 +1139,9 @@ def __init__(self, numticks=None, presets=None):
11331139
self.presets = presets
11341140

11351141
def set_params(self, numticks=None, presets=None):
1136-
"""
1137-
[numticks : Int,present : dict] ->None
1138-
1139-
"""
1142+
"""Set parameters within this locator."""
11401143
if presets is not None:
1141-
self.presets = presents
1144+
self.presets = presets
11421145
if numticks is not None:
11431146
self.numticks = numticks
11441147

@@ -1245,10 +1248,8 @@ def __init__(self, base=1.0):
12451248
self._base = Base(base)
12461249

12471250
def set_params(self, base):
1248-
"""
1249-
1250-
"""
1251-
if base is not None :
1251+
"""Set parameters within this locator."""
1252+
if base is not None:
12521253
self.base = base
12531254

12541255
def __call__(self):
@@ -1352,6 +1353,7 @@ def __init__(self, *args, **kwargs):
13521353
self.set_params(**kwargs)
13531354

13541355
def set_params(self, **kwargs):
1356+
"""Set parameters within this locator."""
13551357
if 'nbins' in kwargs:
13561358
self._nbins = int(kwargs['nbins'])
13571359
if 'trim' in kwargs:
@@ -1487,6 +1489,7 @@ def __init__(self, base=10.0, subs=[1.0], numdecs=4, numticks=15):
14871489
self.numdecs = numdecs
14881490

14891491
def set_params(self, base=None, subs=None, numdecs=None, numticks=None):
1492+
"""Set parameters within this locator."""
14901493
if base is not None:
14911494
self.base = base
14921495
if subs is not None:
@@ -1624,9 +1627,7 @@ def __init__(self, transform, subs=None):
16241627
self.numticks = 15
16251628

16261629
def set_params(self, subs=None, numticks=None):
1627-
"""
1628-
1629-
"""
1630+
"""Set parameters within this locator."""
16301631
if numticks is not None:
16311632
self.numticks = numticks
16321633
if subs is not None:

0 commit comments

Comments
 (0)
0