Skip to content

Commit

Permalink
Merge pull request #33 from landlab/barnhark/update_testing_proceedures
Browse files Browse the repository at this point in the history
Update testing procedures
  • Loading branch information
kbarnhart authored Sep 21, 2018
2 parents 9b0aef5 + 9af929f commit 1e5cf0a
Show file tree
Hide file tree
Showing 21 changed files with 3,049 additions and 2,718 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@

*.out
*.pyc

\.pytest_cache/README\.md

\.pytest_cache/v/cache/lastfailed

\.pytest_cache/v/cache/nodeids
25 changes: 20 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ before_install:
brew cleanup -s
rm -rf $(brew --cache)
fi
- mkdir $MPLCONFIGDIR
- touch $MPLCONFIGDIR/matplotlibrc
install:
- echo "Build on $TRAVIS_OS_NAME for Python $TRAVIS_PYTHON_VERSION"
- |
Expand All @@ -33,12 +35,25 @@ install:
- conda config --set always_yes yes --set changeps1 no
- conda create -n _testing python=$TRAVIS_PYTHON_VERSION
- source activate _testing
- conda install scripting -c csdms-stack
- conda install landlab jupyter -c landlab
- |
if [[ "$TRAVIS_BRANCH" == "release" ]]; then
conda install landlab -c conda-forge
else
pushd ../..
git clone --depth=50 https://github.com/landlab/landlab.git landlab/landlab
pushd landlab/landlab
git fetch origin master
git checkout -qf master
git submodule update --init --recursive
conda install --file=requirements.txt
python setup.py develop
popd
popd
fi
- conda install --file=requirements.txt
- conda info -a && conda list
script:
- mkdir -p $MPLCONFIGDIR
- "echo backend: Agg > $MPLCONFIGDIR/matplotlibrc"
- ./run-all-tests.sh
- mkdir -p $HOME/.config/matplotlib # For Python 3.5
- travis_wait 50 pytest -vvv # the cellular atomata test takes over 10 minutes, and the entire process takes about 30 minutes, so we'll give it 50 min
virtualenv:
system_site_packages: false
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,7 @@ def Plot_(grid, VegType, yrs, yr_step=10):
pic += 1
plt.figure(pic)
plt.plot(years, grass_cov, '-g', label='Grass')
plt.hold(True)
plt.plot(years, shrub_cov, '-r', label='Shrub')
plt.hold(True)
plt.plot(years, tree_cov, '-k', label='Tree')
plt.ylabel(' % Coverage ')
plt.xlabel('Time in years')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def Empty_arrays(n, grid, grid1):
Time = np.empty(n) # To record time elapsed from the start of simulation
# CumWaterStress = np.empty([n/55, grid1.number_of_cells])
# Cum Water Stress
VegType = np.empty([n/55, grid1.number_of_cells], dtype=int)
VegType = np.empty([int(n/55), grid1.number_of_cells], dtype=int)
PET_ = np.zeros([365, grid.number_of_cells])
Rad_Factor = np.empty([365, grid.number_of_cells])
EP30 = np.empty([365, grid.number_of_cells])
Expand Down Expand Up @@ -187,9 +187,7 @@ def Plot_(grid, VegType, yrs, yr_step=10):
pic += 1
plt.figure(pic)
plt.plot(years, grass_cov, '-g', label='Grass')
plt.hold(True)
plt.plot(years, shrub_cov, '-r', label='Shrub')
plt.hold(True)
plt.plot(years, tree_cov, '-k', label='Tree')
plt.ylabel(' % Coverage ')
plt.xlabel('Time in years')
Expand Down

Large diffs are not rendered by default.

285 changes: 193 additions & 92 deletions flexure/lots_of_loads.ipynb

Large diffs are not rendered by default.

865 changes: 0 additions & 865 deletions flow_direction_and_accumulation/Comparison of FlowDirectors.ipynb

This file was deleted.

532 changes: 0 additions & 532 deletions flow_direction_and_accumulation/Introduction to FlowDirectors.ipynb

This file was deleted.

This file was deleted.

1,019 changes: 1,019 additions & 0 deletions flow_direction_and_accumulation/compare_FlowDirectors.ipynb

Large diffs are not rendered by default.

692 changes: 692 additions & 0 deletions flow_direction_and_accumulation/the_FlowAccumulator.ipynb

Large diffs are not rendered by default.

556 changes: 556 additions & 0 deletions flow_direction_and_accumulation/the_FlowDirectors.ipynb

Large diffs are not rendered by default.

146 changes: 67 additions & 79 deletions making_components/making_components.ipynb

Large diffs are not rendered by default.

126 changes: 72 additions & 54 deletions normal_fault/normal_fault_component_tutorial.ipynb

Large diffs are not rendered by default.

167 changes: 78 additions & 89 deletions plotting/landlab-plotting.ipynb

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
jupyter
dask
holoviews
pytest
5 changes: 0 additions & 5 deletions run-all-tests.sh

This file was deleted.

199 changes: 0 additions & 199 deletions run_notebook.py

This file was deleted.

66 changes: 66 additions & 0 deletions test_notebooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import os
import subprocess
import tempfile

import nbformat

_TEST_DIR = os.path.abspath(os.path.dirname(__file__))
_EXCLUDE = ["Python_intro.ipynb", "animate-landlab-output.ipynb"]


def all_notebooks(path="."):
notebooks = []
for root, dirs, files in os.walk(path):
if ".ipynb_checkpoints" in root:
continue
for file in files:
if file.endswith(".ipynb") and (file not in _EXCLUDE):
notebooks.append(os.path.join(root, file))
return notebooks


def pytest_generate_tests(metafunc):
if "notebook" in metafunc.fixturenames:
metafunc.parametrize("notebook", all_notebooks(_TEST_DIR))


def _notebook_run(path):
"""Execute a notebook via nbconvert and collect output.
:returns (parsed nb object, execution errors)
"""
_, notebook = os.path.split(path)
base, ext = os.path.splitext(notebook)

with tempfile.NamedTemporaryFile("w", suffix=".ipynb") as fp:
args = [
"jupyter",
"nbconvert",
"--to",
"notebook",
"--execute",
"--ExecutePreprocessor.kernel_name=python",
"--ExecutePreprocessor.timeout=None",
"--output",
fp.name,
"--output-dir=.",
path,
]
subprocess.check_call(args)

nb = nbformat.read(fp.name, nbformat.current_nbformat, encoding="UTF-8")

errors = [
output
for cell in nb.cells
if "outputs" in cell
for output in cell["outputs"]
if output.output_type == "error"
]

return nb, errors


def test_notebook(tmpdir, notebook):
with tmpdir.as_cwd():
nb, errors = _notebook_run(notebook)
assert not errors
Loading

0 comments on commit 1e5cf0a

Please sign in to comment.