Example #1
0
 def test_simplify(self):
     h = ['a', 'b', 'c']
     ft = FileTransform(header=h)
     self.assertEqual(h, ft.input)
     self.assertEqual(h, ft.header)
     ft = FileTransform(h, simplify=True)
     self.assertEqual(h, ft.input)
     self.assertEqual([], ft.header)
Example #2
0
 def transform_line(self, *pos, **kwargs):
     return FileTransform.transform_line(self, *pos, **kwargs)
Example #3
0
 def test_invalid_option(self):
     with self.assertRaises(TypeError):
         FileTransform(['a', 'b'], require=['a'], blargh=1)
Example #4
0
    def test_require(self):
        ft = FileTransform(['a', 'b'], require=['a'])
        self.assertEqual(['a', 'b'], ft.header)

        ft = FileTransform(['a', 'b'], require=['a'], simplify=True)
        self.assertEqual(['a'], ft.header)
Example #5
0
 def test_combine_error_name_conflict(self):
     h = ['a', 'b', 'c']
     with self.assertRaises(KeyError):
         FileTransform(h, combine={'b': '{a}{b}{c}'})
Example #6
0
 def test_add(self):
     h = ['a', 'b', 'c']
     ft = FileTransform(h, add_default={'k': 1})
     self.assertEqual(h, ft.input)
     self.assertEqual(['a', 'b', 'c', 'k'], ft.header)
Example #7
0
 def test_rename_error(self):
     h = ['a', 'b', 'c']
     with self.assertRaises(KeyError):
         FileTransform(header=h, rename={'k': ['t']})
Example #8
0
 def test_require_error(self):
     h = ['a', 'b', 'c']
     with self.assertRaises(KeyError):
         FileTransform(header=h, require=['k'])
Example #9
0
 def test_membership_bad_object(self):
     with self.assertRaises(TypeError):
         FileTransform(['a'], in_={'a': 1})
Example #10
0
 def test_membership_of_missing_column_error(self):
     with self.assertRaises(KeyError):
         FileTransform(['a'], in_={'x': []})
Example #11
0
 def test_drop_and_require_error(self):
     with self.assertRaises(AssertionError):
         FileTransform(['a'], require=['a'], drop=['a'])
Example #12
0
 def test_validate_missing_column(self):
     with self.assertRaises(KeyError):
         FileTransform(['a', 'b'], validate={'c': ''})
Example #13
0
 def test_duplicate_input_column(self):
     with self.assertRaises(KeyError):
         FileTransform(['a', 'a'])
Example #14
0
 def test_combine_keyerror(self):
     h = ['a', 'b', 'c']
     with self.assertRaises(KeyError):
         FileTransform(h, combine={'k': '{m}{b}{c}'})
Example #15
0
 def test_cast_noncallable_error(self):
     FileTransform(['a'], cast={'a': int})
     with self.assertRaises(TypeError):
         FileTransform(['a'], cast={'a': 1})
Example #16
0
 def test_require_simplify(self):
     h = ['a', 'b', 'c']
     ft = FileTransform(header=h, require=['a'], simplify=True)
     self.assertEqual(h, ft.input)
     self.assertEqual(['a'], ft.header)
Example #17
0
 def test_split_missing_column_error(self):
     FileTransform(['a'], split={'a': r'^(?P<thing>\w+)'})
     with self.assertRaises(KeyError):
         FileTransform(['a'], split={'x': r'^(?P<thing>\w+)'})
Example #18
0
 def test_rename(self):
     h = ['a', 'b', 'c']
     ft = FileTransform(h, rename={'a': ['k', 'm']})
     self.assertEqual(h, ft.input)
     self.assertEqual(['a', 'b', 'c', 'k', 'm'], ft.header)
Example #19
0
 def test_split_duplicate_column_error(self):
     FileTransform(['a', 'b'], split={'a': r'^(?P<thing>\w+)'})
     with self.assertRaises(KeyError):
         FileTransform(['a', 'b'],
                       require=['b'],
                       split={'a': r'^(?P<b>\w+)'})
Example #20
0
 def test_cast_error(self):
     h = ['b', 'c']
     with self.assertRaises(KeyError):
         FileTransform(h, cast={'a': int})
Example #21
0
 def test_add_default(self):
     ft = FileTransform(['a', 'b'], add_default={'c': 1})
     self.assertEqual(['a', 'b', 'c'], ft.header)
     ft = FileTransform(['a', 'b'], add_default={'b': 1})
     self.assertEqual(['a', 'b'], ft.header)
Example #22
0
 def test_require__in(self):
     h = ['a', 'b', 'c']
     ft = FileTransform(h, require=['c'], in_={'a': []}, simplify=True)
     self.assertEqual(h, ft.input)
     self.assertEqual(['a', 'c'], ft.header)
Example #23
0
 def test_combine(self):
     h = ['a', 'b', 'c']
     ft = FileTransform(h, combine={'k': '{a}{b}{c}'})
     self.assertEqual(ft.input, h)
     self.assertEqual(ft.header, h + ['k'])