|
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)
|
@@ -63,6 +65,80 @@ def test_LogLocator():
|
63 | 65 | assert_almost_equal(loc.tick_values(1, 100), test_value)
|
64 | 66 |
|
65 | 67 |
|
| 68 | +def test_LogLocator_set_params(): |
| 69 | + """ |
| 70 | + Create log locator with default value, base=10.0, subs=[1.0], numdecs=4, numticks=15 |
| 71 | + and change it to something else. |
| 72 | + See if change was successful. |
| 73 | + Should not exception. |
| 74 | + """ |
| 75 | + loc = mticker.LogLocator() |
| 76 | + loc.set_params(numticks = 8, numdecs = 8, subs = [2.0], base = 8) |
| 77 | + nose.tools.assert_equal(loc.numticks, 8) |
| 78 | + nose.tools.assert_equal(loc.numdecs, 8) |
| 79 | + nose.tools.assert_equal(loc.base, 8) |
| 80 | + nose.tools.assert_equal(loc.subs, [2.0]) |
| 81 | + |
| 82 | + |
| 83 | +def test_NullLocator_set_params(): |
| 84 | + """ |
| 85 | + Create null locator, and attempt to call set_params() on it. |
| 86 | + Should not exception, and should raise a warning. |
| 87 | + """ |
| 88 | + loc = mticker.NullLocator() |
| 89 | + with warnings.catch_warnings(True) as w: |
| 90 | + loc.set_params() |
| 91 | + nose.tools.assert_equal(len(w), 1) |
| 92 | + |
| 93 | + |
| 94 | +def test_MultipleLocator_set_params(): |
| 95 | + """ |
| 96 | + Create multiple locator with 0.7 base, and change it to something else. |
| 97 | + See if change was successful. |
| 98 | + Should not exception. |
| 99 | + """ |
| 100 | + mult = mticker.MultipleLocator(base = 0.7) |
| 101 | + mult.set_params(base = 1.7) |
| 102 | + nose.tools.assert_equal(mult.base, 1.7) |
| 103 | + |
| 104 | + |
| 105 | +def test_FixedLocator_set_params(): |
| 106 | + """ |
| 107 | + Create fixed locator with 5 nbins, and change it to something else. |
| 108 | + See if change was successful. |
| 109 | + Should not exception. |
| 110 | + """ |
| 111 | + fixed = mticker.FixedLocator(range (0,24),nbins=5) |
| 112 | + fixed.set_params(nbins = 7) |
| 113 | + nose.tools.assert_equal(fixed.nbins, 7) |
| 114 | + |
| 115 | + |
| 116 | +def test_IndexLocator_set_params(): |
| 117 | + """ |
| 118 | + Create index locator with 3 base, 4 offset. and change it to something else. |
| 119 | + See if change was successful. |
| 120 | + Should not exception. |
| 121 | + """ |
| 122 | + index = mticker.IndexLocator(base = 3, offset = 4) |
| 123 | + index.set_params(base = 7, offset = 7) |
| 124 | + nose.tools.assert_equal(index.base, 7) |
| 125 | + nose.tools.assert_equal(index.offset, 7) |
| 126 | + |
| 127 | + |
| 128 | +def test_SymmetricalLogLocator_set_params(): |
| 129 | + """ |
| 130 | + Create symmetrical log locator with default subs =[1.0] numticks = 15, |
| 131 | + and change it to something else. |
| 132 | + See if change was successful. |
| 133 | + Should not exception. |
| 134 | + """ |
| 135 | + #since we only test for the params change. I will pass empty transform |
| 136 | + sym = mticker.SymmetricalLogLocator(None) |
| 137 | + sym.set_params(subs = [2.0], numticks = 8) |
| 138 | + nose.tools.assert_equal(sym._subs, [2.0]) |
| 139 | + nose.tools.assert_equal(sym.numticks, 8) |
| 140 | + |
| 141 | + |
66 | 142 | def test_LogFormatterExponent():
|
67 | 143 | class FakeAxis(object):
|
68 | 144 | """Allow Formatter to be called without having a "full" plot set up."""
|
@@ -111,25 +187,6 @@ def test_formatstrformatter():
|
111 | 187 | tmp_form = mticker.StrMethodFormatter('{x:05d}')
|
112 | 188 | nose.tools.assert_equal('00002', tmp_form(2))
|
113 | 189 |
|
114 |
| -@cleanup |
115 |
| -def test_set_params(): |
116 |
| - loc = mticker.LogLocator(numticks = 2) |
117 |
| - |
118 |
| - assert_raises(ValueError, loc.tick_values, 0, 1000) |
119 |
| - #this should return number of ticks as 5 |
120 |
| - test_value = np.array([ 1.0000000e-10, 1.0000000e-03, 1.0000000e+04, 1.0000000e+11, |
121 |
| - 1.0000000e+18]) |
122 |
| - assert_almost_equal(loc.tick_values(0.001, 1.1e5), test_value) |
123 |
| - #after the set_params(numticks=8), it should have 7 extra which should have 7 extra |
124 |
| - #numticks. Also it won't casue to thrown the exception for bugs # #3658 |
125 |
| - loc.set_params(numticks = 8) |
126 |
| - test_value = np.array([ 1.0000000e-04, 1.0000000e-03, 1.0000000e-02, 1.0000000e-01, |
127 |
| - 1.0000000e+00, 1.0000000e+01, 1.0000000e+02, 1.0000000e+03, |
128 |
| - 1.0000000e+04, 1.0000000e+05, 1.0000000e+06, 1.0000000e+07]) |
129 |
| - assert_almost_equal(loc.tick_values(0.001, 1.1e5), test_value) |
130 |
| - |
131 |
| - |
132 |
| - |
133 | 190 | if __name__ == '__main__':
|
134 | 191 | import nose
|
135 | 192 | nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
|
0 commit comments