Пример #1
0
 def test_make_template(self):
     t_map = KeyTemplate(self.key_cols)
     stern_df = pd.read_csv(self.stern_map_path, delimiter='\t', header=0)
     t_map.update(stern_df)
     df1 = t_map.make_template()
     self.assertIsInstance(df1, pd.DataFrame,
                           "make_template should return a DataFrame")
     self.assertEqual(
         len(df1.columns), 1,
         "make_template should return 1 column single key, no additional columns"
     )
     t_map2 = KeyTemplate(['event_type', 'type'])
     t_map2.update(self.stern_map_path)
     df2 = t_map2.make_template()
     self.assertIsInstance(df2, pd.DataFrame,
                           "make_template should return a DataFrame")
     self.assertEqual(
         len(df2.columns), 2,
         "make_template should return 2 columns w 2 keys, no additional columns"
     )
     df3 = t_map2.make_template(['bananas', 'pears', 'apples'])
     self.assertIsInstance(df3, pd.DataFrame,
                           "make_template should return a DataFrame")
     self.assertEqual(
         len(df3.columns), 5,
         "make_template should return 5 columns w 2 keys, 3 additional columns"
     )
Пример #2
0
 def test_make_template_key_overlap(self):
     t_map = KeyTemplate(['event_type', 'type'])
     t_map.update(self.stern_map_path)
     try:
         t_map.make_template(['Bananas', 'type', 'Pears'])
     except HedFileError:
         pass
     except Exception as ex:
         self.fail(
             f'make_template threw the wrong exception {ex} when additional columns overlapped keys'
         )
     else:
         self.fail(
             'KeyTemplate should have thrown a HedFileError exception when key overlap but threw none'
         )