From 0a7215b81ef1b09326ed5d4e1be1ff1b480fa48f Mon Sep 17 00:00:00 2001 From: Sam Yaple Date: Wed, 1 Nov 2017 16:27:23 -0400 Subject: [PATCH] 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 --- bindep/depends.py | 15 +++++++++------ bindep/tests/test_depends.py | 13 +++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/bindep/depends.py b/bindep/depends.py index d356ad3..e6de4dc 100644 --- a/bindep/depends.py +++ b/bindep/depends.py @@ -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 diff --git a/bindep/tests/test_depends.py b/bindep/tests/test_depends.py index b8cc0bd..0342b73 100644 --- a/bindep/tests/test_depends.py +++ b/bindep/tests/test_depends.py @@ -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(