From 76b422925659ced9b9c9e9e43f6ff056ae81e527 Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Wed, 20 Dec 2023 22:50:36 +1300 Subject: [PATCH] Use `np.testing.assert_allclose` definition. --- .../loaders/tests/test_asano2015.py | 25 ++++++++++--------- .../loaders/tests/test_dyer2017.py | 17 +++++++------ .../loaders/tests/test_ebner1998.py | 13 +++++----- .../loaders/tests/test_hung1995.py | 13 +++++----- colour_datasets/loaders/tests/test_kuopio.py | 9 ++++--- colour_datasets/loaders/tests/test_luo1997.py | 5 ++-- colour_datasets/loaders/tests/test_luo1999.py | 5 ++-- .../loaders/tests/test_winquist2022.py | 5 ++-- 8 files changed, 50 insertions(+), 42 deletions(-) diff --git a/colour_datasets/loaders/tests/test_asano2015.py b/colour_datasets/loaders/tests/test_asano2015.py index f48ffb3..915adc7 100644 --- a/colour_datasets/loaders/tests/test_asano2015.py +++ b/colour_datasets/loaders/tests/test_asano2015.py @@ -5,6 +5,7 @@ import numpy as np from colour import SpectralShape +from colour.constants import TOLERANCE_ABSOLUTE_TESTS from colour_datasets.loaders import DatasetLoader_Asano2015, build_Asano2015 @@ -60,7 +61,7 @@ def test_load(self): SpectralShape(390, 780, 5), ) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( dataset.content["Categorical Observers"][1].XYZ_2[390], np.array( [ @@ -69,10 +70,10 @@ def test_load(self): 0.017705556255144, ] ), - decimal=7, + atol=TOLERANCE_ABSOLUTE_TESTS, ) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( dataset.content["Categorical Observers"][10].LMS_10[780], np.array( [ @@ -81,15 +82,15 @@ def test_load(self): 0.000000000000000, ] ), - decimal=7, + atol=TOLERANCE_ABSOLUTE_TESTS, ) - self.assertAlmostEqual( + np.testing.assert_allclose( dataset.content["Categorical Observers"][5].parameters[ "Shift in S [nm]" ], 0.233255808, - places=7, + atol=TOLERANCE_ABSOLUTE_TESTS, ) self.assertEqual( @@ -97,7 +98,7 @@ def test_load(self): SpectralShape(390, 780, 5), ) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( dataset.content["Colour Normal Observers"][1].XYZ_2[390], np.array( [ @@ -106,10 +107,10 @@ def test_load(self): 0.007492391403616, ] ), - decimal=7, + atol=TOLERANCE_ABSOLUTE_TESTS, ) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( dataset.content["Colour Normal Observers"][10].LMS_10[780], np.array( [ @@ -118,15 +119,15 @@ def test_load(self): 0.000000000000000, ] ), - decimal=7, + atol=TOLERANCE_ABSOLUTE_TESTS, ) - self.assertAlmostEqual( + np.testing.assert_allclose( dataset.content["Colour Normal Observers"][5].parameters[ "Shift in S [nm]" ], 0.000649602695013, - places=7, + atol=TOLERANCE_ABSOLUTE_TESTS, ) self.assertEqual( diff --git a/colour_datasets/loaders/tests/test_dyer2017.py b/colour_datasets/loaders/tests/test_dyer2017.py index d41bc65..2e1370d 100644 --- a/colour_datasets/loaders/tests/test_dyer2017.py +++ b/colour_datasets/loaders/tests/test_dyer2017.py @@ -4,6 +4,7 @@ import unittest import numpy as np +from colour.constants import TOLERANCE_ABSOLUTE_TESTS from colour_datasets.loaders import DatasetLoader_Dyer2017, build_Dyer2017 @@ -54,7 +55,7 @@ def test_load(self): ["camera", "cmf", "illuminant", "training"], ) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( dataset.load()["camera"]["canon eos 5d mark ii"][555], np.array( [ @@ -63,9 +64,9 @@ def test_load(self): 0.028300000000000, ] ), - decimal=7, + atol=TOLERANCE_ABSOLUTE_TESTS, ) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( dataset.load()["cmf"]["cie-1931"][555], np.array( [ @@ -74,14 +75,14 @@ def test_load(self): 0.005749999000000, ] ), - decimal=7, + atol=TOLERANCE_ABSOLUTE_TESTS, ) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( dataset.load()["illuminant"]["iso7589"][555], np.array([0.485000000000000]), - decimal=7, + atol=TOLERANCE_ABSOLUTE_TESTS, ) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( dataset.load()["training"]["190-patch"][555], np.array( [ @@ -277,7 +278,7 @@ def test_load(self): 0.158126080000000, ] ), - decimal=7, + atol=TOLERANCE_ABSOLUTE_TESTS, ) diff --git a/colour_datasets/loaders/tests/test_ebner1998.py b/colour_datasets/loaders/tests/test_ebner1998.py index 291d878..f13739d 100644 --- a/colour_datasets/loaders/tests/test_ebner1998.py +++ b/colour_datasets/loaders/tests/test_ebner1998.py @@ -4,6 +4,7 @@ import unittest import numpy as np +from colour.constants import TOLERANCE_ABSOLUTE_TESTS from colour_datasets.loaders import DatasetLoader_Ebner1998, build_Ebner1998 @@ -74,7 +75,7 @@ def test_load(self): ], ) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( dataset.load()["Constant Perceived-Hue Data"][96].XYZ_r, np.array( [ @@ -83,9 +84,9 @@ def test_load(self): 1.088100000000000, ] ), - decimal=7, + atol=TOLERANCE_ABSOLUTE_TESTS, ) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( dataset.load()["Constant Perceived-Hue Data"][96].XYZ_cr, np.array( [ @@ -94,9 +95,9 @@ def test_load(self): 0.211200000000000, ] ), - decimal=7, + atol=TOLERANCE_ABSOLUTE_TESTS, ) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( dataset.load()["Constant Perceived-Hue Data"][96].XYZ_ct, np.array( [ @@ -122,7 +123,7 @@ def test_load(self): [0.704427000000000, 0.763034000000000, 0.112490000000000], ] ), - decimal=7, + atol=TOLERANCE_ABSOLUTE_TESTS, ) diff --git a/colour_datasets/loaders/tests/test_hung1995.py b/colour_datasets/loaders/tests/test_hung1995.py index b042d53..920ed64 100644 --- a/colour_datasets/loaders/tests/test_hung1995.py +++ b/colour_datasets/loaders/tests/test_hung1995.py @@ -4,6 +4,7 @@ import unittest import numpy as np +from colour.constants import TOLERANCE_ABSOLUTE_TESTS from colour_datasets.loaders import DatasetLoader_Hung1995, build_Hung1995 @@ -78,7 +79,7 @@ def test_load(self): ], ) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( dataset.load()["Constant Hue Loci Data - CL"]["Cyan"].XYZ_r, np.array( [ @@ -87,9 +88,9 @@ def test_load(self): 1.182249493927126, ] ), - decimal=7, + atol=TOLERANCE_ABSOLUTE_TESTS, ) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( dataset.load()["Constant Hue Loci Data - CL"]["Cyan"].XYZ_cr, np.array( [ @@ -98,9 +99,9 @@ def test_load(self): 1.149029086144775, ] ), - decimal=7, + atol=TOLERANCE_ABSOLUTE_TESTS, ) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( dataset.load()["Constant Hue Loci Data - CL"]["Cyan"].XYZ_ct, np.array( [ @@ -110,7 +111,7 @@ def test_load(self): [0.495500000000000, 0.722700000000000, 1.149100000000000], ] ), - decimal=7, + atol=TOLERANCE_ABSOLUTE_TESTS, ) diff --git a/colour_datasets/loaders/tests/test_kuopio.py b/colour_datasets/loaders/tests/test_kuopio.py index 7ab417b..2fb7691 100644 --- a/colour_datasets/loaders/tests/test_kuopio.py +++ b/colour_datasets/loaders/tests/test_kuopio.py @@ -10,6 +10,7 @@ import numpy as np from colour import SpectralShape +from colour.constants import TOLERANCE_ABSOLUTE_TESTS from colour_datasets.loaders.kuopio import ( DatasetLoader_AgfaIT872Set, # pyright: ignore @@ -59,7 +60,7 @@ def test_read_sds_from_mat_file_KuopioUniversity(self): sds = read_sds_from_mat_file_KuopioUniversity(mat_file, metadata) self.assertEqual(len(sds), 32) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( sds["5R 6/8 (3)"].values, np.array( [ @@ -96,7 +97,7 @@ def test_read_sds_from_mat_file_KuopioUniversity(self): 51.890000000000000, ] ), - decimal=7, + atol=TOLERANCE_ABSOLUTE_TESTS, ) @@ -3614,10 +3615,10 @@ def test_load(self): } for dataset_loader, values in dataset_loaders.items(): self.assertEqual(len(dataset_loader.load()[values[0]]), values[1]) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( dataset_loader.content[values[0]][values[2]].values, values[3], - decimal=7, + atol=TOLERANCE_ABSOLUTE_TESTS, ) diff --git a/colour_datasets/loaders/tests/test_luo1997.py b/colour_datasets/loaders/tests/test_luo1997.py index a1c20af..e39eb95 100644 --- a/colour_datasets/loaders/tests/test_luo1997.py +++ b/colour_datasets/loaders/tests/test_luo1997.py @@ -4,6 +4,7 @@ import unittest import numpy as np +from colour.constants import TOLERANCE_ABSOLUTE_TESTS from colour_datasets.loaders import DatasetLoader_Luo1997, build_Luo1997 @@ -51,7 +52,7 @@ def test_load(self): dataset = DatasetLoader_Luo1997() self.assertEqual(len(dataset.load().keys()), 8) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( dataset.content["R-HL"].phases["1"].JQCH_v, np.array( [ @@ -162,7 +163,7 @@ def test_load(self): [45.66667000, 61.23224000, 387.50000000], ] ), - decimal=7, + atol=TOLERANCE_ABSOLUTE_TESTS, ) self.assertEqual( diff --git a/colour_datasets/loaders/tests/test_luo1999.py b/colour_datasets/loaders/tests/test_luo1999.py index e6e1d98..a8dd467 100644 --- a/colour_datasets/loaders/tests/test_luo1999.py +++ b/colour_datasets/loaders/tests/test_luo1999.py @@ -4,6 +4,7 @@ import unittest import numpy as np +from colour.constants import TOLERANCE_ABSOLUTE_TESTS from colour_datasets.loaders import DatasetLoader_Luo1999, build_Luo1999 @@ -51,7 +52,7 @@ def test_load(self): dataset = DatasetLoader_Luo1999() self.assertEqual(len(dataset.load().keys()), 37) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( dataset.content["CSAJ-C - da"].XYZ_ct, np.array( [ @@ -145,7 +146,7 @@ def test_load(self): ] ) / 100, - decimal=7, + atol=TOLERANCE_ABSOLUTE_TESTS, ) self.assertEqual( diff --git a/colour_datasets/loaders/tests/test_winquist2022.py b/colour_datasets/loaders/tests/test_winquist2022.py index 31dda28..ec71ff9 100644 --- a/colour_datasets/loaders/tests/test_winquist2022.py +++ b/colour_datasets/loaders/tests/test_winquist2022.py @@ -7,6 +7,7 @@ import unittest import numpy as np +from colour.constants import TOLERANCE_ABSOLUTE_TESTS from colour_datasets.loaders import ( DatasetLoader_Winquist2022, @@ -59,10 +60,10 @@ def test_load(self): dataset = DatasetLoader_Winquist2022() self.assertEqual(len(dataset.load().keys()), 17) - np.testing.assert_array_almost_equal( + np.testing.assert_allclose( dataset.load()["Canon EOS_1DX_Mark_II"][555], np.array([0.27472975, 0.88354587, 0.08992765]), - decimal=7, + atol=TOLERANCE_ABSOLUTE_TESTS, )