Adjust checker code to read json first with binary fallback.
Adjust the checker code used by CQ checkers to attempt to read the
config input as json first with a temporary fallback to binary. When the
binary is removed the fallback parsing can be removed.
BUG=chromium:1073530
TEST=./run_py_unittests.sh
Change-Id: I5976ff83291a5f59461dcac54f97fc936ff7aca9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/config/+/2174612
Reviewed-by: Andrew Lamb <andrewlamb@chromium.org>
Commit-Queue: David Burger <dburger@chromium.org>
Tested-by: David Burger <dburger@chromium.org>
diff --git a/payload_utils/checker/io_utils_test.py b/payload_utils/checker/io_utils_test.py
index 796d45a..08d08ac 100644
--- a/payload_utils/checker/io_utils_test.py
+++ b/payload_utils/checker/io_utils_test.py
@@ -12,6 +12,8 @@
from chromiumos.config.payload.config_bundle_pb2 import ConfigBundle
from chromiumos.config.api.program_pb2 import ProgramList, Program
+from google.protobuf import json_format
+
class IoUtilsTest(unittest.TestCase):
"""Tests for io_utils."""
@@ -24,10 +26,13 @@
os.mkdir(os.path.join(repo_path, 'generated'))
self.config_path = os.path.join(repo_path, 'generated',
- 'config.binaryproto')
- with open(self.config_path, 'wb') as f:
- f.write(self.config.SerializeToString())
+ 'config.jsonproto')
+ json_output = json_format.MessageToJson(self.config,
+ sort_keys=True,
+ use_integers_for_enums=True)
+ with open(self.config_path, 'w') as f:
+ print(json_output, file=f)
def test_read_config(self):
- """Tests the binary proto can be read."""
+ """Tests the json proto can be read."""
self.assertEqual(io_utils.read_config(self.config_path), self.config)