|
1 | | -import subprocess |
2 | 1 | from test.data import get_pip_log_with_dash, get_pip_log_with_underscore |
3 | | -from unittest.mock import MagicMock |
| 2 | +from unittest.mock import patch |
4 | 3 |
|
5 | 4 | from dac._version_management import find_latest_version |
6 | | -from pytest import MonkeyPatch, fixture |
7 | 5 |
|
8 | 6 |
|
9 | | -def test_if_pkg_name_uses_dash_separator_and_pip_log_dash_then_correct_latest_version(mock_pip_output_with_dash: None): |
10 | | - latest_version = find_latest_version(pkg_name="investing-algorithm-framework") |
11 | | - assert latest_version == "2.3.2" |
| 7 | +def test_if_pkg_name_uses_dash_separator_and_pip_log_dash_then_correct_latest_version(): |
| 8 | + with patch("dac._version_management._pretend_pip_install") as mock_pretend_pip_install: |
| 9 | + mock_pretend_pip_install.return_value = get_pip_log_with_dash() |
12 | 10 |
|
| 11 | + latest_version = find_latest_version(pkg_name="investing-algorithm-framework") |
13 | 12 |
|
14 | | -def test_if_pkg_name_uses_dash_separator_and_pip_log_underscore_then_correct_latest_version( |
15 | | - mock_pip_output_with_underscore: None, |
16 | | -): |
17 | | - latest_version = find_latest_version(pkg_name="investing-algorithm-framework") |
18 | | - assert latest_version == "2.3.2" |
| 13 | + assert latest_version == "2.3.2" |
19 | 14 |
|
20 | 15 |
|
21 | | -def test_if_pkg_name_uses_underscore_separator_and_pip_log_dash_then_correct_latest_version( |
22 | | - mock_pip_output_with_dash: None, |
23 | | -): |
24 | | - latest_version = find_latest_version(pkg_name="investing_algorithm_framework") |
25 | | - assert latest_version == "2.3.2" |
| 16 | +def test_if_pkg_name_uses_dash_separator_and_pip_log_underscore_then_correct_latest_version(): |
| 17 | + with patch("dac._version_management._pretend_pip_install") as mock_pretend_pip_install: |
| 18 | + mock_pretend_pip_install.return_value = get_pip_log_with_underscore() |
26 | 19 |
|
| 20 | + latest_version = find_latest_version(pkg_name="investing-algorithm-framework") |
27 | 21 |
|
28 | | -def test_if_pkg_name_uses_underscore_separator_and_pip_log_underscore_then_correct_latest_version( |
29 | | - mock_pip_output_with_underscore: None, |
30 | | -): |
31 | | - latest_version = find_latest_version(pkg_name="investing_algorithm_framework") |
32 | | - assert latest_version == "2.3.2" |
| 22 | + assert latest_version == "2.3.2" |
33 | 23 |
|
34 | 24 |
|
35 | | -@fixture |
36 | | -def mock_pip_output_with_dash(monkeypatch: MonkeyPatch): |
37 | | - output = MagicMock() |
38 | | - output.decode.return_value = get_pip_log_with_dash() |
| 25 | +def test_if_pkg_name_uses_underscore_separator_and_pip_log_dash_then_correct_latest_version(): |
| 26 | + with patch("dac._version_management._pretend_pip_install") as mock_pretend_pip_install: |
| 27 | + mock_pretend_pip_install.return_value = get_pip_log_with_dash() |
39 | 28 |
|
40 | | - def return_foo(*args, **kwargs) -> str: |
41 | | - return output |
| 29 | + latest_version = find_latest_version(pkg_name="investing_algorithm_framework") |
42 | 30 |
|
43 | | - monkeypatch.setattr(subprocess, "check_output", return_foo) |
| 31 | + assert latest_version == "2.3.2" |
44 | 32 |
|
45 | 33 |
|
46 | | -@fixture |
47 | | -def mock_pip_output_with_underscore(monkeypatch: MonkeyPatch): |
48 | | - output = MagicMock() |
49 | | - output.decode.return_value = get_pip_log_with_underscore() |
| 34 | +def test_if_pkg_name_uses_underscore_separator_and_pip_log_underscore_then_correct_latest_version(): |
| 35 | + with patch("dac._version_management._pretend_pip_install") as mock_pretend_pip_install: |
| 36 | + mock_pretend_pip_install.return_value = get_pip_log_with_underscore() |
50 | 37 |
|
51 | | - def return_foo(*args, **kwargs) -> str: |
52 | | - return output |
| 38 | + latest_version = find_latest_version(pkg_name="investing_algorithm_framework") |
53 | 39 |
|
54 | | - monkeypatch.setattr(subprocess, "check_output", return_foo) |
| 40 | + assert latest_version == "2.3.2" |
0 commit comments