comparison tests/test_fastpickle.py @ 989:8adc27285d93

bake: Big pass on bake performance. - Reduce the amount of data passed between processes. - Make inter-process data simple objects to make it easier to test with alternatives to pickle. - Make sources have the basic requirement to be able to find a content item from an item spec (path). - Make Hoedown the default Markdown formatter.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 19 Nov 2017 14:29:17 -0800
parents fcfbe103cfd1
children
comparison
equal deleted inserted replaced
988:f83ae0a5d793 989:8adc27285d93
1 import io
1 import datetime 2 import datetime
2 import pytest 3 import pytest
3 from piecrust.fastpickle import pickle, unpickle, pickle_obj, unpickle_obj 4 from piecrust.fastpickle import pickle, unpickle, pickle_intob, unpickle_fromb
4 5
5 6
6 class Foo(object): 7 class Foo(object):
7 def __init__(self, name): 8 def __init__(self, name):
8 self.name = name 9 self.name = name
34 def test_pickle_unpickle(obj, expected): 35 def test_pickle_unpickle(obj, expected):
35 data = pickle(obj) 36 data = pickle(obj)
36 actual = unpickle(data) 37 actual = unpickle(data)
37 assert actual == expected 38 assert actual == expected
38 39
40 with io.BytesIO() as buf:
41 pickle_intob(obj, buf)
42 size = buf.tell()
43 buf.seek(0)
44 actual = unpickle_fromb(buf, size)
45 assert actual == expected
46
39 47
40 def test_objects(): 48 def test_objects():
41 f = Foo('foo') 49 f = Foo('foo')
42 f.bars.append(Bar(1)) 50 f.bars.append(Bar(1))
43 f.bars.append(Bar(2)) 51 f.bars.append(Bar(2))
52 assert f.bars[i].value == o.bars[i].value 60 assert f.bars[i].value == o.bars[i].value
53 61
54 62
55 def test_reentrance(): 63 def test_reentrance():
56 a = {'test_ints': 42, 'test_set': set([1, 2])} 64 a = {'test_ints': 42, 'test_set': set([1, 2])}
57 data = pickle_obj(a) 65 data = pickle(a)
58 b = unpickle_obj(data) 66 b = unpickle(data)
59 assert a == b 67 assert a == b
60 other_b = unpickle_obj(data) 68 other_b = unpickle(data)
61 assert a == other_b 69 assert a == other_b
62 c = unpickle_obj(data) 70 c = unpickle(data)
63 assert a == c 71 assert a == c
64