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
1 change: 0 additions & 1 deletion .github/workflows/ci_simple_compilation_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ jobs:
uses: actions/checkout@v4
with:
repository: tdep-developers/tdep
ref: fk_github_ci
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Install packages required for building TDEP
Expand Down
Binary file not shown.
43 changes: 5 additions & 38 deletions tests/thermal_conductivity/test_thermal_conductivity.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import numpy as np
import xarray as xr
from pathlib import Path
import pytest

parent = Path(__file__).parent
folder = parent / "reference"

files_hdf5 = [
"outfile.thermal_conductivity_grid.hdf5",
]
file = "outfile.thermal_conductivity"
file_hdf5 = "outfile.thermal_conductivity_grid.hdf5"


def test_thermal_conductivity(file="outfile.thermal_conductivity", atol=20, rtol=5):
def test_thermal_conductivity(file=file, atol=1, rtol=0.1):
file_ref = folder / file
file_new = parent / file

Expand All @@ -23,39 +21,9 @@ def test_thermal_conductivity(file="outfile.thermal_conductivity", atol=20, rtol
)


def get_variables(file):
"""Helper function to get variables from a dataset"""
return list(xr.load_dataset(folder / file).data_vars)


def generate_test_cases(files=files_hdf5):
"""Generate test cases combining files and their variables"""
test_cases = []
for file in files:
vars = get_variables(file)
for var in vars:
test_cases.append((file, var))
return test_cases


@pytest.mark.parametrize("file,var", generate_test_cases())
def test_hdf5(file, var, atol=1, rtol=0.01):
"""Test HDF5 files by comparing variables between reference and new datasets"""
file_ref = folder / file
file_new = parent / file

ds_ref = xr.load_dataset(file_ref)
ds_new = xr.load_dataset(file_new)

x = ds_ref[var]
y = ds_new[var]

np.testing.assert_allclose(x, y, atol=atol, rtol=rtol, err_msg=var)


def test_conductivity_comparison(
file="outfile.thermal_conductivity",
file_grid="outfile.thermal_conductivity_grid.hdf5",
file=parent / file,
file_grid=parent / file_hdf5,
):
"""Check if the thermal conducivities conincide"""
data1 = np.loadtxt(file)
Expand All @@ -72,5 +40,4 @@ def test_conductivity_comparison(

if __name__ == "__main__":
test_thermal_conductivity()
test_hdf5()
test_conductivity_comparison()