From 9bb7b96c4d22f66abc0ce1dba5c94b989e4cb72a Mon Sep 17 00:00:00 2001 From: Edward Lemur Date: Wed, 30 Oct 2019 22:16:10 +0000 Subject: [PATCH] git-rebase-update: Make tests run on Python 3. Bug: 1009809 Change-Id: I47c9a468b2922248b823ebae5e71863a698c30f0 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1889166 Reviewed-by: Anthony Polito Commit-Queue: Edward Lesmes --- git_new_branch.py | 4 ++-- git_rename_branch.py | 2 +- tests/git_rebase_update_test.py | 11 +++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/git_new_branch.py b/git_new_branch.py index d61a42d79..856b6eab9 100755 --- a/git_new_branch.py +++ b/git_new_branch.py @@ -61,8 +61,8 @@ def main(args): run('checkout', '--track', opts.upstream, '-b', opts.branch_name) get_or_create_merge_base(opts.branch_name) except subprocess2.CalledProcessError as cpe: - sys.stdout.write(cpe.stdout) - sys.stderr.write(cpe.stderr) + sys.stdout.write(cpe.stdout.decode('utf-8', 'replace')) + sys.stderr.write(cpe.stderr.decode('utf-8', 'replace')) return 1 sys.stderr.write('Switched to branch %s.\n' % opts.branch_name) return 0 diff --git a/git_rename_branch.py b/git_rename_branch.py index 8a07535f7..d40b60681 100755 --- a/git_rename_branch.py +++ b/git_rename_branch.py @@ -42,7 +42,7 @@ def main(args): if branch_config(branch, 'remote') == '.': set_branch_config(branch, 'merge', 'refs/heads/' + opts.new_name) except subprocess2.CalledProcessError as cpe: - sys.stderr.write(cpe.stderr) + sys.stderr.write(cpe.stderr.decode('utf-8', 'replace')) return 1 return 0 diff --git a/tests/git_rebase_update_test.py b/tests/git_rebase_update_test.py index c2a8c5366..441bc68eb 100755 --- a/tests/git_rebase_update_test.py +++ b/tests/git_rebase_update_test.py @@ -1,10 +1,13 @@ -#!/usr/bin/env python +#!/usr/bin/env vpython3 # Copyright 2014 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """Unit tests for git_rebase_update.py""" +from __future__ import print_function +from __future__ import unicode_literals + import os import sys @@ -24,7 +27,7 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase): @classmethod def getRepoContent(cls, commit): # Every commit X gets a file X with the content X - return {commit: {'data': commit}} + return {commit: {'data': commit.encode('utf-8')}} @classmethod def setUpClass(cls): @@ -119,7 +122,7 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase): self.assertEqual(self.repo['E'], self.origin['E']) with self.repo.open('bob', 'wb') as f: - f.write('testing auto-freeze/thaw') + f.write(b'testing auto-freeze/thaw') output, _ = self.repo.capture_stdio(self.reup.main) self.assertIn('Cannot rebase-update', output) @@ -158,7 +161,7 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase): self.assertIn('sub_K up-to-date', output) with self.repo.open('bob') as f: - self.assertEqual('testing auto-freeze/thaw', f.read()) + self.assertEqual(b'testing auto-freeze/thaw', f.read()) self.assertEqual(self.repo.git('status', '--porcelain').stdout, '?? bob\n')