Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
- master
- develop
- 'release*'
- 'ci-diagnose'
pull_request:
branches: [master, develop]

Expand Down Expand Up @@ -156,6 +157,12 @@ jobs:
run: |
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Create failedTests artifact folder
working-directory: ./autotest
run: |
[ ! -d ./failedTests ] && mkdir ./failedTests
echo "artifact folder for diagnosing failures." > ./failedTests/readme.txt

- name: Run pytest on autotest scripts
if: matrix.run-type == 'std'
working-directory: ./autotest
Expand All @@ -168,6 +175,14 @@ jobs:
run: |
pytest -v -n auto --durations=0 --cov=flopy --cov-report=xml ${{ matrix.test-path }}

- name: Upload failedTests folder as an artifact
uses: actions/upload-artifact@v2
if: failure()
with:
name: failedTests-${{ matrix.os }}-${{ matrix.python-version }}
path: |
./autotest/failedTests/

- name: Print coverage report before upload
working-directory: ./autotest
run: |
Expand Down
14 changes: 14 additions & 0 deletions autotest/ci_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,20 @@ def add_test_dir(self, test_dirs, clean=False):
print(f"adding test directory...{test_dir}")
create_test_dir(test_dir, clean=clean, verbose=self._verbose)

def save_as_artifact(self):
"""
Save test folder in directory ./failedTests. When run as CI
the ./failedTests folder will be stored as a job artifact.

"""
for test_dir in self._test_dirs:
dirname = os.path.split(test_dir)[-1]
dst = f"./failedTests/{dirname}"
print(f"archiving test folder {dirname} in {dst}")
if os.path.isdir(dst):
shutil.rmtree(dst)
shutil.copytree(test_dir, dst)
return

def _get_mf6path():
"""
Expand Down
46 changes: 32 additions & 14 deletions autotest/t075_test_ugrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"""

import os
import shutil

import numpy as np
from flopy.discretization import UnstructuredGrid, VertexGrid
from flopy.utils.triangle import Triangle
Expand Down Expand Up @@ -393,34 +395,50 @@ def test_voronoi_grid2(plot=False):
circle_poly = [(x, y) for x, y in zip(x, y)]
tri = Triangle(maximum_area=50, angle=30, model_ws=model_ws)
tri.add_polygon(circle_poly)
tri.build(verbose=False)
tri.build(verbose=True)

vor = VoronoiGrid(tri)
gridprops = vor.get_gridprops_vertexgrid()
voronoi_grid = VertexGrid(**gridprops, nlay=1)

if plot:
import matplotlib.pyplot as plt
# Check for success
success = True
final_error_message = ""

fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot()
ax.set_aspect("equal")
voronoi_grid.plot(ax=ax)
plt.savefig(os.path.join(model_ws, f"{name}.png"))

# ensure proper number of cells
# ensure proper number of cells; The answer should be answer_ncpl, but
# we are getting slightly different answers with triangle on ubuntu,
# so instead of matching exactly, we are making sure that the number of
# cells are close.
ncpl = gridprops["ncpl"]
errmsg = f"Number of cells should be {answer_ncpl}. Found {ncpl}"
assert ncpl == answer_ncpl, errmsg
if abs(ncpl - answer_ncpl) > 5:
final_error_message += errmsg + "\n"
success = False

# ensure that all cells have 3 or more points
ninvalid_cells = []
for icell, ivts in enumerate(vor.iverts):
if len(ivts) < 3:
ninvalid_cells.append(icell)
errmsg = f"The following cells do not have 3 or more vertices.\n{ninvalid_cells}"
assert len(ninvalid_cells) == 0, errmsg
if len(ninvalid_cells) > 0:
final_error_message += errmsg + "\n"
success = False

if plot:
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot()
ax.set_aspect("equal")
voronoi_grid.plot(ax=ax)
plt.savefig(os.path.join(model_ws, f"{name}.png"))

# copy folder to ./failedTests folder
# uncomment if problems encountered and this will save
# this test to the failedTests artifact on Github actions
# test_setup.save_as_artifact()

assert success, final_error_message
return


Expand Down Expand Up @@ -616,7 +634,7 @@ def test_voronoi_grid5(plot=False):
# test_voronoi_vertex_grid()
#test_voronoi_grid0(plot=True)
#test_voronoi_grid1(plot=True)
#test_voronoi_grid2(plot=True)
test_voronoi_grid2(plot=True)
#test_voronoi_grid3(plot=True)
#test_voronoi_grid4(plot=True)
test_voronoi_grid5(plot=True)
#test_voronoi_grid5(plot=True)