Skip to content

Commit

Permalink
Cleanup source tests (#1912)
Browse files Browse the repository at this point in the history
* Move test to base for broader coverage (#1848)

* Remove duplicate line (#1848)

* FUDS needed an extra mock (#1848)
  • Loading branch information
mattbowen-usds authored Sep 23, 2022
1 parent f70f30d commit d8dd4cf
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
3 changes: 0 additions & 3 deletions data/data-pipeline/data_pipeline/etl/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ def yaml_config_load(cls) -> dict:
for field in dataset_config["load_fields"]:
cls.COLUMNS_TO_KEEP.append(field["long_name"])
setattr(cls, field["df_field_name"], field["long_name"])

# set the constants for the class
setattr(cls, field["df_field_name"], field["long_name"])
return dataset_config

# This is a classmethod so it can be used by `get_data_frame` without
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,3 @@ def test_get_output_file_path(self, mock_etl, mock_paths):
data_path / "dataset" / "doe_energy_burden" / "usa.csv"
)
assert output_file_path == expected_output_file_path

def test_tract_id_lengths(self, mock_etl, mock_paths):
etl = self._setup_etl_instance_and_run_extract(
mock_etl=mock_etl, mock_paths=mock_paths
)
etl.transform()
etl.validate()
etl.load()
df = etl.get_data_frame()
assert (df[etl.GEOID_TRACT_FIELD_NAME].str.len() == 11).all()
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,10 @@ def test_tracts_without_fuds_not_in_results(self, mock_etl, mock_paths):
assert len(df[etl.GEOID_TRACT_FIELD_NAME]) == len(
self._FIXTURES_SHARED_TRACT_IDS
)

def test_tract_id_lengths(self, mock_etl, mock_paths):
with mock.patch(
"data_pipeline.etl.sources.eamlis.etl.add_tracts_for_geometries",
new=_fake_add_tracts_for_geometries,
):
super().test_tract_id_lengths(mock_etl, mock_paths)
10 changes: 10 additions & 0 deletions data/data-pipeline/data_pipeline/tests/sources/example/test_etl.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ def test_get_output_file_path_base(self, mock_etl, mock_paths):

assert actual_file_path == expected_file_path

def test_tract_id_lengths(self, mock_etl, mock_paths):
etl = self._setup_etl_instance_and_run_extract(
mock_etl=mock_etl, mock_paths=mock_paths
)
etl.transform()
etl.validate()
etl.load()
df = etl.get_data_frame()
assert (df[etl.GEOID_TRACT_FIELD_NAME].str.len() == 11).all()

def test_fixtures_contain_shared_tract_ids_base(self, mock_etl, mock_paths):
"""Check presence of necessary shared tract IDs.
Note: We used shared census tract IDs so that later our tests can join all the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,10 @@ def test_tracts_without_fuds_not_in_results(self, mock_etl, mock_paths):
assert len(df[etl.GEOID_TRACT_FIELD_NAME]) == len(
self._FIXTURES_SHARED_TRACT_IDS
)

def test_tract_id_lengths(self, mock_etl, mock_paths):
with mock.patch(
"data_pipeline.etl.sources.us_army_fuds.etl.add_tracts_for_geometries",
new=_fake_add_tracts_for_geometries,
):
return super().test_tract_id_lengths(mock_etl, mock_paths)

0 comments on commit d8dd4cf

Please sign in to comment.