mirror of
https://gerrit.googlesource.com/git-repo
synced 2026-11-14 16:27:13 +00:00
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 <vapier@google.com> Reviewed-by: Gavin Mak <gavinmak@google.com> Tested-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
1 parent
27402ddb25
commit
b2e30cef91
1 file changed
-54
@@ -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."""
|
||||
|
||||
|
||||
Reference in new issue
Block a user