summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamara Dahlgren <35777542+tldahlgren@users.noreply.github.com>2023-06-30 02:52:42 -0700
committerGitHub <noreply@github.com>2023-06-30 05:52:42 -0400
commitdc25da1931d3fbebb64f35d37b1498f00d17141f (patch)
tree7688b068c20e76b62a75df3db145f0b602f773ab
parent067e40591ad7d6713a410d19af9e97963440e239 (diff)
downloadspack-dc25da1931d3fbebb64f35d37b1498f00d17141f.tar.gz
spack-dc25da1931d3fbebb64f35d37b1498f00d17141f.tar.bz2
spack-dc25da1931d3fbebb64f35d37b1498f00d17141f.tar.xz
spack-dc25da1931d3fbebb64f35d37b1498f00d17141f.zip
tests/pythons: convert to new stand-alone test process (#38340)
-rw-r--r--lib/spack/spack/build_systems/python.py15
-rw-r--r--var/spack/repos/builtin/packages/python/package.py25
2 files changed, 21 insertions, 19 deletions
diff --git a/lib/spack/spack/build_systems/python.py b/lib/spack/spack/build_systems/python.py
index f365fefe0f..7a355490f7 100644
--- a/lib/spack/spack/build_systems/python.py
+++ b/lib/spack/spack/build_systems/python.py
@@ -23,6 +23,7 @@ import spack.spec
import spack.store
from spack.directives import build_system, depends_on, extends, maintainers
from spack.error import NoHeadersError, NoLibrariesError, SpecError
+from spack.install_test import test_part
from spack.version import Version
from ._checks import BaseBuilder, execute_install_time_tests
@@ -167,18 +168,20 @@ class PythonExtension(spack.package_base.PackageBase):
view.remove_files(to_remove)
- def test(self):
+ def test_imports(self):
"""Attempts to import modules of the installed package."""
# Make sure we are importing the installed modules,
# not the ones in the source directory
+ python = inspect.getmodule(self).python.path
for module in self.import_modules:
- self.run_test(
- inspect.getmodule(self).python.path,
- ["-c", "import {0}".format(module)],
- purpose="checking import of {0}".format(module),
+ with test_part(
+ self,
+ f"test_imports_{module}",
+ purpose=f"checking import of {module}",
work_dir="spack-test",
- )
+ ):
+ python("-c", f"import {module}")
def update_external_dependencies(self, extendee_spec=None):
"""
diff --git a/var/spack/repos/builtin/packages/python/package.py b/var/spack/repos/builtin/packages/python/package.py
index f2c9c5945e..7029a7f99d 100644
--- a/var/spack/repos/builtin/packages/python/package.py
+++ b/var/spack/repos/builtin/packages/python/package.py
@@ -1195,19 +1195,18 @@ print(json.dumps(config))
else:
os.remove(dst)
- def test(self):
+ def test_hello_world(self):
+ """run simple hello world program"""
# do not use self.command because we are also testing the run env
- exe = self.spec["python"].command.name
+ python = self.spec["python"].command
- # test hello world
msg = "hello world!"
- reason = "test: running {0}".format(msg)
- options = ["-c", 'print("{0}")'.format(msg)]
- self.run_test(exe, options=options, expected=[msg], installed=True, purpose=reason)
-
- # checks import works and executable comes from the spec prefix
- reason = "test: checking import and executable"
- options = ["-c", "import sys; print(sys.executable)"]
- self.run_test(
- exe, options=options, expected=[self.spec.prefix], installed=True, purpose=reason
- )
+ out = python("-c", f'print("{msg}")', output=str.split, error=str.split)
+ assert msg in out
+
+ def test_import_executable(self):
+ """ensure import of installed executable works"""
+ python = self.spec["python"].command
+
+ out = python("-c", "import sys; print(sys.executable)", output=str.split, error=str.split)
+ assert self.spec.prefix in out