示例#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)
示例#2
0
 def transform_line(self, *pos, **kwargs):
     return FileTransform.transform_line(self, *pos, **kwargs)
示例#3
0
 def test_invalid_option(self):
     with self.assertRaises(TypeError):
         FileTransform(['a', 'b'], require=['a'], blargh=1)
示例#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)
示例#5
0
 def test_combine_error_name_conflict(self):
     h = ['a', 'b', 'c']
     with self.assertRaises(KeyError):
         FileTransform(h, combine={'b': '{a}{b}{c}'})
示例#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)
示例#7
0
 def test_rename_error(self):
     h = ['a', 'b', 'c']
     with self.assertRaises(KeyError):
         FileTransform(header=h, rename={'k': ['t']})
示例#8
0
 def test_require_error(self):
     h = ['a', 'b', 'c']
     with self.assertRaises(KeyError):
         FileTransform(header=h, require=['k'])
示例#9
0
 def test_membership_bad_object(self):
     with self.assertRaises(TypeError):
         FileTransform(['a'], in_={'a': 1})
示例#10
0
 def test_membership_of_missing_column_error(self):
     with self.assertRaises(KeyError):
         FileTransform(['a'], in_={'x': []})
示例#11
0
 def test_drop_and_require_error(self):
     with self.assertRaises(AssertionError):
         FileTransform(['a'], require=['a'], drop=['a'])
示例#12
0
 def test_validate_missing_column(self):
     with self.assertRaises(KeyError):
         FileTransform(['a', 'b'], validate={'c': ''})
示例#13
0
 def test_duplicate_input_column(self):
     with self.assertRaises(KeyError):
         FileTransform(['a', 'a'])
示例#14
0
 def test_combine_keyerror(self):
     h = ['a', 'b', 'c']
     with self.assertRaises(KeyError):
         FileTransform(h, combine={'k': '{m}{b}{c}'})
示例#15
0
 def test_cast_noncallable_error(self):
     FileTransform(['a'], cast={'a': int})
     with self.assertRaises(TypeError):
         FileTransform(['a'], cast={'a': 1})
示例#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)
示例#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+)'})
示例#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)
示例#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+)'})
示例#20
0
 def test_cast_error(self):
     h = ['b', 'c']
     with self.assertRaises(KeyError):
         FileTransform(h, cast={'a': int})
示例#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)
示例#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)
示例#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'])