pocketpy/tests/82_ldtk.py
Mahbub Alam 2950d88545
Add cjson module (#151)
* Add cjson module

* Create structure for cjson module

* Implemenet loads function

* Convert cJsonBool to python boolean

* Implement dumps function

* Convert json bool and null to python Bool and None

* necessary changes of project structure

* Update amalgamate.py

* Support non-dictionary json objects (list, tuple, string, number, bool, null)

* Fix tests

* fix CI

* fix CI

* Convert python to cJson and then to string

* Delete cJSON object after use

---------

Co-authored-by: Mahbub Alam <alam.mahbub214@gmail.com>
Co-authored-by: blueloveTH <blueloveth@foxmail.com>
2023-10-15 13:32:20 +08:00

25 lines
633 B
Python

try:
import cjson as json
print('[INFO] cjson is used')
except ImportError:
import json
_2489KB = 'WorldMap_GridVania_layout.ldtk'
_1093KB = 'WorldMap_Free_layout.ldtk'
_339KB = 'Typical_2D_platformer_example.ldtk'
with open(f'res/{_339KB}', 'r') as f:
json_content = f.read()
data: dict = json.loads(json_content)
assert isinstance(data, dict)
dumped: str = json.dumps(data)
loaded: dict = json.loads(dumped)
assert data == loaded
# import pickle
##### very very slow!! DO NOT RUN IT
# data_pickled: bytes = pickle.dumps(data)
# assert isinstance(data_pickled, bytes)
# assert pickle.loads(data_pickled) == data