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