-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathconftest.py
More file actions
73 lines (62 loc) · 2.43 KB
/
conftest.py
File metadata and controls
73 lines (62 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-
# :Project: python-rapidjson -- Tests configuration
# :Author: Lele Gaifax <lele@metapensiero.it>
# :License: MIT License
# :Copyright: © 2016, 2017, 2018 Lele Gaifax
#
import io
import rapidjson as rj
def binary_streaming_dumps(o, **opts):
stream = io.BytesIO()
rj.dump(o, stream, **opts)
return stream.getvalue().decode('utf-8')
def text_streaming_dumps(o, **opts):
stream = io.StringIO()
rj.dump(o, stream, **opts)
return stream.getvalue()
def binary_streaming_encoder(o, **opts):
stream = io.BytesIO()
rj.Encoder(**opts)(o, stream=stream)
return stream.getvalue().decode('utf-8')
def text_streaming_encoder(o, **opts):
stream = io.StringIO()
rj.Encoder(**opts)(o, stream=stream)
return stream.getvalue()
def pytest_generate_tests(metafunc):
if 'dumps' in metafunc.fixturenames and 'loads' in metafunc.fixturenames:
metafunc.parametrize('dumps,loads', (
((rj.dumps, rj.loads),
(lambda o,**opts: rj.Encoder(**opts)(o),
lambda j,**opts: rj.Decoder(**opts)(j)))
), ids=('func[string]',
'class[string]'))
elif 'dumps' in metafunc.fixturenames:
metafunc.parametrize('dumps', (
rj.dumps,
binary_streaming_dumps,
text_streaming_dumps,
lambda o,**opts: rj.Encoder(**opts)(o),
binary_streaming_encoder,
text_streaming_encoder,
), ids=('func[string]',
'func[bytestream]',
'func[textstream]',
'class[string]',
'class[binarystream]',
'class[textstream]'))
elif 'loads' in metafunc.fixturenames:
metafunc.parametrize('loads', (
rj.loads,
lambda j,**opts: rj.load(io.BytesIO(j.encode('utf-8')
if isinstance(j, str) else j), **opts),
lambda j,**opts: rj.load(io.StringIO(j), **opts),
lambda j,**opts: rj.Decoder(**opts)(j),
lambda j,**opts: rj.Decoder(**opts)(io.BytesIO(j.encode('utf-8')
if isinstance(j, str) else j)),
lambda j,**opts: rj.Decoder(**opts)(io.StringIO(j)),
), ids=('func[string]',
'func[bytestream]',
'func[textstream]',
'class[string]',
'class[bytestream]',
'class[textstream]'))