From 790a0c522dcfd85dc061565adadb2782b6ad9da1 Mon Sep 17 00:00:00 2001 From: Brian Ryner Date: Wed, 11 Jan 2023 17:43:46 +0000 Subject: [PATCH] Fix CheckCIPDManifest for python 3. Change-Id: Icf7b8e7ad732a731520550ff9e276f13016effb7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4149964 Reviewed-by: Josip Sokcevic Commit-Queue: Josip Sokcevic Auto-Submit: Brian Ryner --- presubmit_canned_checks.py | 2 ++ tests/presubmit_unittest.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 321858933..4b5227772 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -1645,6 +1645,8 @@ def CheckCIPDManifest(input_api, output_api, path=None, content=None): assert path is None, 'Cannot provide both "path" and "content".' cmd += ['-ensure-file=-'] kwargs['stdin'] = content + if input_api.sys.version_info.major != 2: + kwargs['stdin'] = kwargs['stdin'].encode('utf-8') # quick and dirty parser to extract checked packages. packages = [ l.split()[0] for l in (ll.strip() for ll in content.splitlines()) diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index e083c6cc9..00a65bab8 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -3125,7 +3125,7 @@ the current line as well! input_api, presubmit.OutputApi, content='manifest_content') self.assertEqual(command.cmd, ['cipd', 'ensure-file-verify', '-log-level', 'debug', '-ensure-file=-']) - self.assertEqual(command.stdin, 'manifest_content') + self.assertEqual(command.stdin, b'manifest_content') self.assertEqual(command.kwargs, { 'stdin': subprocess.PIPE, 'stdout': subprocess.PIPE, @@ -3151,7 +3151,7 @@ the current line as well! }) self.assertEqual(command.cmd, ['cipd', 'ensure-file-verify', '-ensure-file=-']) - self.assertEqual(command.stdin, content) + self.assertEqual(command.stdin, content.encode()) self.assertEqual(command.kwargs, { 'stdin': subprocess.PIPE, 'stdout': subprocess.PIPE,