diff --git a/colorpedia/inputs.py b/colorpedia/inputs.py index 17be065..f93d65e 100644 --- a/colorpedia/inputs.py +++ b/colorpedia/inputs.py @@ -42,6 +42,8 @@ def normalize_degree_angle(value: Union[float, int]) -> float: def normalize_hex_code(value: str) -> str: + if isinstance(value, int): + value = str(value) if isinstance(value, str) and re.search(HEX_REGEX, value): return value if len(value) == 6 else "".join(c * 2 for c in value) raise InputValueError("hex code", f"a string matching {HEX_REGEX}") diff --git a/tests/test_inputs.py b/tests/test_inputs.py index ba6bcfe..dddd4f7 100644 --- a/tests/test_inputs.py +++ b/tests/test_inputs.py @@ -122,14 +122,14 @@ def test_normalize_degree_angle_bad_arg(bad_arg): @pytest.mark.parametrize( ("arg", "expected"), - (("ABC", "AABBCC"), ("ABCDEF", "ABCDEF"), ("FFFFFF", "FFFFFF")), + (("ABC", "AABBCC"), ("ABCDEF", "ABCDEF"), ("FFFFFF", "FFFFFF"), (212121, "212121")), ) def test_normalize_hex_code(arg, expected): assert normalize_hex_code(arg) == expected @pytest.mark.parametrize( - "bad_arg", ("", "F", "FF", "FFFFFH", "#FFFFFF", True, False, max, None, []) + "bad_arg", ("", "F", "FFFFFH", "#FFFFFF", 212121.0, True, False, max, None, []) ) def test_normalize_hex_code_bad_arg(bad_arg): with pytest.raises(InputValueError) as err: