Skip to content
Snippets Groups Projects
Commit 0161f4ef authored by Sebastian Müller's avatar Sebastian Müller 🐈
Browse files

add tests

parent ff1e7cb7
No related branches found
No related tags found
No related merge requests found
......@@ -127,11 +127,12 @@ examples/test_domain
examples/qmod.nc
examples/qmod_couple.nc
examples/aet.nc
examples/*.csv
tests/runoff_out.csv
/docs/build/
/docs/finam_mhm.*
/docs/modules.rst
*.csv
*.DS_Store
......
This diff is collapsed.
import os
import shutil
import unittest
from datetime import datetime, timedelta
from pathlib import Path
import finam as fm
import mhm
import numpy as np
from numpy.testing import assert_allclose
import finam_mhm as fm_mhm
def str2date(dtstr):
return datetime.fromisoformat(dtstr)
class TestMHM(unittest.TestCase):
def test_creation(self):
pass
@classmethod
def setUpClass(self):
self.here = Path(__file__).parent
os.chdir(self.here)
self.test_domain = self.here / "test_domain"
mhm.download_test(path=self.test_domain)
def tearDown(self):
# move out of test-domain directory after each test
os.chdir(self.here)
@classmethod
def tearDownClass(self):
shutil.rmtree(self.test_domain)
def test_run(self):
start_date = datetime(1990, 1, 1)
end_date = datetime(1991, 1, 1)
mhm = fm_mhm.MHM(cwd=self.test_domain)
csv = fm.modules.CsvWriter(
path=self.here / "runoff_out.csv",
inputs=["Runoff"],
time_column="Time",
separator=",",
start=start_date,
step=timedelta(hours=1),
)
composition = fm.Composition([mhm, csv])
composition.initialize()
(
mhm.outputs["L1_TOTAL_RUNOFF"]
>> fm.adapters.GridToValue(func=lambda x: x[0, 8, 4])
>> csv["Runoff"]
)
composition.run(start_time=start_date, end_time=end_date)
ref = np.genfromtxt(
self.here / "test_files/ref_runoff.csv",
names=True,
converters={0: str2date},
delimiter=",",
dtype=None,
encoding="utf-8",
)
ref = np.array([i[1] for i in ref])
out = np.genfromtxt(
self.here / "runoff_out.csv",
names=True,
converters={0: str2date},
delimiter=",",
dtype=None,
encoding="utf-8",
)
out = np.array([i[1] for i in out])
assert_allclose(ref, out)
if __name__ == "__main__":
unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment