Skip to content
Snippets Groups Projects

Resolve "release v1.2.0"

Merged Ghost User requested to merge release_v1.2.0 into master
4 files
+ 100
56
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 47
47
@@ -35,54 +35,54 @@ class PyTestRegex:
@@ -35,54 +35,54 @@ class PyTestRegex:
return self._regex.pattern
return self._regex.pattern
class PyTestAllEqual:
def PyTestAllEqual(check_list: List):
"""
class PyTestAllEqualClass:
Check if all elements in list are the same.
:param check_list: list with elements to check
"""
def __init__(self, check_list: List):
"""Construct class."""
self._list = check_list
self._test_function = None
def _set_test_function(self):
if isinstance(self._list[0], np.ndarray):
self._test_function = np.testing.assert_array_equal
else:
self._test_function = xr.testing.assert_equal
def _check_all_equal(self) -> bool:
"""
Check if all elements are equal.
:return boolean if elements are equal
"""
"""
equal = True
Check if all elements in list are the same.
self._set_test_function()
for b in self._list:
equal *= self._test_function(self._list[0], b) is None
return bool(equal == 1)
def is_true(self) -> bool:
:param check_list: list with elements to check
"""
"""
Start equality check.
:return: true if equality test is passed, false otherwise
def __init__(self, check_list: List):
"""
"""Construct class."""
return self._check_all_equal()
self._list = check_list
self._test_function = None
def xr_all_equal(check_list: List) -> bool:
def _set_test_function(self, _list):
"""
if isinstance(_list[0], list):
Check if all given elements (preferably xarray's) in list are equal.
_test_function = self._set_test_function(_list[0])
self._test_function = lambda r, s: all(map(lambda x, y: _test_function(x, y) is None, r, s))
:param check_list: list with elements to check
elif isinstance(_list[0], np.ndarray):
self._test_function = np.testing.assert_array_equal
:return: boolean if all elements are the same or not
elif isinstance(_list[0], xr.DataArray):
"""
self._test_function = xr.testing.assert_equal
equal = True
else:
for b in check_list:
self._test_function = lambda x, y: self._assert(x, y)
equal *= xr.testing.assert_equal(check_list[0], b) is None
# raise TypeError(f"given type {type(_list[0])} is not supported by PyTestAllEqual.")
return equal == 1
return self._test_function
\ No newline at end of file
 
@staticmethod
 
def _assert(x, y):
 
assert x == y
 
 
def _check_all_equal(self) -> bool:
 
"""
 
Check if all elements are equal.
 
 
:return boolean if elements are equal
 
"""
 
equal = True
 
self._set_test_function(self._list)
 
for b in self._list:
 
equal *= self._test_function(self._list[0], b) in [None, True]
 
return bool(equal == 1)
 
 
def is_true(self) -> bool:
 
"""
 
Start equality check.
 
 
:return: true if equality test is passed, false otherwise
 
"""
 
return self._check_all_equal()
 
 
return PyTestAllEqualClass(check_list).is_true()
Loading