Skip to content
Snippets Groups Projects
Commit cd1ca364 authored by Todd Gamblin's avatar Todd Gamblin
Browse files

SPACK-41: More tests to ensure that constrain() reports changes.

parent 805122c7
Branches
Tags
No related merge requests found
...@@ -1107,13 +1107,12 @@ def validate_names(self): ...@@ -1107,13 +1107,12 @@ def validate_names(self):
raise UnknownVariantError(spec.name, vname) raise UnknownVariantError(spec.name, vname)
def constrain(self, other, **kwargs): def constrain(self, other, deps=True):
"""Merge the constraints of other with self. """Merge the constraints of other with self.
Returns True if the spec changed as a result, False if not. Returns True if the spec changed as a result, False if not.
""" """
other = self._autospec(other) other = self._autospec(other)
constrain_deps = kwargs.get('deps', True)
if not self.name == other.name: if not self.name == other.name:
raise UnsatisfiableSpecNameError(self.name, other.name) raise UnsatisfiableSpecNameError(self.name, other.name)
...@@ -1146,7 +1145,7 @@ def constrain(self, other, **kwargs): ...@@ -1146,7 +1145,7 @@ def constrain(self, other, **kwargs):
self.architecture = self.architecture or other.architecture self.architecture = self.architecture or other.architecture
changed |= (self.architecture != old) changed |= (self.architecture != old)
if constrain_deps: if deps:
changed |= self._constrain_dependencies(other) changed |= self._constrain_dependencies(other)
return changed return changed
...@@ -1154,6 +1153,8 @@ def constrain(self, other, **kwargs): ...@@ -1154,6 +1153,8 @@ def constrain(self, other, **kwargs):
def _constrain_dependencies(self, other): def _constrain_dependencies(self, other):
"""Apply constraints of other spec's dependencies to this spec.""" """Apply constraints of other spec's dependencies to this spec."""
other = self._autospec(other)
if not self.dependencies or not other.dependencies: if not self.dependencies or not other.dependencies:
return False return False
...@@ -1260,6 +1261,8 @@ def satisfies(self, other, deps=True, strict=False): ...@@ -1260,6 +1261,8 @@ def satisfies(self, other, deps=True, strict=False):
def satisfies_dependencies(self, other, strict=False): def satisfies_dependencies(self, other, strict=False):
"""This checks constraints on common dependencies against each other.""" """This checks constraints on common dependencies against each other."""
other = self._autospec(other)
if strict: if strict:
if other.dependencies and not self.dependencies: if other.dependencies and not self.dependencies:
return False return False
......
...@@ -64,6 +64,16 @@ def check_constrain(self, expected, spec, constraint): ...@@ -64,6 +64,16 @@ def check_constrain(self, expected, spec, constraint):
self.assertEqual(exp, spec) self.assertEqual(exp, spec)
def check_constrain_changed(self, spec, constraint):
spec = Spec(spec)
self.assertTrue(spec.constrain(constraint))
def check_constrain_not_changed(self, spec, constraint):
spec = Spec(spec)
self.assertFalse(spec.constrain(constraint))
def check_invalid_constraint(self, spec, constraint): def check_invalid_constraint(self, spec, constraint):
spec = Spec(spec) spec = Spec(spec)
constraint = Spec(constraint) constraint = Spec(constraint)
...@@ -200,6 +210,11 @@ def test_constrain_arch(self): ...@@ -200,6 +210,11 @@ def test_constrain_arch(self):
self.check_constrain('libelf=bgqos_0', 'libelf', 'libelf=bgqos_0') self.check_constrain('libelf=bgqos_0', 'libelf', 'libelf=bgqos_0')
def test_constrain_compiler(self):
self.check_constrain('libelf=bgqos_0', 'libelf=bgqos_0', 'libelf=bgqos_0')
self.check_constrain('libelf=bgqos_0', 'libelf', 'libelf=bgqos_0')
def test_invalid_constraint(self): def test_invalid_constraint(self):
self.check_invalid_constraint('libelf@0:2.0', 'libelf@2.1:3') self.check_invalid_constraint('libelf@0:2.0', 'libelf@2.1:3')
self.check_invalid_constraint('libelf@0:2.5%gcc@4.8:4.9', 'libelf@2.1:3%gcc@4.5:4.7') self.check_invalid_constraint('libelf@0:2.5%gcc@4.8:4.9', 'libelf@2.1:3%gcc@4.5:4.7')
...@@ -208,3 +223,47 @@ def test_invalid_constraint(self): ...@@ -208,3 +223,47 @@ def test_invalid_constraint(self):
self.check_invalid_constraint('libelf+debug~foo', 'libelf+debug+foo') self.check_invalid_constraint('libelf+debug~foo', 'libelf+debug+foo')
self.check_invalid_constraint('libelf=bgqos_0', 'libelf=x86_54') self.check_invalid_constraint('libelf=bgqos_0', 'libelf=x86_54')
def test_constrain_changed(self):
self.check_constrain_changed('libelf', '@1.0')
self.check_constrain_changed('libelf', '@1.0:5.0')
self.check_constrain_changed('libelf', '%gcc')
self.check_constrain_changed('libelf%gcc', '%gcc@4.5')
self.check_constrain_changed('libelf', '+debug')
self.check_constrain_changed('libelf', '~debug')
self.check_constrain_changed('libelf', '=bgqos_0')
def test_constrain_not_changed(self):
self.check_constrain_not_changed('libelf', 'libelf')
self.check_constrain_not_changed('libelf@1.0', '@1.0')
self.check_constrain_not_changed('libelf@1.0:5.0', '@1.0:5.0')
self.check_constrain_not_changed('libelf%gcc', '%gcc')
self.check_constrain_not_changed('libelf%gcc@4.5', '%gcc@4.5')
self.check_constrain_not_changed('libelf+debug', '+debug')
self.check_constrain_not_changed('libelf~debug', '~debug')
self.check_constrain_not_changed('libelf=bgqos_0', '=bgqos_0')
self.check_constrain_not_changed('libelf^foo', 'libelf^foo')
self.check_constrain_not_changed('libelf^foo^bar', 'libelf^foo^bar')
def test_constrain_dependency_changed(self):
self.check_constrain_changed('libelf^foo', 'libelf^foo@1.0')
self.check_constrain_changed('libelf^foo', 'libelf^foo@1.0:5.0')
self.check_constrain_changed('libelf^foo', 'libelf^foo%gcc')
self.check_constrain_changed('libelf^foo%gcc', 'libelf^foo%gcc@4.5')
self.check_constrain_changed('libelf^foo', 'libelf^foo+debug')
self.check_constrain_changed('libelf^foo', 'libelf^foo~debug')
self.check_constrain_changed('libelf^foo', 'libelf^foo=bgqos_0')
def test_constrain_dependency_not_changed(self):
self.check_constrain_not_changed('libelf^foo@1.0', 'libelf^foo@1.0')
self.check_constrain_not_changed('libelf^foo@1.0:5.0', 'libelf^foo@1.0:5.0')
self.check_constrain_not_changed('libelf^foo%gcc', 'libelf^foo%gcc')
self.check_constrain_not_changed('libelf^foo%gcc@4.5', 'libelf^foo%gcc@4.5')
self.check_constrain_not_changed('libelf^foo+debug', 'libelf^foo+debug')
self.check_constrain_not_changed('libelf^foo~debug', 'libelf^foo~debug')
self.check_constrain_not_changed('libelf^foo=bgqos_0', 'libelf^foo=bgqos_0')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment