def testInvalidMap(self): message = json_format_proto3_pb2.TestMap() text = '{"int32Map": {"null": 2, "2": 3}}' self.assertRaisesRegexp( json_format.ParseError, 'Failed to parse int32Map field: invalid literal', json_format.Parse, text, message) text = '{"int32Map": {1: 2, "2": 3}}' self.assertRaisesRegexp( json_format.ParseError, (r'Failed to load JSON: Expecting property name' r'( enclosed in double quotes)?: line 1'), json_format.Parse, text, message) text = '{"boolMap": {"null": 1}}' self.assertRaisesRegexp( json_format.ParseError, 'Failed to parse boolMap field: Expected "true" or "false", not null.', json_format.Parse, text, message) if sys.version_info < (2, 7): return text = r'{"stringMap": {"a": 3, "\u0061": 2}}' self.assertRaisesRegexp(json_format.ParseError, 'Failed to load JSON: duplicate key a', json_format.Parse, text, message) text = r'{"stringMap": 0}' self.assertRaisesRegexp( json_format.ParseError, 'Failed to parse stringMap field: Map field string_map must be ' 'in a dict which is 0.', json_format.Parse, text, message)
def testInvalidMap(self): message = json_format_proto3_pb2.TestMap() text = '{"int32Map": {"null": 2, "2": 3}}' self.assertRaisesRegexp( json_format.ParseError, 'Failed to parse int32Map field: Couldn\'t parse integer: "null"', json_format.Parse, text, message) text = '{"int32Map": {1: 2, "2": 3}}' self.assertRaisesRegexp( json_format.ParseError, (r'Failed to load JSON: Expecting property name' r'( enclosed in double quotes)?: line 1'), json_format.Parse, text, message) text = r'{"stringMap": {"a": 3, "\u0061": 2}}' self.assertRaisesRegexp(json_format.ParseError, 'Failed to load JSON: duplicate key a', json_format.Parse, text, message) text = '{"boolMap": {"null": 1}}' self.assertRaisesRegexp( json_format.ParseError, 'Failed to parse boolMap field: Expect "true" or "false", not null.', json_format.Parse, text, message)