Browse Source

Merge "Fix logic for groups"

tags/2.6.0^0
Zuul 1 year ago
parent
commit
7e941fc9a8
2 changed files with 22 additions and 6 deletions
  1. 9
    6
      bindep/depends.py
  2. 13
    0
      bindep/tests/test_depends.py

+ 9
- 6
bindep/depends.py View File

@@ -165,15 +165,15 @@ class Depends(object):
165 165
         # selectors we need a match.
166 166
         positive = False
167 167
         match_found = False
168
+        group_found = False
169
+        group_match_found = False
168 170
         negative = False
169 171
         for group in partition_rule:
170 172
             if isinstance(group, list):
173
+                group_found = True
171 174
                 if self._match_all(group, profiles):
172
-                    match_found = True
173
-                    continue
174
-                else:
175
-                    negative = True
176
-                    break
175
+                    group_match_found = True
176
+                continue
177 177
             sense, profile = group
178 178
             if sense:
179 179
                 positive = True
@@ -183,7 +183,10 @@ class Depends(object):
183 183
                 if profile in profiles:
184 184
                     negative = True
185 185
                     break
186
-        if not negative and (match_found or not positive):
186
+        if not negative:
187
+            if group_match_found or match_found:
188
+                return True
189
+            if not group_found and not positive:
187 190
                 return True
188 191
         return False
189 192
 

+ 13
- 0
bindep/tests/test_depends.py View File

@@ -236,6 +236,19 @@ class TestDepends(TestCase):
236 236
             [("foo", [(False, "bar"), (True, "baz"), (True, "quux")], [])],
237 237
             depends._rules)
238 238
 
239
+    def test_single_group_only(self):
240
+        depends = Depends("foo [(bar)]\n")
241
+        self.assertTrue(depends._evaluate(depends._rules[0][1], ["bar"]))
242
+        self.assertFalse(depends._evaluate(depends._rules[0][1], ["baz"]))
243
+
244
+    def test_multiple_groups_only(self):
245
+        depends = Depends("foo [(bar baz) (quux)]\n")
246
+        self.assertTrue(depends._evaluate(depends._rules[0][1],
247
+                                          ["bar", "baz"]))
248
+        self.assertTrue(depends._evaluate(depends._rules[0][1], ["quux"]))
249
+        self.assertFalse(depends._evaluate(depends._rules[0][1], ["baz"]))
250
+        self.assertFalse(depends._evaluate(depends._rules[0][1], ["bar"]))
251
+
239 252
     def test_whitespace(self):
240 253
         depends = Depends("foo [ ( bar !baz ) quux ]\n")
241 254
         self.assertEqual(

Loading…
Cancel
Save