66
77import unittest
88
9- from nose .tools import assert_equal , assert_raises
109import numpy .testing as np_test
1110from numpy .testing import assert_almost_equal , assert_array_equal
1211from numpy .testing import assert_array_almost_equal
12+ import pytest
1313from matplotlib .transforms import (Affine2D , BlendedGenericTransform , Bbox ,
1414 TransformedPath , TransformedPatchPath )
1515from matplotlib .path import Path
@@ -262,9 +262,9 @@ def setUp(self):
262262# self.stack2_subset.write_graphviz(file('stack2_subset.dot', 'w'))
263263
264264 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
268268
269269 def test_left_to_right_iteration (self ):
270270 stack3 = (self .ta1 + (self .tn1 + (self .ta2 + self .tn2 ))) + self .ta3
@@ -286,12 +286,11 @@ def test_transform_shortcuts(self):
286286 self .assertEqual (self .stack1 - self .stack2_subset , self .ta1 )
287287 self .assertEqual (self .stack2 - self .stack2_subset , self .ta1 )
288288
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
293291
294- assert_raises (ValueError , self .stack1 .__sub__ , self .stack2 )
292+ with pytest .raises (ValueError ):
293+ self .stack1 - self .stack2
295294
296295 aff1 = self .ta1 + (self .ta2 + self .ta3 )
297296 aff2 = self .ta2 + self .ta3
@@ -496,7 +495,7 @@ def test_bbox_intersection():
496495 # r3 contains r2
497496 assert_bbox_eq (inter (r1 , r3 ), r3 )
498497 # no intersection
499- assert_equal ( inter (r1 , r4 ), None )
498+ assert inter (r1 , r4 ) is None
500499 # single point
501500 assert_bbox_eq (inter (r1 , r5 ), bbox_from_ext (1 , 1 , 1 , 1 ))
502501
@@ -506,11 +505,11 @@ def test_bbox_as_strings():
506505 assert_bbox_eq (b , eval (repr (b ), {'Bbox' : mtrans .Bbox }))
507506 asdict = eval (str (b ), {'Bbox' : dict })
508507 for k , v in asdict .items ():
509- assert_equal ( getattr (b , k ), v )
508+ assert getattr (b , k ) == v
510509 fmt = '.1f'
511510 asdict = eval (format (b , fmt ), {'Bbox' : dict })
512511 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
514513
515514
516515def test_transform_single_point ():
@@ -545,10 +544,12 @@ def test_transform_angles():
545544 assert_array_almost_equal (angles , new_angles )
546545
547546 # 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 ])
549549
550550 # 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 , :])
552553
553554
554555def test_nonsingular ():
@@ -567,12 +568,18 @@ def test_invalid_arguments():
567568 # raises a ValueError, and a wrong shape with a possible number
568569 # of dimensions is caught by our CALL_CPP macro, which always
569570 # 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 ]])
576583
577584
578585def test_transformed_path ():
@@ -614,8 +621,3 @@ def test_transformed_patch_path():
614621 patch .set_radius (0.5 )
615622 assert np .allclose (tpatch .get_fully_transformed_path ().vertices ,
616623 points )
617-
618-
619- if __name__ == '__main__' :
620- import nose
621- nose .runmodule (argv = ['-s' , '--with-doctest' ], exit = False )
0 commit comments