示例#1
0
 def test_has_keypath(self):
     keypaths = [
         Keypath('car.number_of_doors', 'new data.Door Count'),
         Keypath('car.number_of_windows', 'Windows Count'),
     ]
     extractor = KeypathExtractor(keypaths)
     self.assertTrue(extractor.has_keypath(data_object, keypaths[0].source_keypath))
     self.assertFalse(extractor.has_keypath(data_object, keypaths[1].source_keypath))
示例#2
0
 def test_keypath_separator(self):
     keypaths = [
         Keypath('car#number_of_doors', 'new data#Door Count'),
         Keypath('car#fuel_type#0', 'new data#Primary Fuel'),
     ]
     extractor = KeypathExtractor(keypaths, separator='#')
     values = extractor.extract(data_object)
     self.assertTrue('new data' in values)
     self.assertEqual(values['new data']['Door Count'], 4)
     self.assertEqual(values['new data']['Primary Fuel'], 'petrol')
示例#3
0
 def test_keypaths(self):
     keypaths = [
         Keypath('car.number_of_doors', 'new data.Door Count'),
         Keypath('car.fuel_type.0', 'new data.Primary Fuel'),
         Keypath('car.no_value', 'new data.No Value'),
     ]
     extractor = KeypathExtractor(keypaths)
     values = extractor.extract(data_object)
     self.assertTrue('new data' in values)
     self.assertEqual(values['new data']['Door Count'], 4)
     self.assertEqual(values['new data']['Primary Fuel'], 'petrol')
     self.assertEqual(values['new data']['No Value'], None)
示例#4
0
    def test_reuse_value_object(self):
        keypaths1 = [
            Keypath('car.number_of_doors', 'new data.Door Count'),
        ]
        extractor = KeypathExtractor(keypaths1)
        values = extractor.extract(data_object)
        self.assertEqual(values['new data']['Door Count'], 4)

        keypaths2 = [
            Keypath('car.fuel_type.0', 'new data.Primary Fuel'),
        ]
        extractor = KeypathExtractor(keypaths2)
        values = extractor.extract(data_object, values)
        self.assertEqual(values['new data']['Door Count'], 4)
        self.assertEqual(values['new data']['Primary Fuel'], 'petrol')
示例#5
0
 def test_transformer_method(self):
     keypaths = [
         Keypath('car.engine_size', 'new data.Capacity', transformer_fn=self.triple),
     ]
     extractor = KeypathExtractor(keypaths)
     values = extractor.extract(data_object)
     self.assertEqual(values['new data']['Capacity'], 6.0)
示例#6
0
 def test_transformer_function(self):
     keypaths = [
         Keypath('car.number_of_doors', 'new data.Door Count', transformer_fn=double),
     ]
     extractor = KeypathExtractor(keypaths)
     values = extractor.extract(data_object)
     self.assertEqual(values['new data']['Door Count'], 8)
示例#7
0
 def test_optional_keypath(self):
     keypaths = [
         Keypath('car.number_of_windows', 'Windows Count', is_optional=True),
     ]
     extractor = KeypathExtractor(keypaths)
     extractor.extract(data_object)
示例#8
0
 def test_invalid_source_keypath(self):
     keypaths = [
         Keypath('car.number_of_windows', 'Windows Count'),
     ]
     extractor = KeypathExtractor(keypaths)
     self.assertRaises(KeyError, extractor.extract, data_object)