diff options
Diffstat (limited to 'tests/test_git_command.py')
-rw-r--r-- | tests/test_git_command.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/test_git_command.py b/tests/test_git_command.py index c4c3a4c5..1e8beabc 100644 --- a/tests/test_git_command.py +++ b/tests/test_git_command.py | |||
@@ -16,6 +16,7 @@ | |||
16 | 16 | ||
17 | import re | 17 | import re |
18 | import os | 18 | import os |
19 | import subprocess | ||
19 | import unittest | 20 | import unittest |
20 | 21 | ||
21 | try: | 22 | try: |
@@ -65,6 +66,56 @@ class GitCommandTest(unittest.TestCase): | |||
65 | ) | 66 | ) |
66 | 67 | ||
67 | 68 | ||
69 | class GitCommandWaitTest(unittest.TestCase): | ||
70 | """Tests the GitCommand class .Wait()""" | ||
71 | |||
72 | def setUp(self): | ||
73 | class MockPopen(object): | ||
74 | rc = 0 | ||
75 | |||
76 | def communicate( | ||
77 | self, input: str = None, timeout: float = None | ||
78 | ) -> [str, str]: | ||
79 | """Mock communicate fn.""" | ||
80 | return ["", ""] | ||
81 | |||
82 | def wait(self, timeout=None): | ||
83 | return self.rc | ||
84 | |||
85 | self.popen = popen = MockPopen() | ||
86 | |||
87 | def popen_mock(*args, **kwargs): | ||
88 | return popen | ||
89 | |||
90 | def realpath_mock(val): | ||
91 | return val | ||
92 | |||
93 | mock.patch.object(subprocess, "Popen", side_effect=popen_mock).start() | ||
94 | |||
95 | mock.patch.object( | ||
96 | os.path, "realpath", side_effect=realpath_mock | ||
97 | ).start() | ||
98 | |||
99 | def tearDown(self): | ||
100 | mock.patch.stopall() | ||
101 | |||
102 | def test_raises_when_verify_non_zero_result(self): | ||
103 | self.popen.rc = 1 | ||
104 | r = git_command.GitCommand(None, ["status"], verify_command=True) | ||
105 | with self.assertRaises(git_command.GitCommandError): | ||
106 | r.Wait() | ||
107 | |||
108 | def test_returns_when_no_verify_non_zero_result(self): | ||
109 | self.popen.rc = 1 | ||
110 | r = git_command.GitCommand(None, ["status"], verify_command=False) | ||
111 | self.assertEqual(1, r.Wait()) | ||
112 | |||
113 | def test_default_returns_non_zero_result(self): | ||
114 | self.popen.rc = 1 | ||
115 | r = git_command.GitCommand(None, ["status"]) | ||
116 | self.assertEqual(1, r.Wait()) | ||
117 | |||
118 | |||
68 | class GitCallUnitTest(unittest.TestCase): | 119 | class GitCallUnitTest(unittest.TestCase): |
69 | """Tests the _GitCall class (via git_command.git).""" | 120 | """Tests the _GitCall class (via git_command.git).""" |
70 | 121 | ||