Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 41fce6b

Browse files
committed
TST: use pytest.mark.parametrize instead of a for loop
Makes it a bit easier to identify failing cases.
1 parent d5ae201 commit 41fce6b

1 file changed

Lines changed: 52 additions & 55 deletions

File tree

lib/matplotlib/tests/test_path.py

Lines changed: 52 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -265,81 +265,78 @@ def test_path_deepcopy():
265265
copy.deepcopy(path2)
266266

267267

268-
def test_path_intersect_path():
268+
@pytest.mark.parametrize('phi', np.concatenate([
269+
np.array([0, 15, 30, 45, 60, 75, 90, 105, 120, 135]) + delta
270+
for delta in [-1, 0, 1]]))
271+
def test_path_intersect_path(phi):
269272
# test for the range of intersection angles
270-
base_angles = np.array([0, 15, 30, 45, 60, 75, 90, 105, 120, 135])
271-
angles = np.concatenate([base_angles, base_angles + 1, base_angles - 1])
272273
eps_array = [1e-5, 1e-8, 1e-10, 1e-12]
273274

274-
for phi in angles:
275+
transform = transforms.Affine2D().rotate(np.deg2rad(phi))
275276

276-
transform = transforms.Affine2D().rotate(np.deg2rad(phi))
277+
# a and b intersect at angle phi
278+
a = Path([(-2, 0), (2, 0)])
279+
b = transform.transform_path(a)
280+
assert a.intersects_path(b) and b.intersects_path(a)
277281

278-
# a and b intersect at angle phi
279-
a = Path([(-2, 0), (2, 0)])
280-
b = transform.transform_path(a)
281-
assert a.intersects_path(b) and b.intersects_path(a)
282+
# a and b touch at angle phi at (0, 0)
283+
a = Path([(0, 0), (2, 0)])
284+
b = transform.transform_path(a)
285+
assert a.intersects_path(b) and b.intersects_path(a)
282286

283-
# a and b touch at angle phi at (0, 0)
284-
a = Path([(0, 0), (2, 0)])
285-
b = transform.transform_path(a)
286-
assert a.intersects_path(b) and b.intersects_path(a)
287+
# a and b are orthogonal and intersect at (0, 3)
288+
a = transform.transform_path(Path([(0, 1), (0, 3)]))
289+
b = transform.transform_path(Path([(1, 3), (0, 3)]))
290+
assert a.intersects_path(b) and b.intersects_path(a)
287291

288-
# a and b are orthogonal and intersect at (0, 3)
289-
a = transform.transform_path(Path([(0, 1), (0, 3)]))
290-
b = transform.transform_path(Path([(1, 3), (0, 3)]))
291-
assert a.intersects_path(b) and b.intersects_path(a)
292+
# a and b are collinear and intersect at (0, 3)
293+
a = transform.transform_path(Path([(0, 1), (0, 3)]))
294+
b = transform.transform_path(Path([(0, 5), (0, 3)]))
295+
assert a.intersects_path(b) and b.intersects_path(a)
292296

293-
# a and b are collinear and intersect at (0, 3)
294-
a = transform.transform_path(Path([(0, 1), (0, 3)]))
295-
b = transform.transform_path(Path([(0, 5), (0, 3)]))
296-
assert a.intersects_path(b) and b.intersects_path(a)
297+
# self-intersect
298+
assert a.intersects_path(a)
297299

298-
# self-intersect
299-
assert a.intersects_path(a)
300+
# a contains b
301+
a = transform.transform_path(Path([(0, 0), (5, 5)]))
302+
b = transform.transform_path(Path([(1, 1), (3, 3)]))
303+
assert a.intersects_path(b) and b.intersects_path(a)
300304

301-
# a contains b
302-
a = transform.transform_path(Path([(0, 0), (5, 5)]))
303-
b = transform.transform_path(Path([(1, 1), (3, 3)]))
304-
assert a.intersects_path(b) and b.intersects_path(a)
305+
# a and b are collinear but do not intersect
306+
a = transform.transform_path(Path([(0, 1), (0, 5)]))
307+
b = transform.transform_path(Path([(3, 0), (3, 3)]))
308+
assert not a.intersects_path(b) and not b.intersects_path(a)
309+
310+
# a and b are on the same line but do not intersect
311+
a = transform.transform_path(Path([(0, 1), (0, 5)]))
312+
b = transform.transform_path(Path([(0, 6), (0, 7)]))
313+
assert not a.intersects_path(b) and not b.intersects_path(a)
305314

306-
# a and b are collinear but do not intersect
315+
# Note: 1e-13 is the absolute tolerance error used for
316+
# `isclose` function from src/_path.h
317+
318+
# a and b are parallel but do not touch
319+
for eps in eps_array:
307320
a = transform.transform_path(Path([(0, 1), (0, 5)]))
308-
b = transform.transform_path(Path([(3, 0), (3, 3)]))
321+
b = transform.transform_path(Path([(0 + eps, 1), (0 + eps, 5)]))
309322
assert not a.intersects_path(b) and not b.intersects_path(a)
310323

311-
# a and b are on the same line but do not intersect
324+
# a and b are on the same line but do not intersect (really close)
325+
for eps in eps_array:
312326
a = transform.transform_path(Path([(0, 1), (0, 5)]))
313-
b = transform.transform_path(Path([(0, 6), (0, 7)]))
327+
b = transform.transform_path(Path([(0, 5 + eps), (0, 7)]))
314328
assert not a.intersects_path(b) and not b.intersects_path(a)
315329

316-
# Note: 1e-13 is the absolute tolerance error used for
317-
# `isclose` function from src/_path.h
318-
319-
# a and b are parallel but do not touch
320-
for eps in eps_array:
321-
a = transform.transform_path(Path([(0, 1), (0, 5)]))
322-
b = transform.transform_path(Path([(0 + eps, 1), (0 + eps, 5)]))
323-
assert not a.intersects_path(b) and not b.intersects_path(a)
324-
325-
# a and b are on the same line but do not intersect (really close)
326-
for eps in eps_array:
327-
a = transform.transform_path(Path([(0, 1), (0, 5)]))
328-
b = transform.transform_path(Path([(0, 5 + eps), (0, 7)]))
329-
assert not a.intersects_path(b) and not b.intersects_path(a)
330-
331-
# a and b are on the same line and intersect (really close)
332-
for eps in eps_array:
333-
a = transform.transform_path(Path([(0, 1), (0, 5)]))
334-
b = transform.transform_path(Path([(0, 5 - eps), (0, 7)]))
335-
assert a.intersects_path(b) and b.intersects_path(a)
336-
337-
# b is the same as a but with an extra point
330+
# a and b are on the same line and intersect (really close)
331+
for eps in eps_array:
338332
a = transform.transform_path(Path([(0, 1), (0, 5)]))
339-
b = transform.transform_path(Path([(0, 1), (0, 2), (0, 5)]))
333+
b = transform.transform_path(Path([(0, 5 - eps), (0, 7)]))
340334
assert a.intersects_path(b) and b.intersects_path(a)
341335

342-
return
336+
# b is the same as a but with an extra point
337+
a = transform.transform_path(Path([(0, 1), (0, 5)]))
338+
b = transform.transform_path(Path([(0, 1), (0, 2), (0, 5)]))
339+
assert a.intersects_path(b) and b.intersects_path(a)
343340

344341

345342
@pytest.mark.parametrize('offset', range(-720, 361, 45))

0 commit comments

Comments
 (0)