|
1 | 1 | import subprocess
|
| 2 | +from unittest.mock import patch |
2 | 3 |
|
3 |
| -import mock |
4 | 4 | from harvey.git import Git
|
5 | 5 |
|
6 | 6 |
|
7 |
| -@mock.patch('os.path.exists', return_value=True) |
8 |
| -@mock.patch('harvey.git.Git.pull_repo') |
| 7 | +@patch('os.path.exists', return_value=True) |
| 8 | +@patch('harvey.git.Git.pull_repo') |
9 | 9 | def test_update_git_repo_path_exists(mock_pull_repo, mock_path_exists, mock_project_path, mock_webhook): # noqa
|
10 | 10 | Git.update_git_repo(mock_webhook)
|
11 | 11 |
|
12 | 12 | mock_pull_repo.assert_called_once_with(mock_project_path, mock_webhook)
|
13 | 13 |
|
14 | 14 |
|
15 |
| -@mock.patch('os.path.exists', return_value=False) |
16 |
| -@mock.patch('harvey.git.Git.clone_repo') |
17 |
| -def test_update_git_repo_path_does_not_exist(mock_clone_repo, mock_path_exists, mock_project_path, mock_webhook): # noqa |
| 15 | +@patch('os.path.exists', return_value=False) |
| 16 | +@patch('harvey.git.Git.clone_repo') |
| 17 | +def test_update_git_repo_path_does_not_exist(mock_clone_repo, mock_path_exists, mock_project_path, mock_webhook): |
18 | 18 | Git.update_git_repo(mock_webhook)
|
19 | 19 |
|
20 | 20 | mock_clone_repo.assert_called_once_with(mock_project_path, mock_webhook)
|
21 | 21 |
|
22 | 22 |
|
23 |
| -@mock.patch('subprocess.check_output') |
| 23 | +@patch('subprocess.check_output') |
24 | 24 | def test_clone_repo(mock_subprocess, mock_project_path, mock_webhook):
|
25 | 25 | # TODO: Mock the subprocess better to ensure it does what it's supposed to
|
26 | 26 | Git.clone_repo(mock_project_path, mock_webhook)
|
27 | 27 |
|
28 | 28 | mock_subprocess.assert_called_once()
|
29 | 29 |
|
30 | 30 |
|
31 |
| -@mock.patch('harvey.utils.Utils.kill') |
32 |
| -@mock.patch('subprocess.check_output', side_effect=subprocess.TimeoutExpired(cmd=subprocess.check_output, timeout=0.1)) # noqa |
33 |
| -def test_clone_repo_subprocess_timeout(mock_subprocess, mock_utils_kill, mock_project_path, mock_webhook): # noqa |
| 31 | +@patch('harvey.utils.Utils.kill') |
| 32 | +@patch('subprocess.check_output', side_effect=subprocess.TimeoutExpired(cmd=subprocess.check_output, timeout=0.1)) |
| 33 | +def test_clone_repo_subprocess_timeout(mock_subprocess, mock_utils_kill, mock_project_path, mock_webhook): |
34 | 34 | Git.clone_repo(mock_project_path, mock_webhook)
|
35 | 35 |
|
36 | 36 | mock_utils_kill.assert_called_once()
|
37 | 37 |
|
38 | 38 |
|
39 |
| -@mock.patch('harvey.utils.Utils.kill') |
40 |
| -@mock.patch('subprocess.check_output', side_effect=subprocess.CalledProcessError(returncode=1, cmd=subprocess.check_output)) # noqa |
41 |
| -def test_clone_repo_process_error(mock_subprocess, mock_utils_kill, mock_project_path, mock_webhook): # noqa |
| 39 | +@patch('harvey.utils.Utils.kill') |
| 40 | +@patch('subprocess.check_output', side_effect=subprocess.CalledProcessError(returncode=1, cmd=subprocess.check_output)) |
| 41 | +def test_clone_repo_process_error(mock_subprocess, mock_utils_kill, mock_project_path, mock_webhook): |
42 | 42 | Git.clone_repo(mock_project_path, mock_webhook)
|
43 | 43 |
|
44 | 44 | mock_utils_kill.assert_called_once()
|
45 | 45 |
|
46 | 46 |
|
47 |
| -@mock.patch('subprocess.check_output') |
| 47 | +@patch('subprocess.check_output') |
48 | 48 | def test_pull_repo(mock_subprocess, mock_project_path, mock_webhook):
|
49 | 49 | # TODO: Mock the subprocess better to ensure it does what it's supposed to
|
50 | 50 | Git.pull_repo(mock_project_path, mock_webhook)
|
51 | 51 |
|
52 | 52 | mock_subprocess.assert_called_once()
|
53 | 53 |
|
54 | 54 |
|
55 |
| -@mock.patch('harvey.utils.Utils.kill') |
56 |
| -@mock.patch('subprocess.check_output', side_effect=subprocess.TimeoutExpired(cmd=subprocess.check_output, timeout=0.1)) # noqa |
57 |
| -def test_pull_repo_subprocess_timeout(mock_subprocess, mock_utils_kill, mock_project_path, mock_webhook): # noqa |
| 55 | +@patch('harvey.utils.Utils.kill') |
| 56 | +@patch('subprocess.check_output', side_effect=subprocess.TimeoutExpired(cmd=subprocess.check_output, timeout=0.1)) |
| 57 | +def test_pull_repo_subprocess_timeout(mock_subprocess, mock_utils_kill, mock_project_path, mock_webhook): |
58 | 58 | Git.pull_repo(mock_project_path, mock_webhook)
|
59 | 59 |
|
60 | 60 | mock_utils_kill.assert_called_once()
|
61 | 61 |
|
62 | 62 |
|
63 |
| -@mock.patch('harvey.utils.Utils.kill') |
64 |
| -@mock.patch('subprocess.check_output', side_effect=subprocess.CalledProcessError(returncode=1, cmd=subprocess.check_output)) # noqa |
65 |
| -def test_pull_repo_process_error(mock_subprocess, mock_utils_kill, mock_project_path, mock_webhook): # noqa |
| 63 | +@patch('harvey.utils.Utils.kill') |
| 64 | +@patch('subprocess.check_output', side_effect=subprocess.CalledProcessError(returncode=1, cmd=subprocess.check_output)) |
| 65 | +def test_pull_repo_process_error(mock_subprocess, mock_utils_kill, mock_project_path, mock_webhook): |
66 | 66 | Git.pull_repo(mock_project_path, mock_webhook)
|
67 | 67 |
|
68 | 68 | mock_utils_kill.assert_called_once()
|
0 commit comments