-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgrade light-the-torch requirements (#5)
* upgrade light-the-torch requirements * extract force_cpu help from light-the-torch
- Loading branch information
Showing
3 changed files
with
77 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,35 @@ | |
from light_the_torch.computation_backend import CPUBackend | ||
|
||
|
||
@pytest.mark.slow | ||
def test_help_ini(cmd): | ||
result = cmd("--help-ini") | ||
result.assert_success(is_run_test_env=False) | ||
assert "disable_light_the_torch" in result.out | ||
assert "force_cpu" in result.out | ||
@pytest.fixture | ||
def patch_extract_dists(mocker): | ||
def patch_extract_dists_(return_value=None): | ||
if return_value is None: | ||
return_value = [] | ||
return mocker.patch( | ||
"tox_ltt.plugin.ltt.extract_dists", return_value=return_value | ||
) | ||
return mocker.patch() | ||
|
||
return patch_extract_dists_ | ||
|
||
|
||
@pytest.fixture | ||
def patch_find_links(mocker): | ||
def patch_find_links_(return_value=None): | ||
if return_value is None: | ||
return_value = [] | ||
return mocker.patch( | ||
"tox_ltt.plugin.ltt.find_links", return_value=return_value | ||
) | ||
return mocker.patch() | ||
|
||
return patch_find_links_ | ||
|
||
|
||
@pytest.fixture | ||
def install_mock(mocker): | ||
return mocker.patch("tox.venv.VirtualEnv.run_install_command") | ||
|
||
|
||
def get_pyproject_toml(): | ||
|
@@ -100,14 +123,16 @@ def tox_ltt_initproj_( | |
return tox_ltt_initproj_ | ||
|
||
|
||
@pytest.fixture | ||
def install_mock(mocker): | ||
return mocker.patch("tox.venv.VirtualEnv.run_install_command") | ||
def test_help_ini(cmd): | ||
result = cmd("--help-ini") | ||
result.assert_success(is_run_test_env=False) | ||
assert "disable_light_the_torch" in result.out | ||
assert "force_cpu" in result.out | ||
|
||
|
||
@pytest.mark.slow | ||
def test_tox_ltt_disabled(mocker, tox_ltt_initproj, cmd): | ||
mock = mocker.patch("tox_ltt.plugin.ltt.resolve_dists") | ||
def test_tox_ltt_disabled(patch_extract_dists, tox_ltt_initproj, cmd): | ||
mock = patch_extract_dists() | ||
tox_ltt_initproj(disable_light_the_torch=True) | ||
|
||
result = cmd() | ||
|
@@ -117,9 +142,8 @@ def test_tox_ltt_disabled(mocker, tox_ltt_initproj, cmd): | |
|
||
|
||
@pytest.mark.slow | ||
def test_tox_ltt_force_cpu(mocker, tox_ltt_initproj, cmd, install_mock): | ||
mock = mocker.patch("tox_ltt.plugin.ltt.find_links", return_value=[]) | ||
|
||
def test_tox_ltt_force_cpu(patch_find_links, tox_ltt_initproj, cmd, install_mock): | ||
mock = patch_find_links() | ||
tox_ltt_initproj(deps=("torch",), force_cpu=True) | ||
|
||
result = cmd() | ||
|
@@ -130,9 +154,10 @@ def test_tox_ltt_force_cpu(mocker, tox_ltt_initproj, cmd, install_mock): | |
assert kwargs["computation_backend"] == CPUBackend() | ||
|
||
|
||
def test_tox_ltt_no_requirements(mocker, tox_ltt_initproj, cmd, install_mock): | ||
mock = mocker.patch("tox_ltt.plugin.ltt.resolve_dists") | ||
|
||
def test_tox_ltt_no_requirements( | ||
patch_extract_dists, tox_ltt_initproj, cmd, install_mock | ||
): | ||
mock = patch_extract_dists() | ||
tox_ltt_initproj(skip_install=True) | ||
|
||
result = cmd() | ||
|
@@ -142,8 +167,10 @@ def test_tox_ltt_no_requirements(mocker, tox_ltt_initproj, cmd, install_mock): | |
|
||
|
||
@pytest.mark.slow | ||
def test_tox_ltt_no_pytorch_dists(mocker, tox_ltt_initproj, cmd, install_mock): | ||
mock = mocker.patch("tox_ltt.plugin.ltt.find_links") | ||
def test_tox_ltt_no_pytorch_dists( | ||
patch_find_links, tox_ltt_initproj, cmd, install_mock | ||
): | ||
mock = patch_find_links() | ||
|
||
deps = ("light-the-torch",) | ||
tox_ltt_initproj(deps=deps) | ||
|
@@ -155,8 +182,10 @@ def test_tox_ltt_no_pytorch_dists(mocker, tox_ltt_initproj, cmd, install_mock): | |
|
||
|
||
@pytest.mark.slow | ||
def test_tox_ltt_direct_pytorch_dists(mocker, tox_ltt_initproj, cmd, install_mock): | ||
mock = mocker.patch("tox_ltt.plugin.ltt.find_links", return_value=[]) | ||
def test_tox_ltt_direct_pytorch_dists( | ||
patch_find_links, tox_ltt_initproj, cmd, install_mock | ||
): | ||
mock = patch_find_links() | ||
|
||
deps = ("torch", "torchaudio", "torchtext", "torchvision") | ||
dists = set(deps) | ||
|
@@ -171,8 +200,10 @@ def test_tox_ltt_direct_pytorch_dists(mocker, tox_ltt_initproj, cmd, install_moc | |
|
||
|
||
@pytest.mark.slow | ||
def test_tox_ltt_indirect_pytorch_dists(mocker, tox_ltt_initproj, cmd, install_mock): | ||
mock = mocker.patch("tox_ltt.plugin.ltt.find_links", return_value=[]) | ||
def test_tox_ltt_indirect_pytorch_dists( | ||
patch_find_links, tox_ltt_initproj, cmd, install_mock | ||
): | ||
mock = patch_find_links() | ||
|
||
deps = ("git+https://github.com/pmeier/[email protected]",) | ||
dists = {"torch>=1.5.0", "torchvision>=0.6.0"} | ||
|
@@ -187,9 +218,9 @@ def test_tox_ltt_indirect_pytorch_dists(mocker, tox_ltt_initproj, cmd, install_m | |
|
||
|
||
def test_tox_ltt_project_pytorch_dists( | ||
subtests, mocker, tox_ltt_initproj, cmd, install_mock | ||
subtests, patch_find_links, tox_ltt_initproj, cmd, install_mock | ||
): | ||
mock = mocker.patch("tox_ltt.plugin.ltt.find_links", return_value=[]) | ||
mock = patch_find_links() | ||
|
||
install_requires = ("torch>=1.5.0", "torchvision>=0.6.0") | ||
dists = set(install_requires) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters