-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathtest_utils.py
More file actions
56 lines (44 loc) · 1.6 KB
/
test_utils.py
File metadata and controls
56 lines (44 loc) · 1.6 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
import importlib
import json
import renderapi
import pytest
import numpy as np
import ujson
def cross_py23_reload(module):
try:
reload(module)
except NameError:
importlib.reload(module)
@pytest.mark.parametrize("use_ujson", [True, False])
def test_json_load(use_ujson):
if not use_ujson:
try:
import builtins
except ImportError:
import __builtin__ as builtins
realimport = builtins.__import__
def noujson_import(name, globals=None, locals=None,
fromlist=(), level=0):
if 'ujson' in name:
raise ImportError
return realimport(name, globals, locals, fromlist, level)
builtins.__import__ = noujson_import
cross_py23_reload(renderapi.utils)
assert (renderapi.utils.requests_json is ujson
if use_ujson else renderapi.utils.requests_json is json)
assert (
renderapi.utils.requests.models.complexjson is ujson
if use_ujson else renderapi.utils.requests.models.complexjson is json)
def test_jbool():
assert(renderapi.utils.jbool(True) == 'true')
assert(renderapi.utils.jbool(False) == 'false')
assert(renderapi.utils.jbool(0) == 'false')
assert(renderapi.utils.jbool(1) == 'true')
def test_renderdumps_simple():
s = renderapi.utils.renderdumps({'a': 1})
assert(s == '{"a": 1}')
s = renderapi.utils.renderdumps(5)
assert(s == '5')
def test_renderdumps_fails():
with pytest.raises(AttributeError):
renderapi.utils.renderdumps(np.zeros(3))