6
6
7
7
import unittest
8
8
9
- from nose .tools import assert_equal , assert_raises
10
9
import numpy .testing as np_test
11
10
from numpy .testing import assert_almost_equal , assert_array_equal
12
11
from numpy .testing import assert_array_almost_equal
12
+ import pytest
13
13
from matplotlib .transforms import (Affine2D , BlendedGenericTransform , Bbox ,
14
14
TransformedPath , TransformedPatchPath )
15
15
from matplotlib .path import Path
@@ -262,9 +262,9 @@ def setUp(self):
262
262
# self.stack2_subset.write_graphviz(file('stack2_subset.dot', 'w'))
263
263
264
264
def test_transform_depth (self ):
265
- assert_equal ( self .stack1 .depth , 4 )
266
- assert_equal ( self .stack2 .depth , 4 )
267
- assert_equal ( self .stack2_subset .depth , 3 )
265
+ assert self .stack1 .depth == 4
266
+ assert self .stack2 .depth == 4
267
+ assert self .stack2_subset .depth == 3
268
268
269
269
def test_left_to_right_iteration (self ):
270
270
stack3 = (self .ta1 + (self .tn1 + (self .ta2 + self .tn2 ))) + self .ta3
@@ -286,12 +286,11 @@ def test_transform_shortcuts(self):
286
286
self .assertEqual (self .stack1 - self .stack2_subset , self .ta1 )
287
287
self .assertEqual (self .stack2 - self .stack2_subset , self .ta1 )
288
288
289
- assert_equal ((self .stack2_subset - self .stack2 ),
290
- self .ta1 .inverted (),
291
- )
292
- assert_equal ((self .stack2_subset - self .stack2 ).depth , 1 )
289
+ assert self .stack2_subset - self .stack2 == self .ta1 .inverted ()
290
+ assert (self .stack2_subset - self .stack2 ).depth == 1
293
291
294
- assert_raises (ValueError , self .stack1 .__sub__ , self .stack2 )
292
+ with pytest .raises (ValueError ):
293
+ self .stack1 - self .stack2
295
294
296
295
aff1 = self .ta1 + (self .ta2 + self .ta3 )
297
296
aff2 = self .ta2 + self .ta3
@@ -496,7 +495,7 @@ def test_bbox_intersection():
496
495
# r3 contains r2
497
496
assert_bbox_eq (inter (r1 , r3 ), r3 )
498
497
# no intersection
499
- assert_equal ( inter (r1 , r4 ), None )
498
+ assert inter (r1 , r4 ) is None
500
499
# single point
501
500
assert_bbox_eq (inter (r1 , r5 ), bbox_from_ext (1 , 1 , 1 , 1 ))
502
501
@@ -506,11 +505,11 @@ def test_bbox_as_strings():
506
505
assert_bbox_eq (b , eval (repr (b ), {'Bbox' : mtrans .Bbox }))
507
506
asdict = eval (str (b ), {'Bbox' : dict })
508
507
for k , v in asdict .items ():
509
- assert_equal ( getattr (b , k ), v )
508
+ assert getattr (b , k ) == v
510
509
fmt = '.1f'
511
510
asdict = eval (format (b , fmt ), {'Bbox' : dict })
512
511
for k , v in asdict .items ():
513
- assert_equal ( eval (format (getattr (b , k ), fmt )), v )
512
+ assert eval (format (getattr (b , k ), fmt )) == v
514
513
515
514
516
515
def test_transform_single_point ():
@@ -545,10 +544,12 @@ def test_transform_angles():
545
544
assert_array_almost_equal (angles , new_angles )
546
545
547
546
# points missing a 2nd dimension
548
- assert_raises (ValueError , t .transform_angles , angles , points [0 :2 , 0 :1 ])
547
+ with pytest .raises (ValueError ):
548
+ t .transform_angles (angles , points [0 :2 , 0 :1 ])
549
549
550
550
# Number of angles != Number of points
551
- assert_raises (ValueError , t .transform_angles , angles , points [0 :2 , :])
551
+ with pytest .raises (ValueError ):
552
+ t .transform_angles (angles , points [0 :2 , :])
552
553
553
554
554
555
def test_nonsingular ():
@@ -567,12 +568,18 @@ def test_invalid_arguments():
567
568
# raises a ValueError, and a wrong shape with a possible number
568
569
# of dimensions is caught by our CALL_CPP macro, which always
569
570
# raises the less precise RuntimeError.
570
- assert_raises (ValueError , t .transform , 1 )
571
- assert_raises (ValueError , t .transform , [[[1 ]]])
572
- assert_raises (RuntimeError , t .transform , [])
573
- assert_raises (RuntimeError , t .transform , [1 ])
574
- assert_raises (RuntimeError , t .transform , [[1 ]])
575
- assert_raises (RuntimeError , t .transform , [[1 , 2 , 3 ]])
571
+ with pytest .raises (ValueError ):
572
+ t .transform (1 )
573
+ with pytest .raises (ValueError ):
574
+ t .transform ([[[1 ]]])
575
+ with pytest .raises (RuntimeError ):
576
+ t .transform ([])
577
+ with pytest .raises (RuntimeError ):
578
+ t .transform ([1 ])
579
+ with pytest .raises (RuntimeError ):
580
+ t .transform ([[1 ]])
581
+ with pytest .raises (RuntimeError ):
582
+ t .transform ([[1 , 2 , 3 ]])
576
583
577
584
578
585
def test_transformed_path ():
@@ -614,8 +621,3 @@ def test_transformed_patch_path():
614
621
patch .set_radius (0.5 )
615
622
assert np .allclose (tpatch .get_fully_transformed_path ().vertices ,
616
623
points )
617
-
618
-
619
- if __name__ == '__main__' :
620
- import nose
621
- nose .runmodule (argv = ['-s' , '--with-doctest' ], exit = False )
0 commit comments