Add unit test for --no-ensure-ascii option

This commit is contained in:
ushuz 2017-03-16 14:54:55 +08:00 committed by John Hu
parent 543c5c7e1a
commit 10f8bd2f22
2 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,10 @@
{
"alist": [
2,
34,
234
],
"blah": null,
"foo": "bar",
"non_ascii": "中文にほんご한국어"
}

View File

@ -20,6 +20,7 @@ def test_parse_indent():
@pytest.mark.parametrize(('filename', 'expected_retval'), (
('not_pretty_formatted_json.json', 1),
('unsorted_pretty_formatted_json.json', 1),
('non_ascii_pretty_formatted_json.json', 1),
('pretty_formatted_json.json', 0),
))
def test_pretty_format_json(filename, expected_retval):
@ -30,6 +31,7 @@ def test_pretty_format_json(filename, expected_retval):
@pytest.mark.parametrize(('filename', 'expected_retval'), (
('not_pretty_formatted_json.json', 1),
('unsorted_pretty_formatted_json.json', 0),
('non_ascii_pretty_formatted_json.json', 1),
('pretty_formatted_json.json', 0),
))
def test_unsorted_pretty_format_json(filename, expected_retval):
@ -40,6 +42,7 @@ def test_unsorted_pretty_format_json(filename, expected_retval):
@pytest.mark.parametrize(('filename', 'expected_retval'), (
('not_pretty_formatted_json.json', 1),
('unsorted_pretty_formatted_json.json', 1),
('non_ascii_pretty_formatted_json.json', 1),
('pretty_formatted_json.json', 1),
('tab_pretty_formatted_json.json', 0),
))
@ -48,6 +51,11 @@ def test_tab_pretty_format_json(filename, expected_retval):
assert ret == expected_retval
def test_non_ascii_pretty_format_json():
ret = pretty_format_json(['--no-ensure-ascii', get_resource_path('non_ascii_pretty_formatted_json.json')])
assert ret == 0
def test_autofix_pretty_format_json(tmpdir):
srcfile = tmpdir.join('to_be_json_formatted.json')
shutil.copyfile(