Skip to content

Commit

Permalink
Add rapids-test-dummy package for testing
Browse files Browse the repository at this point in the history
Tests previously relied on the more-itertools package, but that
package is now a dependency of one of rapids-build-backend's
dependencies. Create a new rapids-test-dummy package to ensure that
there's no way it could accidentally be installed transitively.
  • Loading branch information
KyleFromNVIDIA committed Aug 8, 2024
1 parent cb2dedb commit 8f2c8a8
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
21 changes: 21 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ def wheelhouse(tmp_path_factory, pip_cache):
ignore=shutil.ignore_patterns("tests*"),
dirs_exist_ok=True,
)
shutil.copytree(
DIR / "tests/rapids-test-dummy",
rapids_build_backend_build_dir / "tests/rapids-test-dummy",
dirs_exist_ok=True,
)

pyproject_file = rapids_build_backend_build_dir / "pyproject.toml"
with open(pyproject_file) as f:
Expand Down Expand Up @@ -203,6 +208,22 @@ def wheelhouse(tmp_path_factory, pip_cache):
check=True,
)

subprocess.run(
[
sys.executable,
"-m",
"pip",
"wheel",
"--disable-pip-version-check",
"--wheel-dir",
str(wheelhouse),
"--cache-dir",
pip_cache,
f"{rapids_build_backend_build_dir}/tests/rapids-test-dummy",
],
check=True,
)

return wheelhouse


Expand Down
5 changes: 5 additions & 0 deletions tests/rapids-test-dummy/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (c) 2024, NVIDIA CORPORATION.

[project]
name = "rapids-test-dummy"
version = "0.0.1"
3 changes: 3 additions & 0 deletions tests/rapids-test-dummy/rapids_test_dummy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (c) 2024, NVIDIA CORPORATION.

__version__ = "0.0.1"
2 changes: 1 addition & 1 deletion tests/templates/dependencies-rbb-only.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dependencies:
matrices:
- matrix: {cuda: "85.*"}
packages:
- more-itertools
- rapids-test-dummy
# keeping this empty means it'll only be filled in if
# rapids-build-backend actually resolves one of the CUDA-specific
# matrices
Expand Down
28 changes: 17 additions & 11 deletions tests/test_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import glob
import os
import re
import subprocess
import zipfile
from email.parser import BytesParser
Expand Down Expand Up @@ -29,6 +30,10 @@ def _generate_wheel(env, package_dir):
break
if "Collecting" in line:
build_requires.add(line.replace("Collecting ", "").replace(" ", ""))
elif re.search(
r"Processing .*/rapids_test_dummy-0\.0\.1-py3-none-any\.whl$", line
):
build_requires.add("rapids-test-dummy")

# Extract metadata from the wheel file.
wheel = glob.glob(str(package_dir / "*.whl"))[0]
Expand Down Expand Up @@ -101,9 +106,9 @@ def test_setuptools_with_imports_in_setup_py_works(
"dependencies-file": '"dependencies-rbb-only.yaml"',
},
"setup_py_lines": [
"import more_itertools",
"import rapids_test_dummy",
"",
"print(more_itertools.__version__)",
"print(rapids_test_dummy.__version__)",
"",
"setup()",
],
Expand All @@ -118,7 +123,7 @@ def test_setuptools_with_imports_in_setup_py_works(
)

assert name == "setuptools-with-imports-in-setup-py-cu85"
assert {"more-itertools"}.issubset(build_requires)
assert {"rapids-test-dummy"}.issubset(build_requires)
assert requirements == set()


Expand All @@ -137,9 +142,9 @@ def test_setuptools_with_imports_in_setup_py_fails_on_missing_imports(
"dependencies-file": '"dependencies-rbb-only.yaml"',
},
"setup_py_lines": [
"import more_itertools",
"import rapids_test_dummy",
"",
"print(more_itertools.__version__)",
"print(rapids_test_dummy.__version__)",
"",
"setup()",
],
Expand All @@ -149,20 +154,21 @@ def test_setuptools_with_imports_in_setup_py_fails_on_missing_imports(
generate_from_template(package_dir, "setup.py", template_args)

# only the CUDA '85.*' in this example provides required build dependency
# 'more-itertools', so it won't be found if using some other matrix.
# 'rapids-test-dummy', so it won't be found if using some other matrix.
#
# This test confirms that rapids-build-backend fails loudly in that case, instead of
# silently ignoring it.
#
# It'd also catch the case where other tests accidentally pass because
# 'more-itertools' already existed in the environment where tests run.
# 'rapids-test-dummy' already existed in the environment where tests run.
with patch_nvcc_if_needed(nvcc_version="25"):
with pytest.raises(subprocess.CalledProcessError, match=".*pip.*"):
_generate_wheel(env=isolated_env, package_dir=package_dir)

captured_output = capfd.readouterr()
assert (
"ModuleNotFoundError: No module named 'more_itertools'" in captured_output.out
"ModuleNotFoundError: No module named 'rapids_test_dummy'"
in captured_output.out
)


Expand All @@ -180,12 +186,12 @@ def test_setuptools_with_setup_requires_fails_with_informative_error(
"dependencies-file": '"dependencies-rbb-only.yaml"',
},
"setup_py_lines": [
"import more_itertools",
"import rapids_test_dummy",
"",
"print(more_itertools.__version__)",
"print(rapids_test_dummy.__version__)",
"",
"setup(",
" setup_requires=['more-itertools'],",
" setup_requires=['rapids-test-dummy'],",
")",
],
}
Expand Down

0 comments on commit 8f2c8a8

Please sign in to comment.