Fix logic for groups

This adjusts the logic to be in keeping with the original spirit of the
patch. We want to treat a group as a profile, so if a group exists and
does not match, and no other groups or profiles were specified, the
package should not be installed.

Change-Id: If76bbb408837b14e79a659348edbdb840be7b9ba
This commit is contained in:
Sam Yaple 2017-11-01 16:27:23 -04:00
parent 24427065c5
commit 0a7215b81e
2 changed files with 22 additions and 6 deletions

View File

@ -165,15 +165,15 @@ class Depends(object):
# selectors we need a match.
positive = False
match_found = False
group_found = False
group_match_found = False
negative = False
for group in partition_rule:
if isinstance(group, list):
group_found = True
if self._match_all(group, profiles):
match_found = True
continue
else:
negative = True
break
group_match_found = True
continue
sense, profile = group
if sense:
positive = True
@ -183,7 +183,10 @@ class Depends(object):
if profile in profiles:
negative = True
break
if not negative and (match_found or not positive):
if not negative:
if group_match_found or match_found:
return True
if not group_found and not positive:
return True
return False

View File

@ -236,6 +236,19 @@ class TestDepends(TestCase):
[("foo", [(False, "bar"), (True, "baz"), (True, "quux")], [])],
depends._rules)
def test_single_group_only(self):
depends = Depends("foo [(bar)]\n")
self.assertTrue(depends._evaluate(depends._rules[0][1], ["bar"]))
self.assertFalse(depends._evaluate(depends._rules[0][1], ["baz"]))
def test_multiple_groups_only(self):
depends = Depends("foo [(bar baz) (quux)]\n")
self.assertTrue(depends._evaluate(depends._rules[0][1],
["bar", "baz"]))
self.assertTrue(depends._evaluate(depends._rules[0][1], ["quux"]))
self.assertFalse(depends._evaluate(depends._rules[0][1], ["baz"]))
self.assertFalse(depends._evaluate(depends._rules[0][1], ["bar"]))
def test_whitespace(self):
depends = Depends("foo [ ( bar !baz ) quux ]\n")
self.assertEqual(