Example #1
0
 def test_altered_default(self):
     """FieldMorpher with default set should apply it"""
     func = lambda x, y: (str(x), float(y) - 0.5)
     fm = FieldMorpher({"3": str, 4: int}, func)
     # check that recognized values aren't tampered with
     self.assertEqual(fm({3: 3, 4: "4"}), {"3": "3", 4: 4})
     # check that unrecognized values get the appropriate conversion
     self.assertEqual(fm({3: 3, 5: "5"}), {"3": "3", "5": 4.5})
Example #2
0
 def test_default_error(self):
     """FieldMorpher default should raise FieldError on unknown fields"""
     fm = FieldMorpher({"a": int, "b": str})
     self.assertRaises(FieldError, fm, {"a": "3", "b": 456, "c": "4"})
Example #3
0
 def test_default(self):
     """FieldMorpher default should use correct constructors"""
     fm = FieldMorpher({"a": int, "b": str})
     self.assertEqual(fm({"a": "3", "b": 456}), {"a": 3, "b": "456"})