Tests: move has_test_method to spack.package (#28813)
This commit is contained in:
parent
634cba930e
commit
36ef59bc67
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import inspect
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
@ -207,24 +206,13 @@ def test_run(args):
|
|||||||
fail_first=args.fail_first)
|
fail_first=args.fail_first)
|
||||||
|
|
||||||
|
|
||||||
def has_test_method(pkg):
|
|
||||||
if not inspect.isclass(pkg):
|
|
||||||
tty.die('{0}: is not a class, it is {1}'.format(pkg, type(pkg)))
|
|
||||||
|
|
||||||
pkg_base = spack.package.PackageBase
|
|
||||||
return (
|
|
||||||
(issubclass(pkg, pkg_base) and pkg.test != pkg_base.test) or
|
|
||||||
(isinstance(pkg, pkg_base) and pkg.test.__func__ != pkg_base.test)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_list(args):
|
def test_list(args):
|
||||||
"""List installed packages with available tests."""
|
"""List installed packages with available tests."""
|
||||||
tagged = set(spack.repo.path.packages_with_tags(*args.tag)) if args.tag \
|
tagged = set(spack.repo.path.packages_with_tags(*args.tag)) if args.tag \
|
||||||
else set()
|
else set()
|
||||||
|
|
||||||
def has_test_and_tags(pkg_class):
|
def has_test_and_tags(pkg_class):
|
||||||
return has_test_method(pkg_class) and \
|
return spack.package.has_test_method(pkg_class) and \
|
||||||
(not args.tag or pkg_class.name in tagged)
|
(not args.tag or pkg_class.name in tagged)
|
||||||
|
|
||||||
if args.list_all:
|
if args.list_all:
|
||||||
|
@ -2618,6 +2618,17 @@ def _run_default_install_time_test_callbacks(self):
|
|||||||
fn()
|
fn()
|
||||||
|
|
||||||
|
|
||||||
|
def has_test_method(pkg):
|
||||||
|
"""Returns True if the package defines its own stand-alone test method."""
|
||||||
|
if not inspect.isclass(pkg):
|
||||||
|
tty.die('{0}: is not a class, it is {1}'.format(pkg, type(pkg)))
|
||||||
|
|
||||||
|
return (
|
||||||
|
(issubclass(pkg, PackageBase) and pkg.test != PackageBase.test) or
|
||||||
|
(isinstance(pkg, PackageBase) and pkg.test.__func__ != PackageBase.test)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_process(pkg, kwargs):
|
def test_process(pkg, kwargs):
|
||||||
with tty.log.log_output(pkg.test_log_file) as logger:
|
with tty.log.log_output(pkg.test_log_file) as logger:
|
||||||
with logger.force_echo():
|
with logger.force_echo():
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
import spack.config
|
import spack.config
|
||||||
import spack.package
|
import spack.package
|
||||||
import spack.store
|
import spack.store
|
||||||
from spack.cmd.test import has_test_method
|
|
||||||
from spack.main import SpackCommand
|
from spack.main import SpackCommand
|
||||||
|
|
||||||
install = SpackCommand('install')
|
install = SpackCommand('install')
|
||||||
@ -226,14 +225,6 @@ def test_test_list(
|
|||||||
assert pkg_with_tests in output
|
assert pkg_with_tests in output
|
||||||
|
|
||||||
|
|
||||||
def test_has_test_method_fails(capsys):
|
|
||||||
with pytest.raises(SystemExit):
|
|
||||||
has_test_method('printing-package')
|
|
||||||
|
|
||||||
captured = capsys.readouterr()[1]
|
|
||||||
assert 'is not a class' in captured
|
|
||||||
|
|
||||||
|
|
||||||
def test_hash_change(mock_test_stage, mock_packages, mock_archive, mock_fetch,
|
def test_hash_change(mock_test_stage, mock_packages, mock_archive, mock_fetch,
|
||||||
install_mockery_mutable_config):
|
install_mockery_mutable_config):
|
||||||
"""Ensure output printed from pkgs is captured by output redirection."""
|
"""Ensure output printed from pkgs is captured by output redirection."""
|
||||||
|
@ -373,3 +373,11 @@ def test_fetch_options(mock_packages, config):
|
|||||||
assert isinstance(fetcher, spack.fetch_strategy.URLFetchStrategy)
|
assert isinstance(fetcher, spack.fetch_strategy.URLFetchStrategy)
|
||||||
assert fetcher.digest == '00000000000000000000000000000012'
|
assert fetcher.digest == '00000000000000000000000000000012'
|
||||||
assert fetcher.extra_options == {'cookie': 'baz'}
|
assert fetcher.extra_options == {'cookie': 'baz'}
|
||||||
|
|
||||||
|
|
||||||
|
def test_has_test_method_fails(capsys):
|
||||||
|
with pytest.raises(SystemExit):
|
||||||
|
spack.package.has_test_method('printing-package')
|
||||||
|
|
||||||
|
captured = capsys.readouterr()[1]
|
||||||
|
assert 'is not a class' in captured
|
||||||
|
Loading…
Reference in New Issue
Block a user