Skip to content

Commit

Permalink
added clean data filter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Martí Bosch committed Feb 15, 2018
1 parent 9a53271 commit bfeae89
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/test_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ def mock_person(serialno, age, sex, income):
mock_person('c', '25', '1', '0000000')
]

def _mock_dirty_household_puma_state_input(self):
return [
{'serialno': 'a', 'puma': '00106', 'st': '06'},
{'serialno': 'b', 'puma': '00107', 'st': '06'},
{'serialno': 'c', 'puma': '00106', 'st': '07'}
]

def test_clean_data(self):
pums_data = datasource.PumsData(
pandas.DataFrame(self._mock_dirty_household_input())
Expand Down Expand Up @@ -65,3 +72,17 @@ def test_clean_data_one_field(self):
inputs.NUM_PEOPLE.name: '2',
}
self.assertDictEqual(actual, expected)

def test_clean_data_filter_length(self):
pums_data = datasource.PumsData(
pandas.DataFrame(self._mock_dirty_household_puma_state_input())
)
field_names = [inputs.SERIAL_NUMBER.name, inputs.STATE.name, inputs.PUMA.name]
cleaned = pums_data.clean(field_names, Preprocessor())
cleaned_state = pums_data.clean(field_names, Preprocessor(), state='06')
cleaned_puma = pums_data.clean(field_names, Preprocessor(), puma='00106')
cleaned_both = pums_data.clean(field_names, Preprocessor(), state='06', puma='00106')
self.assertEqual(len(cleaned.data), 3)
self.assertEqual(len(cleaned_state.data), 2)
self.assertEqual(len(cleaned_puma.data), 2)
self.assertEqual(len(cleaned_both.data), 1)

0 comments on commit bfeae89

Please sign in to comment.