-
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
490d3a9
commit 34e9fc5
Showing
2 changed files
with
47 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,23 @@ | ||
from typing import NamedTuple | ||
|
||
|
||
class RaceEthnicity(NamedTuple): | ||
code: str | ||
description: str | ||
|
||
|
||
RACE_ETHNICITIES = ( | ||
RaceEthnicity("AI", "Alaskan or American Indian"), | ||
RaceEthnicity("AP", "Asian or Pacific Islander"), | ||
RaceEthnicity("BK", "Black"), | ||
RaceEthnicity("H", "Hispanic Origin"), | ||
RaceEthnicity("O", "Non-hispanic"), | ||
RaceEthnicity("U", "Unknown"), | ||
RaceEthnicity("W", "White")) | ||
|
||
|
||
def parse_race_ethnicity(code: str) -> RaceEthnicity: | ||
try: | ||
return tuple(filter(lambda x: x.code == code, RACE_ETHNICITIES))[0] | ||
except IndexError: | ||
raise ValueError(f"Race/Ethnicity 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,24 @@ | ||
import pytest | ||
|
||
import aamva.race_ethnicity as race_ethnicity | ||
|
||
race_ehtnicity_testdata = ( | ||
# ((test, expects), ...) | ||
("AI", ("AI", "Alaskan or American Indian")), | ||
("AP", ("AP", "Asian or Pacific Islander")), | ||
("BK", ("BK", "Black")), | ||
("H", ("H", "Hispanic Origin")), | ||
("O", ("O", "Non-hispanic")), | ||
("U", ("U", "Unknown")), | ||
("W", ("W", "White"))) | ||
|
||
|
||
class TestParseRaceEthnicityFunction: | ||
@pytest.mark.parametrize("test, expects", race_ehtnicity_testdata, ids=tuple(map(lambda x: x[0], race_ehtnicity_testdata))) | ||
def test_should_successfully_return_race_ethnicity_tuple(self, test, expects): | ||
assert race_ethnicity.parse_race_ethnicity(test) == expects | ||
assert type(race_ethnicity.parse_race_ethnicity(test)) == race_ethnicity.RaceEthnicity | ||
|
||
def test_should_raise_value_error_when_code_not_found(self): | ||
with pytest.raises(ValueError, match='not found'): | ||
race_ethnicity.parse_race_ethnicity("AAA") |