From e7208b159800aa8e458fecc86668d250814ba3a7 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Sat, 31 Oct 2020 05:02:06 +0100 Subject: tests: verify to handle dependencies conditional on other dependencies --- lib/spack/spack/test/concretize.py | 18 ++++++++++++++++++ .../builtin.mock/packages/py-extension3/package.py | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 var/spack/repos/builtin.mock/packages/py-extension3/package.py diff --git a/lib/spack/spack/test/concretize.py b/lib/spack/spack/test/concretize.py index f80eb41981..f8b3b1eda2 100644 --- a/lib/spack/spack/test/concretize.py +++ b/lib/spack/spack/test/concretize.py @@ -675,3 +675,21 @@ class TestConcretize(object): s = Spec(spec_str).concretized() assert s.satisfies(expected_str) + + @pytest.mark.parametrize('spec_str,expected,unexpected', [ + ('py-extension3 ^python@3.5.1', [], ['py-extension1']), + ('py-extension3 ^python@2.7.11', ['py-extension1'], []), + ('py-extension3@1.0 ^python@2.7.11', ['patchelf@0.9'], []), + ('py-extension3@1.1 ^python@2.7.11', ['patchelf@0.9'], []), + ('py-extension3@1.0 ^python@3.5.1', ['patchelf@0.10'], []), + ]) + def test_conditional_dependencies(self, spec_str, expected, unexpected): + s = Spec(spec_str).concretized() + + for dep in expected: + msg = '"{0}" is not in "{1}" and was expected' + assert dep in s, msg.format(dep, spec_str) + + for dep in unexpected: + msg = '"{0}" is in "{1}" but was unexpected' + assert dep not in s, msg.format(dep, spec_str) diff --git a/var/spack/repos/builtin.mock/packages/py-extension3/package.py b/var/spack/repos/builtin.mock/packages/py-extension3/package.py new file mode 100644 index 0000000000..164aa00339 --- /dev/null +++ b/var/spack/repos/builtin.mock/packages/py-extension3/package.py @@ -0,0 +1,21 @@ +# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) +class PyExtension3(Package): + """Package with a dependency whose presence is conditional to the + version of Python being used. + """ + + homepage = "http://www.example.com" + url = "http://www.example.com/extension3-1.0.tar.gz" + + depends_on("python") + depends_on('py-extension1', type=('build', 'run'), when='^python@:2.8.0') + + depends_on('patchelf@0.9', when='@1.0:1.1 ^python@:2') + depends_on('patchelf@0.10', when='@1.0:1.1 ^python@3:') + + version('2.0', 'hash-extension3-1.0') + version('1.1', 'hash-extension3-1.0') + version('1.0', 'hash-extension3-1.0') -- cgit v1.2.3-70-g09d2