Пример #1
0
 def test_dump(self):
     inputs = [{'foo': 42}, set([2, 3, 7])]
     output = StringIO()
     dump(inputs, output)
     self.assertEqual(
         '{"foo" 42}\n#{2 3 7}\n',
         output.getvalue())
Пример #2
0
 def test_unknown_handler(self):
     output = StringIO()
     dump([Custom(42)], output, default=repr)
     self.assertEqual('"<Custom(42)>"\n', output.getvalue())
Пример #3
0
 def test_custom_writer(self):
     point = namedtuple('point', 'x y')
     writer = lambda p: (p.x, p.y)
     output = StringIO()
     dump([point(2, 3)], output, [(point, Symbol('point'), writer)])
     self.assertEqual('#point (2 3)\n', output.getvalue())