summaryrefslogtreecommitdiff
path: root/lib/spack/spack/test/multimethod.py
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2022-07-30 15:19:18 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2022-07-31 13:29:20 -0700
commitf52f6e99dbf1131886a80112b8c79dfc414afb7c (patch)
tree05cb7d64b2395922f2f24683da49f472075be12c /lib/spack/spack/test/multimethod.py
parent549ba1ed32372c67fc57271cde3797d58b7dec6e (diff)
downloadspack-f52f6e99dbf1131886a80112b8c79dfc414afb7c.tar.gz
spack-f52f6e99dbf1131886a80112b8c79dfc414afb7c.tar.bz2
spack-f52f6e99dbf1131886a80112b8c79dfc414afb7c.tar.xz
spack-f52f6e99dbf1131886a80112b8c79dfc414afb7c.zip
black: reformat entire repository with black
Diffstat (limited to 'lib/spack/spack/test/multimethod.py')
-rw-r--r--lib/spack/spack/test/multimethod.py121
1 files changed, 63 insertions, 58 deletions
diff --git a/lib/spack/spack/test/multimethod.py b/lib/spack/spack/test/multimethod.py
index 1e0cee71c7..8f3ddaf8cc 100644
--- a/lib/spack/spack/test/multimethod.py
+++ b/lib/spack/spack/test/multimethod.py
@@ -15,16 +15,15 @@ import spack.spec
from spack.multimethod import NoSuchMethodError
pytestmark = [
- pytest.mark.usefixtures('mock_packages', 'config'),
+ pytest.mark.usefixtures("mock_packages", "config"),
pytest.mark.skipif(
- os.environ.get('SPACK_TEST_SOLVER') == 'original' or sys.platform == 'win32',
- reason='The original concretizer cannot concretize most of the specs'
- )
+ os.environ.get("SPACK_TEST_SOLVER") == "original" or sys.platform == "win32",
+ reason="The original concretizer cannot concretize most of the specs",
+ ),
]
-@pytest.fixture(scope='module',
- params=['multimethod', 'multimethod-inheritor'])
+@pytest.fixture(scope="module", params=["multimethod", "multimethod-inheritor"])
def pkg_name(request):
"""Make tests run on both multimethod and multimethod-inheritor.
@@ -35,42 +34,45 @@ def pkg_name(request):
def test_no_version_match(pkg_name):
- spec = spack.spec.Spec(pkg_name + '@2.0').concretized()
+ spec = spack.spec.Spec(pkg_name + "@2.0").concretized()
with pytest.raises(NoSuchMethodError):
spec.package.no_version_2()
-@pytest.mark.parametrize('constraint_str,method_name,expected_result', [
- # Only one version match these constraints
- ('@1.0', 'no_version_2', 1),
- ('@3.0', 'no_version_2', 3),
- ('@4.0', 'no_version_2', 4),
- # These constraints overlap, in which case the first match wins
- ('@2.0', 'version_overlap', 1),
- ('@5.0', 'version_overlap', 2),
- # These constraints are on the version of a virtual dependency
- ('^mpich@3.0.4', 'mpi_version', 3),
- ('^mpich2@1.2', 'mpi_version', 2),
- ('^mpich@1.0', 'mpi_version', 1),
- # Undefined mpi versions
- ('^mpich@0.4', 'mpi_version', 1),
- ('^mpich@1.4', 'mpi_version', 1),
- # Constraints on compilers with a default
- ('%gcc', 'has_a_default', 'gcc'),
- ('%clang', 'has_a_default', 'clang'),
- ('%apple-clang os=elcapitan', 'has_a_default', 'default'),
- # Constraints on dependencies
- ('^zmpi', 'different_by_dep', 'zmpi'),
- ('^mpich', 'different_by_dep', 'mpich'),
- # Constraints on virtual dependencies
- ('^mpich2', 'different_by_virtual_dep', 2),
- ('^mpich@1.0', 'different_by_virtual_dep', 1),
- # Multimethod with base classes
- ('@1', 'base_method', 'base_method'),
- # Boolean
- ('', 'boolean_true_first', 'True'),
- ('', 'boolean_false_first', 'True')
-])
+@pytest.mark.parametrize(
+ "constraint_str,method_name,expected_result",
+ [
+ # Only one version match these constraints
+ ("@1.0", "no_version_2", 1),
+ ("@3.0", "no_version_2", 3),
+ ("@4.0", "no_version_2", 4),
+ # These constraints overlap, in which case the first match wins
+ ("@2.0", "version_overlap", 1),
+ ("@5.0", "version_overlap", 2),
+ # These constraints are on the version of a virtual dependency
+ ("^mpich@3.0.4", "mpi_version", 3),
+ ("^mpich2@1.2", "mpi_version", 2),
+ ("^mpich@1.0", "mpi_version", 1),
+ # Undefined mpi versions
+ ("^mpich@0.4", "mpi_version", 1),
+ ("^mpich@1.4", "mpi_version", 1),
+ # Constraints on compilers with a default
+ ("%gcc", "has_a_default", "gcc"),
+ ("%clang", "has_a_default", "clang"),
+ ("%apple-clang os=elcapitan", "has_a_default", "default"),
+ # Constraints on dependencies
+ ("^zmpi", "different_by_dep", "zmpi"),
+ ("^mpich", "different_by_dep", "mpich"),
+ # Constraints on virtual dependencies
+ ("^mpich2", "different_by_virtual_dep", 2),
+ ("^mpich@1.0", "different_by_virtual_dep", 1),
+ # Multimethod with base classes
+ ("@1", "base_method", "base_method"),
+ # Boolean
+ ("", "boolean_true_first", "True"),
+ ("", "boolean_false_first", "True"),
+ ],
+)
def test_multimethod_calls(pkg_name, constraint_str, method_name, expected_result):
s = spack.spec.Spec(pkg_name + constraint_str).concretized()
msg = "Method {0} from {1} is giving a wrong result".format(method_name, s)
@@ -81,10 +83,10 @@ def test_target_match(pkg_name):
platform = spack.platforms.host()
targets = list(platform.targets.values())
for target in targets[:-1]:
- s = spack.spec.Spec(pkg_name + ' target=' + target.name).concretized()
+ s = spack.spec.Spec(pkg_name + " target=" + target.name).concretized()
assert s.package.different_by_target() == target.name
- s = spack.spec.Spec(pkg_name + ' target=' + targets[-1].name).concretized()
+ s = spack.spec.Spec(pkg_name + " target=" + targets[-1].name).concretized()
if len(targets) == 1:
assert s.package.different_by_target() == targets[-1].name
else:
@@ -92,24 +94,27 @@ def test_target_match(pkg_name):
s.package.different_by_target()
-@pytest.mark.parametrize('spec_str,method_name,expected_result', [
- # This is overridden in the second case
- ('multimethod@3', 'base_method', 'multimethod'),
- ('multimethod-inheritor@3', 'base_method', 'multimethod-inheritor'),
- # Here we have a mix of inherited and overridden methods
- ('multimethod-inheritor@1.0', 'inherited_and_overridden', 'inheritor@1.0'),
- ('multimethod-inheritor@2.0', 'inherited_and_overridden', 'base@2.0'),
- ('multimethod@1.0', 'inherited_and_overridden', 'base@1.0'),
- ('multimethod@2.0', 'inherited_and_overridden', 'base@2.0'),
- # Diamond-like inheritance (even though the MRO linearize everything)
- ('multimethod-diamond@1.0', 'diamond_inheritance', 'base_package'),
- ('multimethod-base@1.0', 'diamond_inheritance', 'base_package'),
- ('multimethod-diamond@2.0', 'diamond_inheritance', 'first_parent'),
- ('multimethod-inheritor@2.0', 'diamond_inheritance', 'first_parent'),
- ('multimethod-diamond@3.0', 'diamond_inheritance', 'second_parent'),
- ('multimethod-diamond-parent@3.0', 'diamond_inheritance', 'second_parent'),
- ('multimethod-diamond@4.0', 'diamond_inheritance', 'subclass'),
-])
+@pytest.mark.parametrize(
+ "spec_str,method_name,expected_result",
+ [
+ # This is overridden in the second case
+ ("multimethod@3", "base_method", "multimethod"),
+ ("multimethod-inheritor@3", "base_method", "multimethod-inheritor"),
+ # Here we have a mix of inherited and overridden methods
+ ("multimethod-inheritor@1.0", "inherited_and_overridden", "inheritor@1.0"),
+ ("multimethod-inheritor@2.0", "inherited_and_overridden", "base@2.0"),
+ ("multimethod@1.0", "inherited_and_overridden", "base@1.0"),
+ ("multimethod@2.0", "inherited_and_overridden", "base@2.0"),
+ # Diamond-like inheritance (even though the MRO linearize everything)
+ ("multimethod-diamond@1.0", "diamond_inheritance", "base_package"),
+ ("multimethod-base@1.0", "diamond_inheritance", "base_package"),
+ ("multimethod-diamond@2.0", "diamond_inheritance", "first_parent"),
+ ("multimethod-inheritor@2.0", "diamond_inheritance", "first_parent"),
+ ("multimethod-diamond@3.0", "diamond_inheritance", "second_parent"),
+ ("multimethod-diamond-parent@3.0", "diamond_inheritance", "second_parent"),
+ ("multimethod-diamond@4.0", "diamond_inheritance", "subclass"),
+ ],
+)
def test_multimethod_calls_and_inheritance(spec_str, method_name, expected_result):
s = spack.spec.Spec(spec_str).concretized()
assert getattr(s.package, method_name)() == expected_result