diff --git a/mlair/helpers/testing.py b/mlair/helpers/testing.py index e727d9b50308d339af79f5c5b82b592af6e91921..9820b4956dac09e213df3b9addc317a00ee381b8 100644 --- a/mlair/helpers/testing.py +++ b/mlair/helpers/testing.py @@ -105,7 +105,7 @@ def get_all_args(*args, remove=None, add=None): return res -def test_nested_equality(obj1, obj2): +def check_nested_equality(obj1, obj2): try: print(f"check type {type(obj1)} and {type(obj2)}") @@ -116,13 +116,13 @@ def test_nested_equality(obj1, obj2): assert len(obj1) == len(obj2) for pos in range(len(obj1)): print(f"check pos {obj1[pos]} and {obj2[pos]}") - assert test_nested_equality(obj1[pos], obj2[pos]) is True + assert check_nested_equality(obj1[pos], obj2[pos]) is True elif isinstance(obj1, dict): print(f"check keys {obj1.keys()} and {obj2.keys()}") assert sorted(obj1.keys()) == sorted(obj2.keys()) for k in obj1.keys(): print(f"check pos {obj1[k]} and {obj2[k]}") - assert test_nested_equality(obj1[k], obj2[k]) is True + assert check_nested_equality(obj1[k], obj2[k]) is True elif isinstance(obj1, xr.DataArray): print(f"check xr {obj1} and {obj2}") assert xr.testing.assert_equal(obj1, obj2) is None diff --git a/test/test_helpers/test_filter.py b/test/test_helpers/test_filter.py index 519a36b3438cafd041cc65c43572fc026eced4dd..6f72eda69f92fced8fde8532b812a3bf340fdc80 100644 --- a/test/test_helpers/test_filter.py +++ b/test/test_helpers/test_filter.py @@ -121,22 +121,22 @@ class TestClimateFIRFilter: obj._create_tmp_dimension(xr_array) assert "Could not create new dimension." in e.value.args[0] - def test_minimum_length(self): + def test_next_order(self): obj = object.__new__(ClimateFIRFilter) - res = obj._minimum_length([43], 15, 0, "hamming") + res = obj._next_order([43], 15, 0, "hamming") assert res == 15 - res = obj._minimum_length([43, 13], 15, 0, ("kaiser", 10)) + res = obj._next_order([43, 13], 15, 0, ("kaiser", 10)) assert res == 28 - res = obj._minimum_length([43, 13], 15, 1, "hamming") + res = obj._next_order([43, 13], 15, 1, "hamming") assert res == 15 - res = obj._minimum_length([128, 64, 43], None, 0, "hamming") + res = obj._next_order([128, 64, 43], None, 0, "hamming") assert res == 64 - res = obj._minimum_length([43], None, 0, "hamming") + res = obj._next_order([43], None, 0, "hamming") assert res is None - def test_minimum_length_with_kzf(self): + def test_next_order_with_kzf(self): obj = object.__new__(ClimateFIRFilter) - res = obj._minimum_length([(15, 5), (5, 3)], None, 0, "kzf") + res = obj._next_order([(15, 5), (5, 3)], None, 0, "kzf") assert res == 13 def test_calculate_filter_coefficients(self): @@ -316,7 +316,7 @@ class TestClimateFIRFilter: obj = object.__new__(ClimateFIRFilter) filter_order = 10*24+1 res = obj.clim_filter(xr_array_long_with_var, 24, 0.05, 10*24+1, sampling="1H", time_dim=time_dim, var_dim=var_dim) - assert len(res) == 4 + assert len(res) == 5 # check filter data properties assert res[0].shape == (*xr_array_long_with_var.shape, filter_order + 1) @@ -349,7 +349,7 @@ class TestClimateFIRFilter: var_dim=var_dim, new_dim="total_new_dim", window=("kaiser", 5), minimum_length=1000, apriori=apriori, plot_dates=plot_dates) - assert res[0].shape == (*xr_array_long_with_var.shape, 1000 + 1) + assert res[0].shape == (*xr_array_long_with_var.shape, 1000 + 2) assert res[0].dims == (*xr_array_long_with_var.dims, "total_new_dim") assert np.testing.assert_almost_equal( res[1], obj._calculate_filter_coefficients(("kaiser", 5), filter_order, 0.05, 24)) is None diff --git a/test/test_helpers/test_testing_helpers.py b/test/test_helpers/test_testing_helpers.py index bceed646c345d3add4602e67b55da1553eabdbaa..9b888a91a7c88a31764bd272632b1aab8e6e170f 100644 --- a/test/test_helpers/test_testing_helpers.py +++ b/test/test_helpers/test_testing_helpers.py @@ -1,4 +1,4 @@ -from mlair.helpers.testing import PyTestRegex, PyTestAllEqual, test_nested_equality +from mlair.helpers.testing import PyTestRegex, PyTestAllEqual, check_nested_equality import re import xarray as xr @@ -52,30 +52,30 @@ class TestPyTestAllEqual: class TestNestedEquality: def test_nested_equality_single_entries(self): - assert test_nested_equality(3, 3) is True - assert test_nested_equality(3.9, 3.9) is True - assert test_nested_equality(3.91, 3.9) is False - assert test_nested_equality("3", 3) is False - assert test_nested_equality("3", "3") is True - assert test_nested_equality(None, None) is True + assert check_nested_equality(3, 3) is True + assert check_nested_equality(3.9, 3.9) is True + assert check_nested_equality(3.91, 3.9) is False + assert check_nested_equality("3", 3) is False + assert check_nested_equality("3", "3") is True + assert check_nested_equality(None, None) is True def test_nested_equality_xarray(self): obj1 = xr.DataArray(np.random.randn(2, 3), dims=('x', 'y'), coords={'x': [10, 20], 'y': [0, 10, 20]}) obj2 = xr.ones_like(obj1) * obj1 - assert test_nested_equality(obj1, obj2) is True + assert check_nested_equality(obj1, obj2) is True def test_nested_equality_numpy(self): obj1 = np.random.randn(2, 3) obj2 = obj1 * 1 - assert test_nested_equality(obj1, obj2) is True + assert check_nested_equality(obj1, obj2) is True def test_nested_equality_list_tuple(self): - assert test_nested_equality([3, 3], [3, 3]) is True - assert test_nested_equality((2, 6), (2, 6)) is True - assert test_nested_equality([3, 3.5], [3.5, 3]) is False - assert test_nested_equality([3, 3.5, 10], [3, 3.5]) is False + assert check_nested_equality([3, 3], [3, 3]) is True + assert check_nested_equality((2, 6), (2, 6)) is True + assert check_nested_equality([3, 3.5], [3.5, 3]) is False + assert check_nested_equality([3, 3.5, 10], [3, 3.5]) is False def test_nested_equality_dict(self): - assert test_nested_equality({"a": 3, "b": 10}, {"b": 10, "a": 3}) is True - assert test_nested_equality({"a": 3, "b": [10, 100]}, {"b": [10, 100], "a": 3}) is True - assert test_nested_equality({"a": 3, "b": 10, "c": "c"}, {"b": 10, "a": 3}) is False + assert check_nested_equality({"a": 3, "b": 10}, {"b": 10, "a": 3}) is True + assert check_nested_equality({"a": 3, "b": [10, 100]}, {"b": [10, 100], "a": 3}) is True + assert check_nested_equality({"a": 3, "b": 10, "c": "c"}, {"b": 10, "a": 3}) is False