示例#1
0
    def test_dumps_convert(self):
        f = Field(name="NAME")
        f.converter(dumps=int)

        self.assertIsNone(f.dumps_convert(None))

        value = f.dumps_convert("10")
        self.assertIsInstance(value, int)
        self.assertEqual(value, 10)

        value = f.dumps_convert(10)
        self.assertIsInstance(value, int)
        self.assertEqual(value, 10)

        self.assertRaises(ValueError, f.dumps_convert, "not a number")
示例#2
0
    def test_converter(self):
        f = Field(name="NAME")
        f.converter(loads=int, dumps=str)

        self.assertEqual(f.loads_converter, int)
        self.assertEqual(f.dumps_converter, str)