From 953278adbf3e52f0ef84a9320ed61e2c3238cd6b Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Fri, 28 Feb 2020 19:46:36 +0000 Subject: [PATCH] Print content of description backup on exit Change-Id: I9607035c8ee5e5f4423b7526c67f384cfebb2f1d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2079708 Commit-Queue: Josip Sokcevic Auto-Submit: Josip Sokcevic Reviewed-by: Edward Lesmes --- git_cl.py | 4 ++++ tests/git_cl_test.py | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/git_cl.py b/git_cl.py index d053dd496..9d60c4fae 100755 --- a/git_cl.py +++ b/git_cl.py @@ -133,6 +133,10 @@ _IS_BEING_TESTED = False def DieWithError(message, change_desc=None): if change_desc: SaveDescriptionBackup(change_desc) + print('\n ** Content of CL description **\n' + + '='*72 + '\n' + + change_desc.description + '\n' + + '='*72 + '\n') print(message, file=sys.stderr) sys.exit(1) diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index 5bf17f817..926afbe8e 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -179,6 +179,28 @@ class SystemExitMock(Exception): class TestGitClBasic(unittest.TestCase): + def setUp(self): + mock.patch('sys.exit', side_effect=SystemExitMock).start() + mock.patch('sys.stdout', StringIO()).start() + mock.patch('sys.stderr', StringIO()).start() + self.addCleanup(mock.patch.stopall) + + def test_die_with_error(self): + with self.assertRaises(SystemExitMock): + git_cl.DieWithError('foo', git_cl.ChangeDescription('lorem ipsum')) + self.assertEqual(sys.stderr.getvalue(), 'foo\n') + self.assertTrue('saving CL description' in sys.stdout.getvalue()) + self.assertTrue('Content of CL description' in sys.stdout.getvalue()) + self.assertTrue('lorem ipsum' in sys.stdout.getvalue()) + sys.exit.assert_called_once_with(1) + + def test_die_with_error_no_desc(self): + with self.assertRaises(SystemExitMock): + git_cl.DieWithError('foo') + self.assertEqual(sys.stderr.getvalue(), 'foo\n') + self.assertEqual(sys.stdout.getvalue(), '') + sys.exit.assert_called_once_with(1) + def test_fetch_description(self): cl = git_cl.Changelist(issue=1, codereview_host='host') cl.description = 'x'