summaryrefslogtreecommitdiff
path: root/lib/spack/spack/test/multimethod.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/spack/spack/test/multimethod.py')
-rw-r--r--lib/spack/spack/test/multimethod.py134
1 files changed, 70 insertions, 64 deletions
diff --git a/lib/spack/spack/test/multimethod.py b/lib/spack/spack/test/multimethod.py
index a885374080..90948f010c 100644
--- a/lib/spack/spack/test/multimethod.py
+++ b/lib/spack/spack/test/multimethod.py
@@ -22,93 +22,99 @@
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
-"""
-Test for multi_method dispatch.
-"""
+"""Test for multi_method dispatch."""
import spack
+import pytest
from spack.multimethod import *
from spack.version import *
-from spack.test.mock_packages_test import *
-class MultiMethodTest(MockPackagesTest):
+def test_no_version_match(builtin_mock):
+ pkg = spack.repo.get('multimethod@2.0')
+ with pytest.raises(NoSuchMethodError):
+ pkg.no_version_2()
- def test_no_version_match(self):
- pkg = spack.repo.get('multimethod@2.0')
- self.assertRaises(NoSuchMethodError, pkg.no_version_2)
- def test_one_version_match(self):
- pkg = spack.repo.get('multimethod@1.0')
- self.assertEqual(pkg.no_version_2(), 1)
+def test_one_version_match(builtin_mock):
+ pkg = spack.repo.get('multimethod@1.0')
+ assert pkg.no_version_2() == 1
- pkg = spack.repo.get('multimethod@3.0')
- self.assertEqual(pkg.no_version_2(), 3)
+ pkg = spack.repo.get('multimethod@3.0')
+ assert pkg.no_version_2() == 3
- pkg = spack.repo.get('multimethod@4.0')
- self.assertEqual(pkg.no_version_2(), 4)
+ pkg = spack.repo.get('multimethod@4.0')
+ assert pkg.no_version_2() == 4
- def test_version_overlap(self):
- pkg = spack.repo.get('multimethod@2.0')
- self.assertEqual(pkg.version_overlap(), 1)
- pkg = spack.repo.get('multimethod@5.0')
- self.assertEqual(pkg.version_overlap(), 2)
+def test_version_overlap(builtin_mock):
+ pkg = spack.repo.get('multimethod@2.0')
+ assert pkg.version_overlap() == 1
- def test_mpi_version(self):
- pkg = spack.repo.get('multimethod^mpich@3.0.4')
- self.assertEqual(pkg.mpi_version(), 3)
+ pkg = spack.repo.get('multimethod@5.0')
+ assert pkg.version_overlap() == 2
- pkg = spack.repo.get('multimethod^mpich2@1.2')
- self.assertEqual(pkg.mpi_version(), 2)
- pkg = spack.repo.get('multimethod^mpich@1.0')
- self.assertEqual(pkg.mpi_version(), 1)
+def test_mpi_version(builtin_mock):
+ pkg = spack.repo.get('multimethod^mpich@3.0.4')
+ assert pkg.mpi_version() == 3
- def test_undefined_mpi_version(self):
- pkg = spack.repo.get('multimethod^mpich@0.4')
- self.assertEqual(pkg.mpi_version(), 1)
+ pkg = spack.repo.get('multimethod^mpich2@1.2')
+ assert pkg.mpi_version() == 2
- pkg = spack.repo.get('multimethod^mpich@1.4')
- self.assertEqual(pkg.mpi_version(), 1)
+ pkg = spack.repo.get('multimethod^mpich@1.0')
+ assert pkg.mpi_version() == 1
- def test_default_works(self):
- pkg = spack.repo.get('multimethod%gcc')
- self.assertEqual(pkg.has_a_default(), 'gcc')
- pkg = spack.repo.get('multimethod%intel')
- self.assertEqual(pkg.has_a_default(), 'intel')
+def test_undefined_mpi_version(builtin_mock):
+ pkg = spack.repo.get('multimethod^mpich@0.4')
+ assert pkg.mpi_version() == 1
- pkg = spack.repo.get('multimethod%pgi')
- self.assertEqual(pkg.has_a_default(), 'default')
+ pkg = spack.repo.get('multimethod^mpich@1.4')
+ assert pkg.mpi_version() == 1
- def test_target_match(self):
- platform = spack.architecture.platform()
- targets = platform.targets.values()
- for target in targets[:-1]:
- pkg = spack.repo.get('multimethod target=' + target.name)
- self.assertEqual(pkg.different_by_target(), target.name)
- pkg = spack.repo.get('multimethod target=' + targets[-1].name)
- if len(targets) == 1:
- self.assertEqual(pkg.different_by_target(), targets[-1].name)
- else:
- self.assertRaises(NoSuchMethodError, pkg.different_by_target)
+def test_default_works(builtin_mock):
+ pkg = spack.repo.get('multimethod%gcc')
+ assert pkg.has_a_default() == 'gcc'
- def test_dependency_match(self):
- pkg = spack.repo.get('multimethod^zmpi')
- self.assertEqual(pkg.different_by_dep(), 'zmpi')
+ pkg = spack.repo.get('multimethod%intel')
+ assert pkg.has_a_default() == 'intel'
- pkg = spack.repo.get('multimethod^mpich')
- self.assertEqual(pkg.different_by_dep(), 'mpich')
+ pkg = spack.repo.get('multimethod%pgi')
+ assert pkg.has_a_default() == 'default'
- # 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')
- self.assertEqual(pkg.different_by_dep(), 'mpich')
- def test_virtual_dep_match(self):
- pkg = spack.repo.get('multimethod^mpich2')
- self.assertEqual(pkg.different_by_virtual_dep(), 2)
+def test_target_match(builtin_mock):
+ platform = spack.architecture.platform()
+ targets = platform.targets.values()
+ for target in targets[:-1]:
+ pkg = spack.repo.get('multimethod target=' + target.name)
+ assert pkg.different_by_target() == target.name
- pkg = spack.repo.get('multimethod^mpich@1.0')
- self.assertEqual(pkg.different_by_virtual_dep(), 1)
+ pkg = spack.repo.get('multimethod target=' + targets[-1].name)
+ if len(targets) == 1:
+ assert pkg.different_by_target() == targets[-1].name
+ else:
+ with pytest.raises(NoSuchMethodError):
+ pkg.different_by_target()
+
+
+def test_dependency_match(builtin_mock):
+ pkg = spack.repo.get('multimethod^zmpi')
+ assert pkg.different_by_dep() == 'zmpi'
+
+ pkg = spack.repo.get('multimethod^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')
+ assert pkg.different_by_dep() == 'mpich'
+
+
+def test_virtual_dep_match(builtin_mock):
+ pkg = spack.repo.get('multimethod^mpich2')
+ assert pkg.different_by_virtual_dep() == 2
+
+ pkg = spack.repo.get('multimethod^mpich@1.0')
+ assert pkg.different_by_virtual_dep() == 1