From 2fec2685f0bccb14c6002cf2dc2f2a59d9623b2e Mon Sep 17 00:00:00 2001 From: juanbc Date: Wed, 17 Jan 2024 01:23:39 -0300 Subject: [PATCH] style and coverage done --- skcriteria/agg/_agg_base.py | 7 ++++++- skcriteria/cmp/ranks_cmp.py | 1 - skcriteria/testing.py | 4 ++-- tests/utils/test_dict_cmp.py | 4 ++-- tests/utils/test_object_diff.py | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/skcriteria/agg/_agg_base.py b/skcriteria/agg/_agg_base.py index a5ff941..58658a2 100644 --- a/skcriteria/agg/_agg_base.py +++ b/skcriteria/agg/_agg_base.py @@ -189,7 +189,12 @@ def __len__(self): @doc_inherit(DiffEqualityMixin.diff) def diff( - self, other, rtol=1e-05, atol=1e-08, equal_nan=False, check_dtypes=False + self, + other, + rtol=1e-05, + atol=1e-08, + equal_nan=False, + check_dtypes=False, ): def array_allclose(left_value, right_value): return np.allclose( diff --git a/skcriteria/cmp/ranks_cmp.py b/skcriteria/cmp/ranks_cmp.py index 447b019..53a86fa 100644 --- a/skcriteria/cmp/ranks_cmp.py +++ b/skcriteria/cmp/ranks_cmp.py @@ -32,7 +32,6 @@ from sklearn import metrics as _skl_metrics from ..agg import RankResult -from ..core import SKCMethodABC from ..utils import ( AccessorABC, Bunch, diff --git a/skcriteria/testing.py b/skcriteria/testing.py index 89fd788..c2a56ce 100644 --- a/skcriteria/testing.py +++ b/skcriteria/testing.py @@ -128,7 +128,6 @@ def assert_result_equals(left, right, **diff_kws): AssertionError if the two results are not equal. """ - # Check if left is a ResultABC _assert( isinstance(left, ResultABC), @@ -199,7 +198,8 @@ def assert_rcmp_equals(left, right, **diff_kws): # check if right is a RanksComparator _assert( diff.different_types is False, - f"'right' is not a RanksComparator instance. Found {diff.right_type!r}", + "'right' is not a RanksComparator instance. " + f"Found {diff.right_type!r}", ) # check if left and right have the same length diff --git a/tests/utils/test_dict_cmp.py b/tests/utils/test_dict_cmp.py index 7738ceb..f0d7c22 100644 --- a/tests/utils/test_dict_cmp.py +++ b/tests/utils/test_dict_cmp.py @@ -30,8 +30,8 @@ def test_dict_allclose(): - left = {"a": np.array([1, 2, 3]), "b": np.array([4, 5, 6]), "c": 1} - right = {"a": np.array([1, 2, 3]), "b": np.array([4, 5, 6]), "c": 1} + left = {"a": np.array([1, 2, 3]), "b": np.array([4, 5, 6]), "c": {}} + right = {"a": np.array([1, 2, 3]), "b": np.array([4, 5, 6]), "c": {}} assert dict_cmp.dict_allclose(left, right) diff --git a/tests/utils/test_object_diff.py b/tests/utils/test_object_diff.py index 750a138..9792b6e 100644 --- a/tests/utils/test_object_diff.py +++ b/tests/utils/test_object_diff.py @@ -30,6 +30,11 @@ # ============================================================================= +def test_MISSING(): + assert object_diff.MISSING is object_diff._Missing() + assert repr(object_diff.MISSING) == "" + + def test_diff(): class SomeClass: def __init__(self, **kws): @@ -197,6 +202,33 @@ def diff( assert obj_a.aequals(obj_b) is False +def test_DiffEqualityMixin_diff_not_implemented(): + class SomeClass(object_diff.DiffEqualityMixin): + def __init__(self, **kwargs): + self.__dict__.update(kwargs) + + def diff( + self, + other, + rtol=1e-05, + atol=1e-08, + equal_nan=True, + check_dtypes=False, + ): + return super().diff( + other, + rtol=rtol, + atol=atol, + equal_nan=equal_nan, + check_dtypes=check_dtypes, + ) + + obj_a = SomeClass(a=1, b=2, d=5) + + with pytest.raises(NotImplementedError): + obj_a.diff(1) + + def test_DiffEqualityMixin_invalid_diff_parameters(): with pytest.raises(TypeError):