forked from indymedia/epicyon
Use dumps to save json
parent
96c56491eb
commit
ac2ab89aa6
4
tests.py
4
tests.py
|
@ -1635,7 +1635,7 @@ def testSaveLoadJson():
|
|||
print('testSaveLoadJson')
|
||||
testJson={
|
||||
"param1": 3,
|
||||
"param2": "test"
|
||||
"param2": '"Crème brûlée यह एक परीक्षण ह"'
|
||||
}
|
||||
testFilename='/tmp/.epicyonTestSaveLoadJson.json'
|
||||
if os.path.isfile(testFilename):
|
||||
|
@ -1647,7 +1647,7 @@ def testSaveLoadJson():
|
|||
assert testLoadJson.get('param1')
|
||||
assert testLoadJson.get('param2')
|
||||
assert testLoadJson['param1']==3
|
||||
assert testLoadJson['param2']=="test"
|
||||
assert testLoadJson['param2']=='"Crème brûlée यह एक परीक्षण ह"'
|
||||
os.remove(testFilename)
|
||||
|
||||
def runAllTests():
|
||||
|
|
3
utils.py
3
utils.py
|
@ -10,6 +10,7 @@ import os
|
|||
import time
|
||||
import shutil
|
||||
import datetime
|
||||
import json
|
||||
import commentjson
|
||||
|
||||
def saveJson(jsonObject: {},filename: str) -> bool:
|
||||
|
@ -19,7 +20,7 @@ def saveJson(jsonObject: {},filename: str) -> bool:
|
|||
while tries<5:
|
||||
try:
|
||||
with open(filename, 'w') as fp:
|
||||
commentjson.dump(jsonObject, fp, indent=2, sort_keys=False)
|
||||
fp.write(json.dumps(jsonObject))
|
||||
return True
|
||||
except:
|
||||
print('WARN: saveJson '+str(tries))
|
||||
|
|
Loading…
Reference in New Issue