-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_encodeDecode.py
More file actions
30 lines (30 loc) · 849 Bytes
/
test_encodeDecode.py
File metadata and controls
30 lines (30 loc) · 849 Bytes
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
from classes import HASave
import json
import logging
try:
import deepdiff
except ImportError:
deepdiff = None
from pprint import pprint
logging.basicConfig(level=logging.INFO)
with open("save_data/the_inventory","rb") as ori:
save = HASave()
print("decoding save")
save.decode(bytearray(ori.read()))
o = save.values.copy()
print("writing json")
with open("the_inventory.json","w") as j:
json.dump(save.values,j)
print("encodeing json")
ba = save.encode(2,save.section_count,save.values)
print("re-writing save")
with open("the_inventory","wb") as copy:
copy.write(bytes(ba))
print(save.section_count)
print(save.values["default"])
print("re-decoding save")
save.decode(ba)
print(json.dumps(save.values,indent=4))
print(save.values == o)
if deepdiff:
print(json.dumps(deepdiff.DeepDiff(o,save.values),default=str,indent=4))