diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2018-12-05 10:36:16 -0600 |
---|---|---|
committer | Greg Becker <becker33@llnl.gov> | 2018-12-06 15:48:23 -0800 |
commit | 43d94d4a3033fe758b922a395a1b4b879b296817 (patch) | |
tree | ecc95c2918f818672088b9713de924f3d8ab2ed9 /lib/spack | |
parent | 61b859193db23b81860b7d4bcc219db3aa56ddec (diff) | |
download | spack-43d94d4a3033fe758b922a395a1b4b879b296817.tar.gz spack-43d94d4a3033fe758b922a395a1b4b879b296817.tar.bz2 spack-43d94d4a3033fe758b922a395a1b4b879b296817.tar.xz spack-43d94d4a3033fe758b922a395a1b4b879b296817.zip |
tests: fully parametrize multimethod test
- all multimethod tests are now run for both `multimethod` and
`multimethod-inheritor`
- do this with a parameterized fixture (pkg_name) that runs the same
tests on both
Diffstat (limited to 'lib/spack')
-rw-r--r-- | lib/spack/spack/test/multimethod.py | 84 |
1 files changed, 47 insertions, 37 deletions
diff --git a/lib/spack/spack/test/multimethod.py b/lib/spack/spack/test/multimethod.py index 2780c57fc5..b475b3ae93 100644 --- a/lib/spack/spack/test/multimethod.py +++ b/lib/spack/spack/test/multimethod.py @@ -10,69 +10,83 @@ import spack.repo from spack.multimethod import NoSuchMethodError -def test_no_version_match(mock_packages): - pkg = spack.repo.get('multimethod@2.0') +pytestmark = pytest.mark.usefixtures('mock_packages') + + +@pytest.fixture(scope='module', + params=['multimethod', 'multimethod-inheritor']) +def pkg_name(request): + """Make tests run on both multimethod and multimethod-inheritor. + + This means we test all of our @when methods on a class that uses them + directly, AND on a class that inherits them. + """ + return request.param + + +def test_no_version_match(pkg_name): + pkg = spack.repo.get(pkg_name + '@2.0') with pytest.raises(NoSuchMethodError): pkg.no_version_2() -def test_one_version_match(mock_packages): - pkg = spack.repo.get('multimethod@1.0') +def test_one_version_match(pkg_name): + pkg = spack.repo.get(pkg_name + '@1.0') assert pkg.no_version_2() == 1 - pkg = spack.repo.get('multimethod@3.0') + pkg = spack.repo.get(pkg_name + '@3.0') assert pkg.no_version_2() == 3 - pkg = spack.repo.get('multimethod@4.0') + pkg = spack.repo.get(pkg_name + '@4.0') assert pkg.no_version_2() == 4 -def test_version_overlap(mock_packages): - pkg = spack.repo.get('multimethod@2.0') +def test_version_overlap(pkg_name): + pkg = spack.repo.get(pkg_name + '@2.0') assert pkg.version_overlap() == 1 - pkg = spack.repo.get('multimethod@5.0') + pkg = spack.repo.get(pkg_name + '@5.0') assert pkg.version_overlap() == 2 -def test_mpi_version(mock_packages): - pkg = spack.repo.get('multimethod^mpich@3.0.4') +def test_mpi_version(pkg_name): + pkg = spack.repo.get(pkg_name + '^mpich@3.0.4') assert pkg.mpi_version() == 3 - pkg = spack.repo.get('multimethod^mpich2@1.2') + pkg = spack.repo.get(pkg_name + '^mpich2@1.2') assert pkg.mpi_version() == 2 - pkg = spack.repo.get('multimethod^mpich@1.0') + pkg = spack.repo.get(pkg_name + '^mpich@1.0') assert pkg.mpi_version() == 1 -def test_undefined_mpi_version(mock_packages): - pkg = spack.repo.get('multimethod^mpich@0.4') +def test_undefined_mpi_version(pkg_name): + pkg = spack.repo.get(pkg_name + '^mpich@0.4') assert pkg.mpi_version() == 1 - pkg = spack.repo.get('multimethod^mpich@1.4') + pkg = spack.repo.get(pkg_name + '^mpich@1.4') assert pkg.mpi_version() == 1 -def test_default_works(mock_packages): - pkg = spack.repo.get('multimethod%gcc') +def test_default_works(pkg_name): + pkg = spack.repo.get(pkg_name + '%gcc') assert pkg.has_a_default() == 'gcc' - pkg = spack.repo.get('multimethod%intel') + pkg = spack.repo.get(pkg_name + '%intel') assert pkg.has_a_default() == 'intel' - pkg = spack.repo.get('multimethod%pgi') + pkg = spack.repo.get(pkg_name + '%pgi') assert pkg.has_a_default() == 'default' -def test_target_match(mock_packages): +def test_target_match(pkg_name): platform = spack.architecture.platform() targets = list(platform.targets.values()) for target in targets[:-1]: - pkg = spack.repo.get('multimethod target=' + target.name) + pkg = spack.repo.get(pkg_name + ' target=' + target.name) assert pkg.different_by_target() == target.name - pkg = spack.repo.get('multimethod target=' + targets[-1].name) + pkg = spack.repo.get(pkg_name + ' target=' + targets[-1].name) if len(targets) == 1: assert pkg.different_by_target() == targets[-1].name else: @@ -80,34 +94,30 @@ def test_target_match(mock_packages): pkg.different_by_target() -def test_dependency_match(mock_packages): - pkg = spack.repo.get('multimethod^zmpi') +def test_dependency_match(pkg_name): + pkg = spack.repo.get(pkg_name + '^zmpi') assert pkg.different_by_dep() == 'zmpi' - pkg = spack.repo.get('multimethod^mpich') + pkg = spack.repo.get(pkg_name + '^mpich') assert pkg.different_by_dep() == 'mpich' # If we try to switch on some entirely different dep, it's ambiguous, # but should take the first option - pkg = spack.repo.get('multimethod^foobar') + pkg = spack.repo.get(pkg_name + '^foobar') assert pkg.different_by_dep() == 'mpich' -def test_virtual_dep_match(mock_packages): - pkg = spack.repo.get('multimethod^mpich2') +def test_virtual_dep_match(pkg_name): + pkg = spack.repo.get(pkg_name + '^mpich2') assert pkg.different_by_virtual_dep() == 2 - pkg = spack.repo.get('multimethod^mpich@1.0') + pkg = spack.repo.get(pkg_name + '^mpich@1.0') assert pkg.different_by_virtual_dep() == 1 -def test_multimethod_with_base_class(mock_packages): - pkg = spack.repo.get('multimethod@3') +def test_multimethod_with_base_class(pkg_name): + pkg = spack.repo.get(pkg_name + '@3') assert pkg.base_method() == "subclass_method" - pkg = spack.repo.get('multimethod@1') + pkg = spack.repo.get(pkg_name + '@1') assert pkg.base_method() == "base_method" - -def test_multimethod_inheritance(mock_packages): - pkg = spack.repo.get('multimethod-inheritor@1.0') - assert pkg.no_version_2() == 1 |