diff --git a/ammico/colors.py b/ammico/colors.py index 0605a24d..43cdb0c5 100644 --- a/ammico/colors.py +++ b/ammico/colors.py @@ -91,7 +91,12 @@ def analyse_image(self): merge_color=self.merge_color, delta_e_method=self.delta_e_method, ) - self.subdict[rgb_name] += round(color.proportion, 2) + self.subdict[rgb_name] += color.proportion + + # ensure color rounding + for key in self.set_keys().keys(): + if self.subdict[key]: + self.subdict[key] = round(self.subdict[key], 2) return self.subdict diff --git a/ammico/test/test_colors.py b/ammico/test/test_colors.py index 05fef3b2..8d8f2de9 100644 --- a/ammico/test/test_colors.py +++ b/ammico/test/test_colors.py @@ -1,5 +1,6 @@ from ammico.colors import ColorDetector import pytest +from numpy import isclose def test_init(): @@ -57,11 +58,20 @@ def test_analyze_images(get_path): mydict_1 = { "filename": get_path + "IMG_2809.png", } + mydict_2 = { + "filename": get_path + "IMG_2809.png", + } test1 = ColorDetector(mydict_1, delta_e_method="CIE 2000").analyse_image() - assert test1["red"] == 0.0 - assert round(test1["green"], 2) == 0.62 + assert isclose(test1["red"], 0.0, atol=0.01) + assert isclose(test1["green"], 0.63, atol=0.01) + + test2 = ColorDetector(mydict_2).analyse_image() + assert isclose(test2["red"], 0.0, atol=0.01) + assert isclose(test2["green"], 0.06, atol=0.01) - test2 = ColorDetector(mydict_1).analyse_image() - assert test2["red"] == 0.0 - assert test2["green"] == 0.05 + mydict_1["test"] = "test" + test3 = ColorDetector(mydict_1).analyse_image() + assert isclose(test3["red"], 0.0, atol=0.01) + assert isclose(test3["green"], 0.06, atol=0.01) + assert test3["test"] == "test"