6
6
import numpy as np
7
7
import matplotlib .pyplot as plt
8
8
import matplotlib .tri as mtri
9
- from nose . tools import assert_equal , assert_raises , assert_true , assert_false
9
+ import pytest
10
10
from numpy .testing import assert_array_equal , assert_array_almost_equal ,\
11
11
assert_array_less
12
12
import numpy .ma .testutils as matest
@@ -39,14 +39,14 @@ def test_delaunay():
39
39
assert_array_almost_equal (triang .y , y )
40
40
41
41
# 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
45
45
46
46
# 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
50
50
51
51
# Neighbors - integers.
52
52
# Check that neighbors calculated by C++ triangulation class are the same
@@ -86,7 +86,8 @@ def test_delaunay_points_in_line():
86
86
# that delaunay code fails gracefully.
87
87
x = np .linspace (0.0 , 10.0 , 11 )
88
88
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 )
90
91
91
92
# Add an extra point not on the line and the triangulation is OK.
92
93
x = np .append (x , 2.0 )
@@ -96,16 +97,21 @@ def test_delaunay_points_in_line():
96
97
97
98
def test_delaunay_insufficient_points ():
98
99
# 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 ])
102
106
103
107
# Triangulation should also raise a ValueError if passed duplicate points
104
108
# 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 ])
109
115
110
116
111
117
def test_delaunay_robust ():
@@ -149,7 +155,7 @@ def tris_contain_point(triang, xy):
149
155
# overlapping triangles; qhull is OK.
150
156
triang = mtri .Triangulation (tri_points [:, 0 ], tri_points [:, 1 ])
151
157
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
153
159
154
160
# If ignore the first point of tri_points, matplotlib.delaunay throws a
155
161
# KeyError when calculating the convex hull; qhull is OK.
@@ -283,7 +289,7 @@ def test_trifinder():
283
289
assert_array_equal (tris , [- 1 , 0 , 1 , - 1 ])
284
290
285
291
triang .set_mask ([1 , 0 ])
286
- assert_equal ( trifinder , triang .get_trifinder () )
292
+ assert trifinder == triang .get_trifinder ()
287
293
tris = trifinder (xs , ys )
288
294
assert_array_equal (tris , [- 1 , - 1 , 1 , - 1 ])
289
295
@@ -971,10 +977,10 @@ def test_trirefiner_fortran_contiguous_triangles():
971
977
# github issue 4180. Test requires two arrays of triangles that are
972
978
# identical except that one is C-contiguous and one is fortran-contiguous.
973
979
triangles1 = np .array ([[2 , 0 , 3 ], [2 , 1 , 0 ]])
974
- assert_false ( np .isfortran (triangles1 ) )
980
+ assert not np .isfortran (triangles1 )
975
981
976
982
triangles2 = np .array (triangles1 , copy = True , order = 'F' )
977
- assert_true ( np .isfortran (triangles2 ) )
983
+ assert np .isfortran (triangles2 )
978
984
979
985
x = np .array ([0.39 , 0.59 , 0.43 , 0.32 ])
980
986
y = np .array ([33.99 , 34.01 , 34.19 , 34.18 ])
@@ -1033,9 +1039,5 @@ def test_tricontourf_decreasing_levels():
1033
1039
y = [0.0 , 0.0 , 1.0 ]
1034
1040
z = [0.2 , 0.4 , 0.6 ]
1035
1041
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