Skip to content

Commit

Permalink
Add tests for ME and WI (#1848)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbowen-usds committed Sep 14, 2022
1 parent ecdd761 commit 922a3ba
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"Tract ID","STATE2KX","CNTY2KX","TRACT2KX","e(0)","se(e(0))","Abridged life table flag"
23001010100,23,001,010100,72.3,2.2928,3
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"Tract ID","STATE2KX","CNTY2KX","TRACT2KX","e(0)","se(e(0))","Abridged life table flag"
55001950201,55,001,950201,74.5,2.5471,3
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ GEOID10_TRACT,Life expectancy (years)
06069000802,99.1000000000
06061021322,99.1000000000
15009030201,99.1000000000
23001010100,72.3000000000
55001950201,74.5000000000
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ GEOID10_TRACT,STATE2KX,CNTY2KX,TRACT2KX,Life expectancy (years),se(e(0)),Abridge
06069000802,06,1,20100,99.1000000000,3.1415000000,3
06061021322,06,7,40300,99.1000000000,3.1415000000,3
15009030201,15,9,30201,99.1000000000,3.1415000000,3
23001010100,23,1,10100,72.3000000000,2.2928000000,3
55001950201,55,1,950201,74.5000000000,2.5471000000,3
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class TestCDCLifeExpectency(TestETL):
_SAMPLE_DATA_ZIP_FILE_NAME = None
_EXTRACT_TMP_FOLDER_NAME = "CDCLifeExpectanc"
_EXTRACT_CSV_FILE_NAME = "extract.csv"
_FIXTURES_SHARED_TRACT_IDS = TestETL._FIXTURES_SHARED_TRACT_IDS + [
"55001950201", # WI
"23001010100", # ME
]

def setup_method(self, _method, filename=__file__):
"""Invoke `setup_method` from Parent, but using the current file name.
Expand Down Expand Up @@ -55,31 +59,20 @@ def _setup_etl_instance_and_run_extract(
"data_pipeline.etl.score.etl_utils.get_state_fips_codes"
) as mock_get_state_fips_codes:
tmp_path = mock_paths[1]
if self._SAMPLE_DATA_ZIP_FILE_NAME is not None:
zip_file_fixture_src = (
self._DATA_DIRECTORY_FOR_TEST
/ self._SAMPLE_DATA_ZIP_FILE_NAME
)

# Create mock response.
with open(zip_file_fixture_src, mode="rb") as file:
file_contents = file.read()
else:

def fake_get(url, *args, **kwargs):
file_path = url.split("/")[-1]
with open(
self._DATA_DIRECTORY_FOR_TEST / self._SAMPLE_DATA_FILE_NAME,
self._DATA_DIRECTORY_FOR_TEST / file_path,
"rb",
) as file:
file_contents = file.read()

def fake_get(url, *args, **kwargs):
response_mock = requests.Response()
response_mock.status_code = 200
# pylint: disable=protected-access
# Return text fixture:
if url.endswith("US_A.CSV"):
response_mock._content = file_contents
else:
response_mock._content = b"Tract ID,STATE2KX,CNTY2KX,TRACT2KX,e(0),se(e(0)),Abridged life table flag"
response_mock._content = file_contents
return response_mock

requests_mock.get = fake_get
Expand Down

0 comments on commit 922a3ba

Please sign in to comment.