From 5d9d2a6f25a5759cff9b437eeb816c477dba9757 Mon Sep 17 00:00:00 2001 From: Joohwan Oh Date: Sun, 24 Jan 2021 13:27:18 -0800 Subject: [PATCH] Convert int to str in normalize_hex_code function --- colorpedia/inputs.py | 2 ++ tests/test_inputs.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) 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: