def test_map_should_clean_opcs_code(self): self.assertEqual('U212 Y973', mapped_value('U212,Y973,X1', clean_opcs_mapping)) self.assertEqual('', mapped_value('98', clean_opcs_mapping)) self.assertEqual('', mapped_value('TooLong', clean_opcs_mapping)) self.assertIsNone('', mapped_value('', clean_opcs_mapping)) self.assertEqual('ABCD', mapped_value('AbcD', clean_opcs_mapping)) self.assertEqual('1234', mapped_value('1234', clean_opcs_mapping))
def test_line_mapping_should_create_valid_hash_with_blank_cleaned_value( self): self.assertEqual('', mapped_value('98', clean_opcs_mapping)) line_hash = mapped_line(['98'], simple_mapping_with_clean_opcs) self.assertIsNone(line_hash['primaryprocedures']) self.assertEqual('98', line_hash['rawtext']['primaryprocedures'])
def test_should_return_correct_date_format_for_date_fields_with_daysafter( self): self.assertEqual(datetime(2012, 5, 18), mapped_value(2, daysafter_mapping)) self.assertEqual(datetime(2012, 5, 18), mapped_value('2', daysafter_mapping)) self.assertEqual(datetime(2012, 5, 14), mapped_value(-2, daysafter_mapping)) self.assertEqual(datetime(2012, 5, 14), mapped_value('-2', daysafter_mapping)) self.assertEqual(datetime(2012, 5, 16), mapped_value(0, daysafter_mapping)) self.assertEqual('String', mapped_value('String', daysafter_mapping)) self.assertEqual('', mapped_value('', daysafter_mapping)) self.assertIsNone(mapped_value(None, daysafter_mapping)) self.assertEqual(datetime(2057, 8, 23), mapped_value(16535, daysafter_mapping)) # Answer independently checked http://www.wolframalpha.com/input/?i=2012-05-16+%2B+9379+days self.assertEqual(datetime(2038, 1, 19), mapped_value(9379, daysafter_mapping)) self.assertEqual(datetime(1946, 5, 11), mapped_value(16900, {'daysafter': '1900-02-01'})) self.assertEqual(datetime(2014, 4, 8), mapped_value(16900, {'daysafter': '1967-12-31'})) self.assertEqual(datetime(2046, 4, 9), mapped_value(16900, {'daysafter': '2000-01-01'}))
def test_map_should_use_multiple_cleans(self): self.assertEqual( 'U3 Y2 X1', mapped_value('u3,y2,x1', clean_code_and_upcase_mapping))
def test_map_should_clean_icd_code(self): self.assertEqual('C343 R932 Z515', mapped_value('C34.3,R93.2,Z51.5', clean_icd_mapping))
def test_map_should_clean_name(self): self.assertEqual('ANNABELLE SMITH', mapped_value('anna.belle,smith', clean_name_mapping))
def test_map_should_clean_ethnic_category(self): self.assertEqual('M', mapped_value('1', clean_ethniccategory_mapping)) self.assertEqual('X', mapped_value('99', clean_ethniccategory_mapping)) self.assertEqual('A', mapped_value('A', clean_ethniccategory_mapping)) self.assertEqual('INVALID', mapped_value('InVaLiD', clean_ethniccategory_mapping))
def test_map_should_return_no_date_format(self): self.assertIsNone(mapped_value('03/25/2011', format_mapping))
def test_map_should_return_incorrect_date_format(self): self.assertNotEqual(datetime(2011, 3, 4), mapped_value('03/04/2011', format_mapping))
def test_map_should_return_correct_date_format(self): self.assertEqual(datetime(2011, 1, 25), mapped_value('25/01/2011', format_mapping)) self.assertEqual(datetime(2011, 1, 25), mapped_value('20110125', format_mapping_yyyymmdd))
def test_map_should_return_unmapped(self): self.assertEqual('B', mapped_value('B', map_mapping))
def test_map_should_return_a_number(self): self.assertEqual('1', mapped_value('A', map_mapping))