From 6b4f9190c52b533c2408ff2b5833e728b01f1ba7 Mon Sep 17 00:00:00 2001 From: fernando-aristizabal Date: Thu, 14 Dec 2023 18:29:26 +0000 Subject: [PATCH] - updated code base with flake8 and black - updated `_assert_pairing_dict_equal()` docstring --- tests/cases_compare.py | 16 ++++++++++------ tests/conftest.py | 14 +++++--------- tests/test_attributes.py | 1 + 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/tests/cases_compare.py b/tests/cases_compare.py index f71040fe..6d65c0cb 100644 --- a/tests/cases_compare.py +++ b/tests/cases_compare.py @@ -13,7 +13,9 @@ from tests.conftest import _load_xarray from gval.utils.schemas import Crosstab_df from gval.comparison.pairing_functions import ( - szudzik_pair_signed, cantor_pair_signed, PairingDict + szudzik_pair_signed, + cantor_pair_signed, + PairingDict, ) @@ -127,11 +129,13 @@ def case_szudzik_pair_signed(c, b, a): expected_dict_data = [ ( - PairingDict({ - (np.finfo(float).max, 1): 1, - (2, np.finfo(float).max): 2, - (np.finfo(float).max, 5): 3, - }) + PairingDict( + { + (np.finfo(float).max, 1): 1, + (2, np.finfo(float).max): 2, + (np.finfo(float).max, 5): 3, + } + ) ) ] diff --git a/tests/conftest.py b/tests/conftest.py index ebd3f65b..9bec53a9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,7 +9,6 @@ import os -import numpy as np import xarray as xr import rioxarray as rxr import geopandas as gpd @@ -95,18 +94,16 @@ def _load_xarray( def _assert_pairing_dict_equal( - computed_dict: Union[dict, PairingDict], expected_dict: Union[dict, PairingDict] + computed_dict: Union[dict, PairingDict], expected_dict: Union[dict, PairingDict] ) -> None: """ Testing function used to test if two pairing dictionaries are equal. - This is necessary because np.nans can be of float or np.float64 kind which makes operator (==) comparisons false. - Parameters ---------- - computed_dict : dict + computed_dict : dict or PairingDict Pairing dict computed to test. - expected_dict : dict + expected_dict : dict or PairingDict Expected pairing dict to compare to. Returns @@ -125,9 +122,8 @@ def _assert_pairing_dict_equal( diff = DeepDiff(expected_dict, computed_dict) if diff: - raise AssertionError( - f"Dictionaries are not equal. {diff}" - ) + raise AssertionError(f"Dictionaries are not equal. {diff}") + def _attributes_to_string( obj: Union[xr.DataArray, xr.Dataset] diff --git a/tests/test_attributes.py b/tests/test_attributes.py index f1f24c88..0ba1f7d2 100644 --- a/tests/test_attributes.py +++ b/tests/test_attributes.py @@ -51,6 +51,7 @@ def test_attribute_tracking( pd.testing.assert_frame_equal(results[0], expected_df) _assert_pairing_dict_equal(results[1].attrs, expected_attr) + @parametrize_with_cases( "candidate_map, benchmark_map, candidate_include, candidate_exclude, benchmark_include, benchmark_exclude, exception", glob="attribute_tracking_fail",