def test_multiple_elements(self): stream = load(StringIO('#{1 2 3} "foo"\n43,32')) self.assertEqual(set([1, 2, 3]), next(stream)) self.assertEqual(u"foo", next(stream)) self.assertEqual(43, next(stream)) self.assertEqual(32, next(stream)) self.assertRaises(StopIteration, next, stream)
def time_edn(): list(load(buf))
def test_custom_default(self): marker = object() handler = lambda a, b: (marker, b) stream = StringIO('#foo [1 2] #bar "qux"') parsed = list(load(stream, default=handler)) self.assertEqual([(marker, (1, 2)), (marker, u"qux")], parsed)
def test_custom_tag(self): text = '#foo [1 2] #foo [3 4]' parsed = load(StringIO(text), {Symbol('foo'): reverse}) self.assertEqual([[2, 1], [4, 3]], list(parsed))
def test_single_element(self): stream = load(StringIO('#{1 2 3}')) self.assertEqual(set([1, 2, 3]), next(stream)) self.assertRaises(StopIteration, next, stream)
def time_edn(f): start = datetime.now() list(load(f)) end = datetime.now() return (end - start).total_seconds()