Commit ffa050aa authored by Michal Čihař's avatar Michal Čihař

Merge pull request #898 from quinox/json_newline

End JSON files with a newline
parents 0cb4a07f d82da8b8
......@@ -37,7 +37,7 @@ class JsonFile(JsonFileTT):
# simple JSON files.
for unit in self.units:
data[unit.getid().lstrip('.')] = unit.source
return json.dumps(
return (json.dumps(
data, sort_keys=True, separators=(',', ': '),
indent=4, ensure_ascii=False
).encode('utf-8')
) + '\n').encode('utf-8')
......@@ -213,3 +213,29 @@ if 'resx' in FILE_FORMATS:
FIND = u'Hello'
FIND_MATCH = u''
MATCH = '<root></root>'
class OutputTest(TestCase):
def test_json_default_output(self):
json_input = '{"string_xyz":"Foo Bar","string_abc": "Checkbox? ☑!"}'
# Expected result:
# - Keys sorted alphabetically
# - No trailing spaces
# - Newline at the end of the file
# - Embedded Unicode chars (not replaced by \uxxx versions)
# - UTF-8 file
json_expected_output = u'''{
"string_abc": "Checkbox? ☑!",
"string_xyz": "Foo Bar"
}
'''
out = tempfile.NamedTemporaryFile()
out.write(json_input)
out.flush()
JSONFormat(out.name).save()
with open(out.name) as handle:
self.assertEqual(
handle.read().decode('UTF-8'),
json_expected_output
)
out.close()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment