@@ -159,53 +159,47 @@ def test_SymmetricalLogLocator_set_params():
159
159
nose .tools .assert_equal (sym .numticks , 8 )
160
160
161
161
162
- @cleanup
163
162
def test_ScalarFormatter_offset_value ():
164
163
fig , ax = plt .subplots ()
165
164
formatter = ax .get_xaxis ().get_major_formatter ()
166
165
167
- def update_ticks (ax ):
168
- return next (ax .get_xaxis ().iter_ticks ())
169
-
170
- ax .set_xlim (123 , 189 )
171
- update_ticks (ax )
172
- assert_equal (formatter .offset , 0 )
173
-
174
- ax .set_xlim (- 189 , - 123 )
175
- update_ticks (ax )
176
- assert_equal (formatter .offset , 0 )
177
-
178
- ax .set_xlim (12341 , 12349 )
179
- update_ticks (ax )
180
- assert_equal (formatter .offset , 12340 )
181
-
182
- ax .set_xlim (- 12349 , - 12341 )
183
- update_ticks (ax )
184
- assert_equal (formatter .offset , - 12340 )
185
-
186
- ax .set_xlim (99999.5 , 100010.5 )
187
- update_ticks (ax )
188
- assert_equal (formatter .offset , 100000 )
189
-
190
- ax .set_xlim (- 100010.5 , - 99999.5 )
191
- update_ticks (ax )
192
- assert_equal (formatter .offset , - 100000 )
193
-
194
- ax .set_xlim (99990.5 , 100000.5 )
195
- update_ticks (ax )
196
- assert_equal (formatter .offset , 100000 )
197
-
198
- ax .set_xlim (- 100000.5 , - 99990.5 )
199
- update_ticks (ax )
200
- assert_equal (formatter .offset , - 100000 )
201
-
202
- ax .set_xlim (1233999 , 1234001 )
203
- update_ticks (ax )
204
- assert_equal (formatter .offset , 1234000 )
205
-
206
- ax .set_xlim (- 1234001 , - 1233999 )
207
- update_ticks (ax )
208
- assert_equal (formatter .offset , - 1234000 )
166
+ def check_offset_for (left , right , offset ):
167
+ ax .set_xlim (left , right )
168
+ # Update ticks.
169
+ next (ax .get_xaxis ().iter_ticks ())
170
+ assert_equal (formatter .offset , offset )
171
+
172
+ test_data = [(123 , 189 , 0 ),
173
+ (- 189 , - 123 , 0 ),
174
+ (12341 , 12349 , 12340 ),
175
+ (- 12349 , - 12341 , - 12340 ),
176
+ (99999.5 , 100010.5 , 100000 ),
177
+ (- 100010.5 , - 99999.5 , - 100000 ),
178
+ (99990.5 , 100000.5 , 100000 ),
179
+ (- 100000.5 , - 99990.5 , - 100000 ),
180
+ (1233999 , 1234001 , 1234000 ),
181
+ (- 1234001 , - 1233999 , - 1234000 ),
182
+ # Test cases courtesy of @WeatherGod
183
+ (.4538 , .4578 , .45 ),
184
+ (3789.12 , 3783.1 , 3780 ),
185
+ (45124.3 , 45831.75 , 45000 ),
186
+ (0.000721 , 0.0007243 , 0.00072 ),
187
+ (12592.82 , 12591.43 , 12590 ),
188
+ (9. , 12. , 0 ),
189
+ (900. , 1200. , 0 ),
190
+ (1900. , 1200. , 0 ),
191
+ (0.99 , 1.01 , 1 ),
192
+ (9.99 , 10.01 , 10 ),
193
+ (99.99 , 100.01 , 100 ),
194
+ (5.99 , 6.01 , 6 ),
195
+ (15.99 , 16.01 , 16 ),
196
+ (- 0.452 , 0.492 , 0 ),
197
+ (- 0.492 , 0.492 , 0 ),
198
+ (12331.4 , 12350.5 , 12300 ),
199
+ (- 12335.3 , 12335.3 , 0 )]
200
+
201
+ for left , right , offset in test_data :
202
+ yield check_offset_for , left , right , offset
209
203
210
204
211
205
def _logfe_helper (formatter , base , locs , i , expected_result ):
0 commit comments