Example #1
0
 def test_transform_none(self):
     o = None
     schema = {
         'a': int,
         'b': float,
         'c': [perky.nullable(int)],
         'd': {
             'e': str,
             'g': perky.const
         }
     }
     with self.assertRaises(perky.PerkyFormatError):
         perky.transform(o, schema)
Example #2
0
 def test_transform_bad_obj(self):
     o2 = {'a': '44'}
     schema = [{
         'a': int,
         'b': float,
         'c': [perky.nullable(int)],
         'd': {
             'e': str,
             'g': perky.const
         }
     }]
     with self.assertRaises(perky.PerkyFormatError):
         perky.transform(o2, schema)
Example #3
0
 def test_transform_dict(self):
     o = {
         'a': '3',
         'b': '5.0',
         'c': ['1', '2', 'None', '3'],
         'd': {
             'e': 'f',
             'g': 'True'
         }
     }
     schema = {
         'a': int,
         'b': float,
         'c': [perky.nullable(int)],
         'd': {
             'e': str,
             'g': perky.const
         }
     }
     test_func = perky.transform(o, schema)
     expected_dict = {
         'a': 3,
         'b': 5.0,
         'c': [1, 2, None, 3],
         'd': {
             'e': 'f',
             'g': True
         }
     }
     self.assertEqual(expected_dict, test_func)
Example #4
0
 def test_transform_type_mismatch(self):
     o = {
         'a': '3',
         'b': '5.0',
         'c': ['1', '2', 'None', '3'],
         'd': {
             'e': 'f',
             'g': 'True'
         }
     }
     schema = [{
         'a': int,
         'b': float,
         'c': [perky.nullable(int)],
         'd': {
             'e': str,
             'g': perky.const
         }
     }]
     with self.assertRaises(perky.PerkyFormatError):
         perky.transform(o, schema)