Skip to content

Commit

Permalink
Convert int to str in normalize_hex_code function
Browse files Browse the repository at this point in the history
  • Loading branch information
joowani committed Jan 24, 2021
1 parent 412c3b1 commit 5d9d2a6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions colorpedia/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 5d9d2a6

Please sign in to comment.