Commit a3faf080 authored by Josh Haberman's avatar Josh Haberman

Added JSON support to Python conformance tests.

parent 325392dd
...@@ -39,6 +39,7 @@ import struct ...@@ -39,6 +39,7 @@ import struct
import sys import sys
import os import os
from google.protobuf import message from google.protobuf import message
from google.protobuf import json_format
import conformance_pb2 import conformance_pb2
sys.stdout = os.fdopen(sys.stdout.fileno(), 'wb', 0) sys.stdout = os.fdopen(sys.stdout.fileno(), 'wb', 0)
...@@ -61,8 +62,11 @@ def do_test(request): ...@@ -61,8 +62,11 @@ def do_test(request):
return response return response
elif request.WhichOneof('payload') == 'json_payload': elif request.WhichOneof('payload') == 'json_payload':
response.skipped = "JSON not supported yet." try:
return response json_format.Parse(request.json_payload, test_message)
except json_format.ParseError as e:
response.parse_error = str(e)
return response
else: else:
raise "Request didn't have payload." raise "Request didn't have payload."
...@@ -74,7 +78,8 @@ def do_test(request): ...@@ -74,7 +78,8 @@ def do_test(request):
response.protobuf_payload = test_message.SerializeToString() response.protobuf_payload = test_message.SerializeToString()
elif request.requested_output_format == conformance_pb2.JSON: elif request.requested_output_format == conformance_pb2.JSON:
response.skipped = "JSON not supported yet." response.json_payload = json_format.MessageToJson(test_message)
except Exception as e: except Exception as e:
response.runtime_error = str(e) response.runtime_error = str(e)
......
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