def test_error_presentation(self): document = dedent(""" # An example with several Bobs. # One with hobbies. { "type_alias": "pants_test.engine.test_parsers.Bob", # And internal comment and blank lines. "hobbies": [1, 2, 3]} { # This comment is inside an empty object that started on the prior line! } # Another that is imaginary aged. { "type_alias": "pants_test.engine.test_parsers.Bob", "age": 42i, "four": 1, "five": 1, "six": 1, "seven": 1, "eight": 1, "nine": 1 } """).strip() filepath = '/dev/null' with self.assertRaises(parser.ParseError) as exc: parsers.JsonParser(EmptyTable()).parse(filepath, document) # Strip trailing whitespace from the message since our expected literal below will have # trailing ws stripped via editors and code reviews calling for it. actual_lines = [line.rstrip() for line in str(exc.exception).splitlines()] # This message from the json stdlib varies between python releases, so fuzz the match a bit. self.assertRegexpMatches(actual_lines[0], r'Expecting (?:,|\',\'|",") delimiter: line 3 column 12 \(char 67\)') self.assertEqual(dedent(""" In document at {filepath}: # An example with several Bobs. # One with hobbies. {{ "type_alias": "pants_test.engine.test_parsers.Bob", # And internal comment and blank lines. "hobbies": [1, 2, 3]}} {{ # This comment is inside an empty object that started on the prior line! }} # Another that is imaginary aged. 1: {{ 2: "type_alias": "pants_test.engine.test_parsers.Bob", 3: "age": 42i, 4: "four": 1, 5: "five": 1, 6: "six": 1, 7: "seven": 1, 8: "eight": 1, 9: "nine": 1 10: }} """.format(filepath=filepath)).strip(), '\n'.join(actual_lines[1:]))
def parse(self, document, symbol_table=None, **kwargs): symbol_table = symbol_table or EmptyTable() return parse(parsers.JsonParser(symbol_table), document, **kwargs)
def parse(self, document, symbol_table=None, **kwargs): symbol_table = symbol_table or EMPTY_TABLE return parse(parsers.JsonParser(symbol_table), document, **kwargs)