This repository was archived by the owner on Jun 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathtest_json.py
More file actions
44 lines (40 loc) · 1.67 KB
/
test_json.py
File metadata and controls
44 lines (40 loc) · 1.67 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
from datetime import datetime
from dateutil.tz import tzutc
from tests import PyResTests
import pyres.json_parser as json
class JSONTests(PyResTests):
def test(self):
naive_now = datetime.now()
aware_now = datetime.now(tzutc())
for now in [naive_now, aware_now]:
for obj in [now, now.date(), now.timetz(), now.time()]:
encoded = json.dumps(obj)
decoded = json.loads(encoded)
assert obj == decoded
def test_in_list(self):
naive_now = datetime.now()
aware_now = datetime.now(tzutc())
for now in [naive_now, aware_now]:
for obj in [now, now.date(), now.timetz(), now.time()]:
to_encode = [1, obj]
encoded = json.dumps(to_encode)
decoded = json.loads(encoded)
assert to_encode == decoded
def test_in_dict(self):
naive_now = datetime.now()
aware_now = datetime.now(tzutc())
for now in [naive_now, aware_now]:
for obj in [now, now.date(), now.timetz(), now.time()]:
to_encode = dict(a=1, b=obj)
encoded = json.dumps(to_encode)
decoded = json.loads(encoded)
assert to_encode == decoded
def test_complex(self):
naive_now = datetime.now()
aware_now = datetime.now(tzutc())
for now in [naive_now, aware_now]:
for obj in [now, now.date(), now.timetz(), now.time()]:
to_encode = dict(a=1, b=obj, c=dict(c1=2, c2=obj), d=[3, obj])
encoded = json.dumps(to_encode)
decoded = json.loads(encoded)
assert to_encode == decoded