-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up matrix testing for PDM versions. (#4)
- Loading branch information
Showing
10 changed files
with
220 additions
and
17 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from pathlib import Path | ||
|
||
|
||
FIXTURES = Path(__file__).parent / "fixtures" |
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import os | ||
|
||
from typing import Dict, Tuple | ||
|
||
import pytest | ||
|
||
|
||
os.environ.update(CI="1", PDM_CHECK_UPDATE="0") | ||
|
||
|
||
# store history of failures per test class name and per index in parametrize (if parametrize used) | ||
_test_failed_incremental: Dict[str, Dict[Tuple[int, ...], str]] = {} | ||
|
||
|
||
def pytest_runtest_makereport(item, call): | ||
if "incremental" in item.keywords: | ||
# incremental marker is used | ||
if call.excinfo is not None: | ||
# the test has failed | ||
# retrieve the class name of the test | ||
cls_name = str(item.cls) | ||
# retrieve the index of the test if parametrize is used in combination with incremental | ||
parametrize_index = ( | ||
tuple(item.callspec.indices.values()) | ||
if hasattr(item, "callspec") | ||
else () | ||
) | ||
# retrieve the name of the test function | ||
test_name = item.originalname or item.name | ||
# store in _test_failed_incremental the original name of the failed test | ||
_test_failed_incremental.setdefault(cls_name, {}).setdefault( | ||
parametrize_index, test_name | ||
) | ||
|
||
|
||
def pytest_runtest_setup(item): | ||
if "incremental" in item.keywords: | ||
# retrieve the class name of the test | ||
cls_name = str(item.cls) | ||
# check if a previous test has failed for this class | ||
if cls_name in _test_failed_incremental: | ||
# retrieve the index of the test if parametrize is used in combination with incremental | ||
parametrize_index = ( | ||
tuple(item.callspec.indices.values()) | ||
if hasattr(item, "callspec") | ||
else () | ||
) | ||
# retrieve the name of the first test function to fail for this class name and index | ||
test_name = _test_failed_incremental[cls_name].get(parametrize_index, None) | ||
# if name found, test has failed for the combination of class name & test name | ||
if test_name is not None: | ||
pytest.xfail("previous test failed ({})".format(test_name)) | ||
|
||
|
||
def pytest_configure(config): | ||
config.addinivalue_line( | ||
"markers", "incremental: mark tests in class to run in series with early out" | ||
) | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption( | ||
"--pdm-bin", action="store", default="pdm", help="the pdm binary to run" | ||
) |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[project] | ||
name = "test-cpu-only" | ||
authors = [ | ||
{name = "Tom Solberg", email = "[email protected]"}, | ||
] | ||
requires-python = "~=3.8.0" | ||
license = {text = "MIT"} | ||
dependencies = [] | ||
description = "" | ||
version = "0.0.01" | ||
|
||
[build-system] | ||
requires = ["pdm-pep517"] | ||
build-backend = "pdm.pep517.api" | ||
|
||
[tool.pdm.plugins.torch] | ||
dependencies = [ | ||
"torch==1.10.2" | ||
] | ||
lockfile = "torch.lock" | ||
enable-cpu = true | ||
|
||
enable-rocm = false | ||
rocm-versions = ["4.2"] | ||
|
||
enable-cuda = false | ||
cuda-versions = ["cu111", "cu113"] | ||
|
||
[tool.pdm.scripts] | ||
post_install = "pdm plugin add ../../" | ||
post_lock = "pdm torch lock" |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import os | ||
import shutil | ||
import subprocess | ||
|
||
from pathlib import Path | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
from tests import FIXTURES | ||
|
||
|
||
PLUGIN_DIR = os.path.abspath(f"{__file__}/../..") | ||
|
||
|
||
def copytree(src: Path, dst: Path) -> None: | ||
if not dst.exists(): | ||
dst.mkdir(parents=True) | ||
for subpath in src.iterdir(): | ||
if subpath.is_dir(): | ||
copytree(subpath, dst / subpath.name) | ||
else: | ||
shutil.copy2(subpath, dst) | ||
|
||
|
||
def make_entry_point(plugin): | ||
ret = mock.Mock() | ||
ret.load.return_value = plugin | ||
return ret | ||
|
||
|
||
def tmpdir_project(project_name, dest): | ||
source = FIXTURES / project_name | ||
copytree(source, dest) | ||
|
||
|
||
@pytest.fixture | ||
def pdm(request): | ||
pdm_name = request.config.getoption("--pdm-bin") | ||
|
||
def _invoker(args, dir): | ||
output = subprocess.check_output([pdm_name, *args], cwd=dir) | ||
return output | ||
|
||
return _invoker | ||
|
||
|
||
class TestPdmVariants: | ||
@staticmethod | ||
def test_install_plugin(tmpdir, pdm): | ||
output = pdm(["self", "add", PLUGIN_DIR], tmpdir) | ||
assert output == b"Installation succeeds.\n" | ||
|
||
@staticmethod | ||
def test_lock_check_fails(tmpdir, pdm): | ||
import subprocess | ||
|
||
tmpdir_project("cpu-only", tmpdir) | ||
with pytest.raises(subprocess.CalledProcessError): | ||
pdm(["torch", "lock", "--check"], tmpdir) | ||
|
||
@staticmethod | ||
def test_lock_plugin_check_succeeds(tmpdir, pdm): | ||
tmpdir_project("cpu-only", tmpdir) | ||
pdm(["torch", "lock"], tmpdir) | ||
pdm(["torch", "lock", "--check"], tmpdir) | ||
|
||
@staticmethod | ||
def test_install_fails(tmpdir, pdm): | ||
import subprocess | ||
|
||
tmpdir_project("cpu-only", tmpdir) | ||
with pytest.raises(subprocess.CalledProcessError): | ||
pdm(["torch", "install", "cpu"], tmpdir) | ||
|
||
@staticmethod | ||
def test_install_succeeds(tmpdir, pdm): | ||
tmpdir_project("cpu-only", tmpdir) | ||
pdm(["torch", "lock"], tmpdir) | ||
pdm(["torch", "install", "cpu"], tmpdir) |