-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03739b0
commit 25a2c74
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from typing import NamedTuple | ||
|
||
|
||
class HairColor(NamedTuple): | ||
code: str | ||
color: str | ||
|
||
|
||
HAIR_COLORS = ( | ||
HairColor("BAL", "Bald"), | ||
HairColor("BLK", "Black"), | ||
HairColor("BLN", "Blond"), | ||
HairColor("BRO", "Brown"), | ||
HairColor("GRY", "Gray"), | ||
HairColor("RED", "Red/Auburn"), | ||
HairColor("SDY", "Sandy"), | ||
HairColor("WHI", "White"), | ||
HairColor("UNK", "Unknown")) | ||
|
||
|
||
def parse_hair_color(code: str) -> HairColor: | ||
code = "BRO" if code == "BRN" else code # Some cards use BRN for Brown | ||
try: | ||
return tuple(filter(lambda x: x.code == code, HAIR_COLORS))[0] | ||
except IndexError: | ||
raise ValueError(f"Color code '{code}' not found.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import pytest | ||
|
||
import aamva.hair_color as hair_color | ||
|
||
hair_color_testdata = ( | ||
# ((test, expects), ...) | ||
("BAL", ("BAL", "Bald")), | ||
("BLK", ("BLK", "Black")), | ||
("BLN", ("BLN", "Blond")), | ||
("BRO", ("BRO", "Brown")), | ||
("BRN", ("BRO", "Brown")), | ||
("GRY", ("GRY", "Gray")), | ||
("RED", ("RED", "Red/Auburn")), | ||
("SDY", ("SDY", "Sandy")), | ||
("WHI", ("WHI", "White")), | ||
("UNK", ("UNK", "Unknown"))) | ||
|
||
|
||
class TestParseHairColorFunction: | ||
@pytest.mark.parametrize("test, expects", hair_color_testdata, ids=tuple(map(lambda x: x[0], hair_color_testdata))) | ||
def test_should_successfully_return_hair_color_tuple(self, test, expects): | ||
assert hair_color.parse_hair_color(test) == expects | ||
assert type(hair_color.parse_hair_color(test)) == hair_color.HairColor | ||
|
||
def test_should_raise_value_error_when_code_not_found(self): | ||
with pytest.raises(ValueError, match='not found'): | ||
hair_color.parse_hair_color("AAA") |