88
99from nose .tools import assert_equal , assert_raises
1010import numpy .testing as np_test
11- from numpy .testing import assert_almost_equal
11+ from numpy .testing import assert_almost_equal , assert_array_equal
1212from matplotlib .transforms import Affine2D , BlendedGenericTransform
1313from matplotlib .path import Path
1414from matplotlib .scale import LogScale
@@ -450,14 +450,14 @@ def test_line_extents_for_non_affine_transData(self):
450450 expeted_data_lim )
451451
452452
453+ def assert_bbox_eq (bbox1 , bbox2 ):
454+ assert_array_equal (bbox1 .bounds , bbox2 .bounds )
455+
456+
453457def test_bbox_intersection ():
454458 bbox_from_ext = mtrans .Bbox .from_extents
455459 inter = mtrans .Bbox .intersection
456460
457- from numpy .testing import assert_array_equal as assert_a_equal
458- def assert_bbox_eq (bbox1 , bbox2 ):
459- assert_a_equal (bbox1 .bounds , bbox2 .bounds )
460-
461461 r1 = bbox_from_ext (0 , 0 , 1 , 1 )
462462 r2 = bbox_from_ext (0.5 , 0.5 , 1.5 , 1.5 )
463463 r3 = bbox_from_ext (0.5 , 0 , 0.75 , 0.75 )
@@ -476,6 +476,18 @@ def assert_bbox_eq(bbox1, bbox2):
476476 assert_bbox_eq (inter (r1 , r5 ), bbox_from_ext (1 , 1 , 1 , 1 ))
477477
478478
479+ def test_bbox_as_strings ():
480+ b = mtrans .Bbox ([[.5 , 0 ], [.75 , .75 ]])
481+ assert_bbox_eq (b , eval (repr (b ), {'Bbox' : mtrans .Bbox }))
482+ asdict = eval (str (b ), {'Bbox' : dict })
483+ for k , v in asdict .items ():
484+ assert_equal (getattr (b , k ), v )
485+ fmt = '.1f'
486+ asdict = eval (format (b , fmt ), {'Bbox' : dict })
487+ for k , v in asdict .items ():
488+ assert_equal (eval (format (getattr (b , k ), fmt )), v )
489+
490+
479491if __name__ == '__main__' :
480492 import nose
481493 nose .runmodule (argv = ['-s' ,'--with-doctest' ], exit = False )
0 commit comments