11
11
import matplotlib .ticker as mticker
12
12
from matplotlib .testing .decorators import cleanup
13
13
14
+ import warnings
15
+
14
16
15
17
def test_MaxNLocator ():
16
18
loc = mticker .MaxNLocator (nbins = 5 )
@@ -50,7 +52,6 @@ def test_AutoMinorLocator():
50
52
51
53
def test_LogLocator ():
52
54
loc = mticker .LogLocator (numticks = 5 )
53
-
54
55
assert_raises (ValueError , loc .tick_values , 0 , 1000 )
55
56
56
57
test_value = np .array ([1.00000000e-05 , 1.00000000e-03 , 1.00000000e-01 ,
@@ -63,6 +64,101 @@ def test_LogLocator():
63
64
assert_almost_equal (loc .tick_values (1 , 100 ), test_value )
64
65
65
66
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
+
78
+ def test_LogLocator_set_params ():
79
+ """
80
+ Create log locator with default value, base=10.0, subs=[1.0], numdecs=4,
81
+ numticks=15 and change it to something else.
82
+ See if change was successful.
83
+ Should not exception.
84
+ """
85
+ loc = mticker .LogLocator ()
86
+ loc .set_params (numticks = 8 , numdecs = 8 , subs = [2.0 ], base = 8 )
87
+ nose .tools .assert_equal (loc .numticks , 8 )
88
+ nose .tools .assert_equal (loc .numdecs , 8 )
89
+ nose .tools .assert_equal (loc .base , 8 )
90
+ nose .tools .assert_equal (loc .subs , [2.0 ])
91
+
92
+
93
+ def test_NullLocator_set_params ():
94
+ """
95
+ Create null locator, and attempt to call set_params() on it.
96
+ Should not exception, and should raise a warning.
97
+ """
98
+ loc = mticker .NullLocator ()
99
+ with warnings .catch_warnings (record = True ) as w :
100
+ loc .set_params ()
101
+ nose .tools .assert_equal (len (w ), 1 )
102
+
103
+
104
+ def test_MultipleLocator_set_params ():
105
+ """
106
+ Create multiple locator with 0.7 base, and change it to something else.
107
+ See if change was successful.
108
+ Should not exception.
109
+ """
110
+ mult = mticker .MultipleLocator (base = 0.7 )
111
+ mult .set_params (base = 1.7 )
112
+ nose .tools .assert_equal (mult ._base , 1.7 )
113
+
114
+
115
+ def test_LogitLocator_set_params ():
116
+ """
117
+ Create logit locator with default minor=False, and change it to something
118
+ else. See if change was successful. Should not exception.
119
+ """
120
+ loc = mticker .LogitLocator () # Defaults to false.
121
+ loc .set_params (minor = True )
122
+ nose .tools .assert_true (loc .minor )
123
+
124
+
125
+ def test_FixedLocator_set_params ():
126
+ """
127
+ Create fixed locator with 5 nbins, and change it to something else.
128
+ See if change was successful.
129
+ Should not exception.
130
+ """
131
+ fixed = mticker .FixedLocator (range (0 , 24 ), nbins = 5 )
132
+ fixed .set_params (nbins = 7 )
133
+ nose .tools .assert_equal (fixed .nbins , 7 )
134
+
135
+
136
+ def test_IndexLocator_set_params ():
137
+ """
138
+ Create index locator with 3 base, 4 offset. and change it to something
139
+ else. See if change was successful.
140
+ Should not exception.
141
+ """
142
+ index = mticker .IndexLocator (base = 3 , offset = 4 )
143
+ index .set_params (base = 7 , offset = 7 )
144
+ nose .tools .assert_equal (index ._base , 7 )
145
+ nose .tools .assert_equal (index .offset , 7 )
146
+
147
+
148
+ def test_SymmetricalLogLocator_set_params ():
149
+ """
150
+ Create symmetrical log locator with default subs =[1.0] numticks = 15,
151
+ and change it to something else.
152
+ See if change was successful.
153
+ Should not exception.
154
+ """
155
+ # since we only test for the params change. I will pass empty transform
156
+ sym = mticker .SymmetricalLogLocator (None )
157
+ sym .set_params (subs = [2.0 ], numticks = 8 )
158
+ nose .tools .assert_equal (sym ._subs , [2.0 ])
159
+ nose .tools .assert_equal (sym .numticks , 8 )
160
+
161
+
66
162
def test_LogFormatterExponent ():
67
163
class FakeAxis (object ):
68
164
"""Allow Formatter to be called without having a "full" plot set up."""
@@ -111,7 +207,6 @@ def test_formatstrformatter():
111
207
tmp_form = mticker .StrMethodFormatter ('{x:05d}' )
112
208
nose .tools .assert_equal ('00002' , tmp_form (2 ))
113
209
114
-
115
210
if __name__ == '__main__' :
116
211
import nose
117
212
nose .runmodule (argv = ['-s' , '--with-doctest' ], exit = False )
0 commit comments