refactor run_test to Package level
This commit is contained in:

committed by
Tamara Dahlgren

parent
dd0fbe670c
commit
ce06e24a2e
@@ -55,7 +55,7 @@
|
|||||||
from spack.filesystem_view import YamlFilesystemView
|
from spack.filesystem_view import YamlFilesystemView
|
||||||
from spack.installer import \
|
from spack.installer import \
|
||||||
install_args_docstring, PackageInstaller, InstallError
|
install_args_docstring, PackageInstaller, InstallError
|
||||||
from spack.util.executable import which
|
from spack.util.executable import which, ProcessError
|
||||||
from spack.util.prefix import Prefix
|
from spack.util.prefix import Prefix
|
||||||
from spack.stage import stage_prefix, Stage, ResourceStage, StageComposite
|
from spack.stage import stage_prefix, Stage, ResourceStage, StageComposite
|
||||||
from spack.util.package_hash import package_hash
|
from spack.util.package_hash import package_hash
|
||||||
@@ -1674,6 +1674,34 @@ def test_process():
|
|||||||
def test(self):
|
def test(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def run_test(self, exe, options, expected, status):
|
||||||
|
"""Run the test and confirm obtain the expected results
|
||||||
|
|
||||||
|
Args:
|
||||||
|
exe (str): the name of the executable
|
||||||
|
options (list of str): list of options to pass to the runner
|
||||||
|
expected (list of str): list of expected output strings
|
||||||
|
status (int or None): the expected process status if int or None
|
||||||
|
if the test is expected to succeed
|
||||||
|
"""
|
||||||
|
result = 'fail with status {0}'.format(status) if status else 'succeed'
|
||||||
|
tty.debug('test: {0}: expect to {1}'.format(exe, result))
|
||||||
|
runner = which(exe)
|
||||||
|
assert runner is not None
|
||||||
|
|
||||||
|
try:
|
||||||
|
output = runner(*options, output=str.split, error=str.split)
|
||||||
|
assert not status, 'Expected execution to fail'
|
||||||
|
except ProcessError as err:
|
||||||
|
output = str(err)
|
||||||
|
status_msg = 'exited with status {0}'.format(status)
|
||||||
|
expected_msg = 'Expected \'{0}\' in \'{1}\''.format(
|
||||||
|
status_msg, err.message)
|
||||||
|
assert status_msg in output, expected_msg
|
||||||
|
|
||||||
|
for check in expected:
|
||||||
|
assert check in output
|
||||||
|
|
||||||
def unit_test_check(self):
|
def unit_test_check(self):
|
||||||
"""Hook for unit tests to assert things about package internals.
|
"""Hook for unit tests to assert things about package internals.
|
||||||
|
|
||||||
|
@@ -74,34 +74,6 @@ def import_module_test(self):
|
|||||||
with working_dir('spack-test', create=True):
|
with working_dir('spack-test', create=True):
|
||||||
python('-c', 'import libxml2')
|
python('-c', 'import libxml2')
|
||||||
|
|
||||||
def _run_test(self, exe, options, expected, status):
|
|
||||||
"""Run the test and confirm obtain the expected results
|
|
||||||
|
|
||||||
Args:
|
|
||||||
exe (str): the name of the executable
|
|
||||||
options (list of str): list of options to pass to the runner
|
|
||||||
expected (list of str): list of expected output strings
|
|
||||||
status (int or None): the expected process status if int or None
|
|
||||||
if the test is expected to succeed
|
|
||||||
"""
|
|
||||||
result = 'fail with status {0}'.format(status) if status else 'succeed'
|
|
||||||
tty.msg('test: {0}: expect to {1}'.format(exe, result))
|
|
||||||
runner = which(exe)
|
|
||||||
assert runner is not None
|
|
||||||
|
|
||||||
try:
|
|
||||||
output = runner(*options, output=str.split, error=str.split)
|
|
||||||
assert not status, 'Expected execution to fail'
|
|
||||||
except ProcessError as err:
|
|
||||||
output = str(err)
|
|
||||||
status_msg = 'exited with status {0}'.format(status)
|
|
||||||
expected_msg = 'Expected \'{0}\' in \'{1}\''.format(
|
|
||||||
status_msg, err.message)
|
|
||||||
assert status_msg in output, expected_msg
|
|
||||||
|
|
||||||
for check in expected:
|
|
||||||
assert check in output
|
|
||||||
|
|
||||||
def test(self):
|
def test(self):
|
||||||
"""Perform smoke tests on the installed package"""
|
"""Perform smoke tests on the installed package"""
|
||||||
# Start with what we already have post-install
|
# Start with what we already have post-install
|
||||||
@@ -129,7 +101,7 @@ def test(self):
|
|||||||
}
|
}
|
||||||
for exe in exec_checks:
|
for exe in exec_checks:
|
||||||
for options, expected, status in exec_checks[exe]:
|
for options, expected, status in exec_checks[exe]:
|
||||||
self._run_test(exe, options, expected, status)
|
self.run_test(exe, options, expected, status)
|
||||||
|
|
||||||
# Perform some cleanup
|
# Perform some cleanup
|
||||||
fs.force_remove(test_fn)
|
fs.force_remove(test_fn)
|
||||||
|
Reference in New Issue
Block a user