66import numpy as np
77import matplotlib .pyplot as plt
88import matplotlib .tri as mtri
9- from nose . tools import assert_equal , assert_raises , assert_true , assert_false
9+ import pytest
1010from numpy .testing import assert_array_equal , assert_array_almost_equal ,\
1111 assert_array_less
1212import numpy .ma .testutils as matest
@@ -39,14 +39,14 @@ def test_delaunay():
3939 assert_array_almost_equal (triang .y , y )
4040
4141 # Triangles - integers.
42- assert_equal ( len (triang .triangles ), ntriangles )
43- assert_equal ( np .min (triang .triangles ), 0 )
44- assert_equal ( np .max (triang .triangles ), npoints - 1 )
42+ assert len (triang .triangles ) == ntriangles
43+ assert np .min (triang .triangles ) == 0
44+ assert np .max (triang .triangles ) == npoints - 1
4545
4646 # Edges - integers.
47- assert_equal ( len (triang .edges ), nedges )
48- assert_equal ( np .min (triang .edges ), 0 )
49- assert_equal ( np .max (triang .edges ), npoints - 1 )
47+ assert len (triang .edges ) == nedges
48+ assert np .min (triang .edges ) == 0
49+ assert np .max (triang .edges ) == npoints - 1
5050
5151 # Neighbors - integers.
5252 # Check that neighbors calculated by C++ triangulation class are the same
@@ -86,7 +86,8 @@ def test_delaunay_points_in_line():
8686 # that delaunay code fails gracefully.
8787 x = np .linspace (0.0 , 10.0 , 11 )
8888 y = np .linspace (0.0 , 10.0 , 11 )
89- assert_raises (RuntimeError , mtri .Triangulation , x , y )
89+ with pytest .raises (RuntimeError ):
90+ mtri .Triangulation (x , y )
9091
9192 # Add an extra point not on the line and the triangulation is OK.
9293 x = np .append (x , 2.0 )
@@ -96,16 +97,21 @@ def test_delaunay_points_in_line():
9697
9798def test_delaunay_insufficient_points ():
9899 # Triangulation should raise a ValueError if passed less than 3 points.
99- assert_raises (ValueError , mtri .Triangulation , [], [])
100- assert_raises (ValueError , mtri .Triangulation , [1 ], [5 ])
101- assert_raises (ValueError , mtri .Triangulation , [1 , 2 ], [5 , 6 ])
100+ with pytest .raises (ValueError ):
101+ mtri .Triangulation ([], [])
102+ with pytest .raises (ValueError ):
103+ mtri .Triangulation ([1 ], [5 ])
104+ with pytest .raises (ValueError ):
105+ mtri .Triangulation ([1 , 2 ], [5 , 6 ])
102106
103107 # Triangulation should also raise a ValueError if passed duplicate points
104108 # such that there are less than 3 unique points.
105- assert_raises (ValueError , mtri .Triangulation , [1 , 2 , 1 ], [5 , 6 , 5 ])
106- assert_raises (ValueError , mtri .Triangulation , [1 , 2 , 2 ], [5 , 6 , 6 ])
107- assert_raises (ValueError , mtri .Triangulation , [1 , 1 , 1 , 2 , 1 , 2 ],
108- [5 , 5 , 5 , 6 , 5 , 6 ])
109+ with pytest .raises (ValueError ):
110+ mtri .Triangulation ([1 , 2 , 1 ], [5 , 6 , 5 ])
111+ with pytest .raises (ValueError ):
112+ mtri .Triangulation ([1 , 2 , 2 ], [5 , 6 , 6 ])
113+ with pytest .raises (ValueError ):
114+ mtri .Triangulation ([1 , 1 , 1 , 2 , 1 , 2 ], [5 , 5 , 5 , 6 , 5 , 6 ])
109115
110116
111117def test_delaunay_robust ():
@@ -149,7 +155,7 @@ def tris_contain_point(triang, xy):
149155 # overlapping triangles; qhull is OK.
150156 triang = mtri .Triangulation (tri_points [:, 0 ], tri_points [:, 1 ])
151157 for test_point in test_points :
152- assert_equal ( tris_contain_point (triang , test_point ), 1 )
158+ assert tris_contain_point (triang , test_point ) == 1
153159
154160 # If ignore the first point of tri_points, matplotlib.delaunay throws a
155161 # KeyError when calculating the convex hull; qhull is OK.
@@ -283,7 +289,7 @@ def test_trifinder():
283289 assert_array_equal (tris , [- 1 , 0 , 1 , - 1 ])
284290
285291 triang .set_mask ([1 , 0 ])
286- assert_equal ( trifinder , triang .get_trifinder () )
292+ assert trifinder == triang .get_trifinder ()
287293 tris = trifinder (xs , ys )
288294 assert_array_equal (tris , [- 1 , - 1 , 1 , - 1 ])
289295
@@ -971,10 +977,10 @@ def test_trirefiner_fortran_contiguous_triangles():
971977 # github issue 4180. Test requires two arrays of triangles that are
972978 # identical except that one is C-contiguous and one is fortran-contiguous.
973979 triangles1 = np .array ([[2 , 0 , 3 ], [2 , 1 , 0 ]])
974- assert_false ( np .isfortran (triangles1 ) )
980+ assert not np .isfortran (triangles1 )
975981
976982 triangles2 = np .array (triangles1 , copy = True , order = 'F' )
977- assert_true ( np .isfortran (triangles2 ) )
983+ assert np .isfortran (triangles2 )
978984
979985 x = np .array ([0.39 , 0.59 , 0.43 , 0.32 ])
980986 y = np .array ([33.99 , 34.01 , 34.19 , 34.18 ])
@@ -1033,9 +1039,5 @@ def test_tricontourf_decreasing_levels():
10331039 y = [0.0 , 0.0 , 1.0 ]
10341040 z = [0.2 , 0.4 , 0.6 ]
10351041 plt .figure ()
1036- assert_raises (ValueError , plt .tricontourf , x , y , z , [1.0 , 0.0 ])
1037-
1038-
1039- if __name__ == '__main__' :
1040- import nose
1041- nose .runmodule (argv = ['-s' , '--with-doctest' ], exit = False )
1042+ with pytest .raises (ValueError ):
1043+ plt .tricontourf (x , y , z , [1.0 , 0.0 ])
0 commit comments