Skip to content

Commit 07069ff

Browse files
committed
ENH: unit test for simulation.run
ENH: better .gitignore
1 parent 83208a6 commit 07069ff

4 files changed

Lines changed: 235 additions & 15 deletions

File tree

.gitignore

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
tests/output_test/
2+
tests/hawaii/
3+
14
# Added
25
/wheelhouse/
36
*.whl
@@ -42,3 +45,181 @@ compile_commands.json
4245
*.exe
4346
*.out
4447
*.app
48+
49+
50+
#python
51+
52+
# Byte-compiled / optimized / DLL files
53+
__pycache__/
54+
*.py[cod]
55+
*$py.class
56+
57+
# C extensions
58+
*.so
59+
60+
# Distribution / packaging
61+
.Python
62+
build/
63+
develop-eggs/
64+
dist/
65+
downloads/
66+
eggs/
67+
.eggs/
68+
lib/
69+
lib64/
70+
parts/
71+
sdist/
72+
var/
73+
wheels/
74+
share/python-wheels/
75+
*.egg-info/
76+
.installed.cfg
77+
*.egg
78+
MANIFEST
79+
80+
# PyInstaller
81+
# Usually these files are written by a python script from a template
82+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
83+
*.manifest
84+
*.spec
85+
86+
# Installer logs
87+
pip-log.txt
88+
pip-delete-this-directory.txt
89+
90+
# Unit test / coverage reports
91+
htmlcov/
92+
.tox/
93+
.nox/
94+
.coverage
95+
.coverage.*
96+
.cache
97+
nosetests.xml
98+
coverage.xml
99+
*.cover
100+
*.py,cover
101+
.hypothesis/
102+
.pytest_cache/
103+
cover/
104+
105+
# Translations
106+
*.mo
107+
*.pot
108+
109+
# Django stuff:
110+
*.log
111+
local_settings.py
112+
db.sqlite3
113+
db.sqlite3-journal
114+
115+
# Flask stuff:
116+
instance/
117+
.webassets-cache
118+
119+
# Scrapy stuff:
120+
.scrapy
121+
122+
# Sphinx documentation
123+
docs/_build/
124+
125+
# PyBuilder
126+
.pybuilder/
127+
target/
128+
129+
# Jupyter Notebook
130+
.ipynb_checkpoints
131+
132+
# IPython
133+
profile_default/
134+
ipython_config.py
135+
136+
# pyenv
137+
# For a library or package, you might want to ignore these files since the code is
138+
# intended to run in multiple environments; otherwise, check them in:
139+
# .python-version
140+
141+
# pipenv
142+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
143+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
144+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
145+
# install all needed dependencies.
146+
#Pipfile.lock
147+
148+
# UV
149+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
150+
# This is especially recommended for binary packages to ensure reproducibility, and is more
151+
# commonly ignored for libraries.
152+
#uv.lock
153+
154+
# poetry
155+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
156+
# This is especially recommended for binary packages to ensure reproducibility, and is more
157+
# commonly ignored for libraries.
158+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
159+
#poetry.lock
160+
161+
# pdm
162+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
163+
#pdm.lock
164+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
165+
# in version control.
166+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
167+
.pdm.toml
168+
.pdm-python
169+
.pdm-build/
170+
171+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
172+
__pypackages__/
173+
174+
# Celery stuff
175+
celerybeat-schedule
176+
celerybeat.pid
177+
178+
# SageMath parsed files
179+
*.sage.py
180+
181+
# Environments
182+
.env
183+
.venv
184+
env/
185+
venv/
186+
ENV/
187+
env.bak/
188+
venv.bak/
189+
190+
# Spyder project settings
191+
.spyderproject
192+
.spyproject
193+
194+
# Rope project settings
195+
.ropeproject
196+
197+
# mkdocs documentation
198+
/site
199+
200+
# mypy
201+
.mypy_cache/
202+
.dmypy.json
203+
dmypy.json
204+
205+
# Pyre type checker
206+
.pyre/
207+
208+
# pytype static type analyzer
209+
.pytype/
210+
211+
# Cython debug symbols
212+
cython_debug/
213+
214+
# PyCharm
215+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
216+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
217+
# and can be added to the global gitignore or merged into this file. For a more nuclear
218+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
219+
#.idea/
220+
221+
# Ruff stuff:
222+
.ruff_cache/
223+
224+
# PyPI configuration file
225+
.pypirc

examples/run_simulation.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/conftest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from pathlib import Path
2+
from pyflowy import util
3+
import pytest
4+
5+
FILEPATH = Path(__file__).parent
6+
7+
@pytest.fixture
8+
def hawaii_example() -> tuple[Path, Path]:
9+
toml_filepath = Path(f"{FILEPATH}/hawaii/input.toml")
10+
asc_filepath = Path(f"{FILEPATH}/hawaii/test20m.asc")
11+
util.download_file_from_github( toml_filepath, relative_file_path="examples/KILAUEA2014-2015/input.toml" )
12+
util.download_file_from_github( asc_filepath, relative_file_path="examples/KILAUEA2014-2015/test20m.asc" )
13+
return toml_filepath, asc_filepath

tests/test_simulation.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import pytest
2+
import numpy as np
3+
import pyflowy as pfy
4+
from pyflowy import util
5+
from pathlib import Path
6+
7+
FILEPATH = Path(__file__).parent
8+
9+
def test_simulation(hawaii_example):
10+
11+
toml_filepath, asc_filepath = hawaii_example
12+
13+
input_params = pfy.flowycpp.parse_config( toml_filepath )
14+
input_params.write_thickness_every_n_lobes = 5000
15+
pfy.flowycpp.validate_settings(input_params)
16+
17+
output_folder = Path(f"{FILEPATH}/output_test")
18+
# Remove any previous files because otherwise you just get more extra files and the old ones persist
19+
if output_folder.exists():
20+
[f.unlink() for f in output_folder.glob("*")]
21+
output_folder.rmdir()
22+
23+
input_params.output_folder = output_folder
24+
input_params.source = asc_filepath
25+
26+
# Change some of the output settings
27+
input_params.output_settings.use_netcdf = True
28+
input_params.output_settings.crop_to_content = True
29+
input_params.output_settings.data_type = pfy.flowycpp.StorageDataType.Short
30+
31+
simulation = pfy.flowycpp.Simulation(input_params, None)
32+
simulation.run()
33+
34+
assert Path(output_folder/f"{input_params.run_name}_thickness_after_{input_params.write_thickness_every_n_lobes}_lobes.nc").exists()
35+
# There is only one "masking threshold" value but internally this is a list
36+
assert Path(output_folder/f"{input_params.run_name}_thickness_masked_{input_params.masking_threshold[-1]}.nc").exists()
37+
assert Path(output_folder/f"{input_params.run_name}_hazard_full.nc").exists()
38+
# Same deal for the masking threshold for the hazard
39+
assert Path(output_folder/f"{input_params.run_name}_hazard_masked_{input_params.masking_threshold[-1]}.nc").exists()
40+
# Make sure that this summary file was written
41+
assert Path(output_folder / f"{input_params.run_name}_avg_thick.txt").exists()

0 commit comments

Comments
 (0)