tests/pythons: convert to new stand-alone test process (#38340)

This commit is contained in:
Tamara Dahlgren 2023-06-30 02:52:42 -07:00 committed by GitHub
parent 067e40591a
commit dc25da1931
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 18 deletions

View File

@ -23,6 +23,7 @@
import spack.store import spack.store
from spack.directives import build_system, depends_on, extends, maintainers from spack.directives import build_system, depends_on, extends, maintainers
from spack.error import NoHeadersError, NoLibrariesError, SpecError from spack.error import NoHeadersError, NoLibrariesError, SpecError
from spack.install_test import test_part
from spack.version import Version from spack.version import Version
from ._checks import BaseBuilder, execute_install_time_tests from ._checks import BaseBuilder, execute_install_time_tests
@ -167,18 +168,20 @@ def remove_files_from_view(self, view, merge_map):
view.remove_files(to_remove) view.remove_files(to_remove)
def test(self): def test_imports(self):
"""Attempts to import modules of the installed package.""" """Attempts to import modules of the installed package."""
# Make sure we are importing the installed modules, # Make sure we are importing the installed modules,
# not the ones in the source directory # not the ones in the source directory
python = inspect.getmodule(self).python.path
for module in self.import_modules: for module in self.import_modules:
self.run_test( with test_part(
inspect.getmodule(self).python.path, self,
["-c", "import {0}".format(module)], f"test_imports_{module}",
purpose="checking import of {0}".format(module), purpose=f"checking import of {module}",
work_dir="spack-test", work_dir="spack-test",
) ):
python("-c", f"import {module}")
def update_external_dependencies(self, extendee_spec=None): def update_external_dependencies(self, extendee_spec=None):
""" """

View File

@ -1195,19 +1195,18 @@ def remove_files_from_view(self, view, merge_map):
else: else:
os.remove(dst) 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 # 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!" msg = "hello world!"
reason = "test: running {0}".format(msg) out = python("-c", f'print("{msg}")', output=str.split, error=str.split)
options = ["-c", 'print("{0}")'.format(msg)] assert msg in out
self.run_test(exe, options=options, expected=[msg], installed=True, purpose=reason)
# checks import works and executable comes from the spec prefix def test_import_executable(self):
reason = "test: checking import and executable" """ensure import of installed executable works"""
options = ["-c", "import sys; print(sys.executable)"] python = self.spec["python"].command
self.run_test(
exe, options=options, expected=[self.spec.prefix], installed=True, purpose=reason out = python("-c", "import sys; print(sys.executable)", output=str.split, error=str.split)
) assert self.spec.prefix in out