Skip to content

Commit 9bc7aac

Browse files
authored
test: accommodate slight triangle grid variations (#2757)
Triangle can give slightly different results depending on platform and compiler
1 parent fe620d5 commit 9bc7aac

1 file changed

Lines changed: 8 additions & 13 deletions

File tree

autotest/test_grid.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33
import warnings
44
from contextlib import nullcontext
5+
from platform import system
56
from warnings import warn
67

78
import matplotlib
@@ -1492,17 +1493,9 @@ def test_voronoi_grid(request, function_tmpdir, grid_case):
14921493
name = request.node.name.replace("/", "_").replace("\\", "_").replace(":", "_")
14931494
ncpl, vor, gridprops, grid = grid_case()
14941495

1495-
# TODO: debug off-by-3 issue
1496-
# could be a rounding error as described here:
1497-
# https://github.com/modflowpy/flopy/issues/1492#issuecomment-1210596349
1498-
1499-
# ensure proper number of cells
1500-
almost_right = ncpl == 538 and gridprops["ncpl"] == 535
1501-
if almost_right:
1502-
warn("off-by-3")
1503-
15041496
# ensure that all cells have 3 or more points
15051497
invalid_cells = [i for i, ivts in enumerate(vor.iverts) if len(ivts) < 3]
1498+
assert len(invalid_cells) == 0
15061499

15071500
# make a plot including invalid cells
15081501
fig = plt.figure(figsize=(10, 10))
@@ -1512,10 +1505,12 @@ def test_voronoi_grid(request, function_tmpdir, grid_case):
15121505
ax.plot(grid.xcellcenters[invalid_cells], grid.ycellcenters[invalid_cells], "ro")
15131506
plt.savefig(function_tmpdir / f"{name}.png")
15141507

1515-
assert ncpl == gridprops["ncpl"] or almost_right
1516-
assert len(invalid_cells) == 0, (
1517-
f"The following cells do not have 3 or more vertices.\n{invalid_cells}"
1518-
)
1508+
# ensure proper number of cells. the grid may be slightly different
1509+
# on different platforms depending which compiler triangle is built
1510+
# with, so allow small variations.
1511+
tol = 10 if system() == "Windows" else 3
1512+
assert abs(ncpl - gridprops["ncpl"]) <= tol
1513+
assert len(invalid_cells) == 0
15191514

15201515

15211516
@pytest.fixture

0 commit comments

Comments
 (0)