Skip to content

Commit

Permalink
[CI] added quantitative tests for telemac
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsail committed Mar 22, 2024
1 parent d8372b9 commit 5c00dcc
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions tests/test_telemac.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import os
import numpy as np
import xarray as xr
import multiprocessing

# from . import DATA_DIR
import pathlib

import pyposeidon
Expand Down Expand Up @@ -70,27 +75,40 @@
}


def telemac(tmpdir, dic):
@pytest.mark.telemac
@pytest.mark.parametrize("case", [case0, case1, case2, case3])
def test_telemac(tmpdir, case):
# initialize a model
rpath = str(tmpdir) + "/"
dic.update({"rpath": rpath}) # use tmpdir for running the model

b = pyposeidon.model.set(**dic)

b.execute()
case.update({"rpath": rpath}) # use tmpdir for running the model

b = pyposeidon.model.set(**case)
b.create()
b.mesh.Dataset.type[:] = "closed"
b.output()
b.save()
b.run()
b.results()
zarr_tar = b.rpath + "/outputs/out_2D.zarr.tar"
assert os.path.exists(zarr_tar)

This comment has been minimized.

Copy link
@pmav99

pmav99 May 9, 2024

Collaborator

Since we do the assertion, what's the point of the if in the next line?

This comment has been minimized.

Copy link
@tomsail

tomsail May 9, 2024

Author Collaborator

good catch. I'll rectify this. thanks

if os.path.exists(zarr_tar):
a = pyposeidon.model.read(rpath + b.module + "_model.json") # read model
a.execute()
a.create()
a.mesh.Dataset.type[:] = "closed"
a.output()
a.save()
a.run()
a.results()
zarr_tar = a.rpath + "/outputs/out_2D.zarr.tar"
return os.path.exists(zarr_tar)
else:
return False


@pytest.mark.telemac
@pytest.mark.parametrize("case", [case0, case1, case2, case3])
def test_answer(tmpdir, case):
assert telemac(tmpdir, case) == True
res = a.rpath + "/results_2D.slf"
assert os.path.exists(zarr_tar)
ds = xr.open_dataset(res, engine="selafin")
if "WH" in ds.variables:
max_WH = ds.WH.max().values
assert np.isclose(max_WH, 4.13, atol=1e-2)
elif "S" in ds.variables:
max_S = ds.S.max().values
print(max_S)
assert max_S < 1
else:
pass

0 comments on commit 5c00dcc

Please sign in to comment.