mirror of
https://github.com/ansible/awx.git
synced 2024-11-01 16:51:11 +03:00
Regress trailing comma modification and enhance error message
This commit is contained in:
parent
422950f45d
commit
96d491fdce
@ -62,9 +62,4 @@ class JSONParser(parsers.JSONParser):
|
||||
raise ParseError(_('JSON parse error - not a JSON object'))
|
||||
return obj
|
||||
except ValueError as exc:
|
||||
try:
|
||||
# PyYAML can also parse JSON-style input string, and support more flexible
|
||||
# input grammar like trailing commas.
|
||||
return yaml.load(data, OrderedDictLoader)
|
||||
except Exception:
|
||||
raise ParseError(_('JSON parse error - %s') % six.text_type(exc))
|
||||
raise ParseError(_('JSON parse error - %s\nPossible cause: trailing comma.' % six.text_type(exc)))
|
||||
|
@ -1,31 +0,0 @@
|
||||
import pytest
|
||||
|
||||
import StringIO
|
||||
from collections import OrderedDict
|
||||
|
||||
from awx.api.parsers import JSONParser
|
||||
|
||||
|
||||
@pytest.mark.parametrize('input_, output', [
|
||||
('{"foo": "bar", "alice": "bob"}', OrderedDict([("foo", "bar"), ("alice", "bob")])),
|
||||
('{"foo": "bar", "alice": "bob",\n }', OrderedDict([("foo", "bar"), ("alice", "bob")])),
|
||||
('{"foo": ["alice", "bob"]}', {"foo": ["alice","bob"]}),
|
||||
('{"foo": ["alice", "bob",\n ]}', {"foo": ["alice","bob"]}),
|
||||
('{"foo": "\\"bar, \\n}"}', {"foo": "\"bar, \n}"}),
|
||||
('{"foo": ["\\"alice,\\n ]", "bob"]}', {"foo": ["\"alice,\n ]","bob"]}),
|
||||
])
|
||||
def test_trailing_comma_support(input_, output):
|
||||
input_buffer = StringIO.StringIO()
|
||||
input_buffer.write(input_)
|
||||
input_buffer.seek(0)
|
||||
assert JSONParser().parse(input_buffer) == output
|
||||
input_buffer.close()
|
||||
|
||||
|
||||
def test_yaml_load_preserves_input_order():
|
||||
input_ = '{"a": "b", "c": "d", "e": "f"}'
|
||||
output = ('a', 'c', 'e')
|
||||
input_buffer = StringIO.StringIO()
|
||||
input_buffer.write(input_)
|
||||
input_buffer.seek(0)
|
||||
assert tuple(JSONParser().parse(input_buffer)) == output
|
Loading…
Reference in New Issue
Block a user