2
2
Tests specific to the collections module.
3
3
"""
4
4
5
- import nose .tools
5
+ from nose .tools import assert_equal
6
6
import numpy as np
7
+ from numpy .testing import assert_array_equal
8
+
7
9
import matplotlib .pyplot as plt
10
+ import matplotlib .collections as mcollections
11
+ import matplotlib .transforms as mtransforms
8
12
from matplotlib .collections import EventCollection
9
13
from matplotlib .testing .decorators import cleanup , image_comparison
10
14
@@ -81,7 +85,7 @@ def test__EventCollection__get_orientation():
81
85
orientation
82
86
'''
83
87
_ , coll , props = generate_EventCollection_plot ()
84
- nose . tools . assert_equal (props ['orientation' ], coll .get_orientation ())
88
+ assert_equal (props ['orientation' ], coll .get_orientation ())
85
89
86
90
87
91
@cleanup
@@ -91,7 +95,7 @@ def test__EventCollection__is_horizontal():
91
95
orientation
92
96
'''
93
97
_ , coll , _ = generate_EventCollection_plot ()
94
- nose . tools . assert_equal (True , coll .is_horizontal ())
98
+ assert_equal (True , coll .is_horizontal ())
95
99
96
100
97
101
@cleanup
@@ -100,7 +104,7 @@ def test__EventCollection__get_linelength():
100
104
check to make sure the default linelength matches the input linelength
101
105
'''
102
106
_ , coll , props = generate_EventCollection_plot ()
103
- nose . tools . assert_equal (props ['linelength' ], coll .get_linelength ())
107
+ assert_equal (props ['linelength' ], coll .get_linelength ())
104
108
105
109
106
110
@cleanup
@@ -109,7 +113,7 @@ def test__EventCollection__get_lineoffset():
109
113
check to make sure the default lineoffset matches the input lineoffset
110
114
'''
111
115
_ , coll , props = generate_EventCollection_plot ()
112
- nose . tools . assert_equal (props ['lineoffset' ], coll .get_lineoffset ())
116
+ assert_equal (props ['lineoffset' ], coll .get_lineoffset ())
113
117
114
118
115
119
@cleanup
@@ -118,7 +122,7 @@ def test__EventCollection__get_linestyle():
118
122
check to make sure the default linestyle matches the input linestyle
119
123
'''
120
124
_ , coll , _ = generate_EventCollection_plot ()
121
- nose . tools . assert_equal (coll .get_linestyle (), [(None , None )])
125
+ assert_equal (coll .get_linestyle (), [(None , None )])
122
126
123
127
124
128
@cleanup
@@ -213,8 +217,8 @@ def test__EventCollection__switch_orientation():
213
217
splt , coll , props = generate_EventCollection_plot ()
214
218
new_orientation = 'vertical'
215
219
coll .switch_orientation ()
216
- nose . tools . assert_equal (new_orientation , coll .get_orientation ())
217
- nose . tools . assert_equal (False , coll .is_horizontal ())
220
+ assert_equal (new_orientation , coll .get_orientation ())
221
+ assert_equal (False , coll .is_horizontal ())
218
222
new_positions = coll .get_positions ()
219
223
check_segments (coll ,
220
224
new_positions ,
@@ -236,8 +240,8 @@ def test__EventCollection__switch_orientation_2x():
236
240
coll .switch_orientation ()
237
241
coll .switch_orientation ()
238
242
new_positions = coll .get_positions ()
239
- nose . tools . assert_equal (props ['orientation' ], coll .get_orientation ())
240
- nose . tools . assert_equal (True , coll .is_horizontal ())
243
+ assert_equal (props ['orientation' ], coll .get_orientation ())
244
+ assert_equal (True , coll .is_horizontal ())
241
245
np .testing .assert_array_equal (props ['positions' ], new_positions )
242
246
check_segments (coll ,
243
247
new_positions ,
@@ -255,8 +259,8 @@ def test__EventCollection__set_orientation():
255
259
splt , coll , props = generate_EventCollection_plot ()
256
260
new_orientation = 'vertical'
257
261
coll .set_orientation (new_orientation )
258
- nose . tools . assert_equal (new_orientation , coll .get_orientation ())
259
- nose . tools . assert_equal (False , coll .is_horizontal ())
262
+ assert_equal (new_orientation , coll .get_orientation ())
263
+ assert_equal (False , coll .is_horizontal ())
260
264
check_segments (coll ,
261
265
props ['positions' ],
262
266
props ['linelength' ],
@@ -275,7 +279,7 @@ def test__EventCollection__set_linelength():
275
279
splt , coll , props = generate_EventCollection_plot ()
276
280
new_linelength = 15
277
281
coll .set_linelength (new_linelength )
278
- nose . tools . assert_equal (new_linelength , coll .get_linelength ())
282
+ assert_equal (new_linelength , coll .get_linelength ())
279
283
check_segments (coll ,
280
284
props ['positions' ],
281
285
new_linelength ,
@@ -293,7 +297,7 @@ def test__EventCollection__set_lineoffset():
293
297
splt , coll , props = generate_EventCollection_plot ()
294
298
new_lineoffset = - 5.
295
299
coll .set_lineoffset (new_lineoffset )
296
- nose . tools . assert_equal (new_lineoffset , coll .get_lineoffset ())
300
+ assert_equal (new_lineoffset , coll .get_lineoffset ())
297
301
check_segments (coll ,
298
302
props ['positions' ],
299
303
props ['linelength' ],
@@ -311,7 +315,7 @@ def test__EventCollection__set_linestyle():
311
315
splt , coll , _ = generate_EventCollection_plot ()
312
316
new_linestyle = 'dashed'
313
317
coll .set_linestyle (new_linestyle )
314
- nose . tools . assert_equal (coll .get_linestyle (), [(0 , (6.0 , 6.0 ))])
318
+ assert_equal (coll .get_linestyle (), [(0 , (6.0 , 6.0 ))])
315
319
splt .set_title ('EventCollection: set_linestyle' )
316
320
317
321
@@ -323,7 +327,7 @@ def test__EventCollection__set_linewidth():
323
327
splt , coll , _ = generate_EventCollection_plot ()
324
328
new_linewidth = 5
325
329
coll .set_linewidth (new_linewidth )
326
- nose . tools . assert_equal (coll .get_linewidth (), new_linewidth )
330
+ assert_equal (coll .get_linewidth (), new_linewidth )
327
331
splt .set_title ('EventCollection: set_linewidth' )
328
332
329
333
@@ -362,10 +366,10 @@ def check_segments(coll, positions, linelength, lineoffset, orientation):
362
366
363
367
# test to make sure each segment is correct
364
368
for i , segment in enumerate (segments ):
365
- nose . tools . assert_equal (segment [0 , pos1 ], lineoffset + linelength / 2. )
366
- nose . tools . assert_equal (segment [1 , pos1 ], lineoffset - linelength / 2. )
367
- nose . tools . assert_equal (segment [0 , pos2 ], positions [i ])
368
- nose . tools . assert_equal (segment [1 , pos2 ], positions [i ])
369
+ assert_equal (segment [0 , pos1 ], lineoffset + linelength / 2. )
370
+ assert_equal (segment [1 , pos1 ], lineoffset - linelength / 2. )
371
+ assert_equal (segment [0 , pos2 ], positions [i ])
372
+ assert_equal (segment [1 , pos2 ], positions [i ])
369
373
370
374
371
375
def check_allprop (values , target ):
@@ -375,7 +379,7 @@ def check_allprop(values, target):
375
379
note: this is not a test, it is used by tests
376
380
'''
377
381
for value in values :
378
- nose . tools . assert_equal (value , target )
382
+ assert_equal (value , target )
379
383
380
384
381
385
def check_allprop_array (values , target ):
@@ -387,6 +391,14 @@ def check_allprop_array(values, target):
387
391
for value in values :
388
392
np .testing .assert_array_equal (value , target )
389
393
390
- if __name__ == '_main_' :
394
+
395
+ def test_null_collection_datalim ():
396
+ col = mcollections .PathCollection ([])
397
+ col_data_lim = col .get_datalim (mtransforms .IdentityTransform ())
398
+ assert_array_equal (col_data_lim .get_points (),
399
+ mtransforms .Bbox ([[0 , 0 ], [0 , 0 ]]).get_points ())
400
+
401
+
402
+ if __name__ == '__main__' :
391
403
import nose
392
404
nose .runmodule (argv = ['-s' , '--with-doctest' ], exit = False )
0 commit comments