From b2e30cef911e184a471d7229fab060b2d1e7866c Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 9 Nov 2026 22:29:01 -0500 Subject: [PATCH] tests: delete buggy git_command tests The Popen mocking is incomplete & buggy: * It uses a nested class which hinders pickling. * Nested classes should rarely be used in the first place, stylewise. * It does not mock the full Popen API causing failures. For example, this fails: $ pytest -vvv tests/test_git_command.py::GitCommandWaitTest ... FAILED tests/test_git_command.py::GitCommandWaitTest::test_default_returns_non_zero_result - AttributeError: 'MockPopen' object has no attribute 'returncode' FAILED tests/test_git_command.py::GitCommandWaitTest::test_raises_when_verify_non_zero_result - AttributeError: 'MockPopen' object has no attribute 'returncode' FAILED tests/test_git_command.py::GitCommandWaitTest::test_returns_when_no_verify_non_zero_result - AttributeError: 'MockPopen' object has no attribute 'returncode' ... Delete the tests since they don't seem to add much value currently. Bug: b/293344017 Change-Id: I3d613a84657e30cbc7eac0b363ebfcb46b95eb49 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/655886 Commit-Queue: Mike Frysinger Reviewed-by: Gavin Mak Tested-by: Mike Frysinger --- tests/test_git_command.py | 54 --------------------------------------- 1 file changed, 54 deletions(-) diff --git a/tests/test_git_command.py b/tests/test_git_command.py index 21caa7f42..dccc83106 100644 --- a/tests/test_git_command.py +++ b/tests/test_git_command.py @@ -65,60 +65,6 @@ class GitCommandTest(unittest.TestCase): ) -class GitCommandWaitTest(unittest.TestCase): - """Tests the GitCommand class .Wait()""" - - def setUp(self): - class MockPopen: - rc = 0 - - def __init__(self): - self.stdout = io.BufferedReader(io.BytesIO()) - self.stderr = io.BufferedReader(io.BytesIO()) - - def communicate( - self, input: str = None, timeout: float = None - ) -> [str, str]: - """Mock communicate fn.""" - return ["", ""] - - def wait(self, timeout=None): - return self.rc - - self.popen = popen = MockPopen() - - def popen_mock(*args, **kwargs): - return popen - - def realpath_mock(val): - return val - - mock.patch.object(subprocess, "Popen", side_effect=popen_mock).start() - - mock.patch.object( - os.path, "realpath", side_effect=realpath_mock - ).start() - - def tearDown(self): - mock.patch.stopall() - - def test_raises_when_verify_non_zero_result(self): - self.popen.rc = 1 - r = git_command.GitCommand(None, ["status"], verify_command=True) - with self.assertRaises(git_command.GitCommandError): - r.Wait() - - def test_returns_when_no_verify_non_zero_result(self): - self.popen.rc = 1 - r = git_command.GitCommand(None, ["status"], verify_command=False) - self.assertEqual(1, r.Wait()) - - def test_default_returns_non_zero_result(self): - self.popen.rc = 1 - r = git_command.GitCommand(None, ["status"]) - self.assertEqual(1, r.Wait()) - - class GitCommandStreamLogsTest(unittest.TestCase): """Tests the GitCommand class stderr log streaming cases."""