summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-01-18 09:28:55 -0500
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-01-18 09:28:55 -0500
commit528184be255835c455c69c4754a09dbe456a9139 (patch)
treefd4ad1dba1823173e1d3890dfbfd08ec3dd585bc
parent6348f198b4dd64689a2350847255ed453cdcfbd3 (diff)
downloadbcfg2-528184be255835c455c69c4754a09dbe456a9139.tar.gz
bcfg2-528184be255835c455c69c4754a09dbe456a9139.tar.bz2
bcfg2-528184be255835c455c69c4754a09dbe456a9139.zip
GroupPatterns: improved PackedDigitRange and tests
-rw-r--r--src/lib/Bcfg2/Server/Plugins/GroupPatterns.py7
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestGroupPatterns.py5
2 files changed, 6 insertions, 6 deletions
diff --git a/src/lib/Bcfg2/Server/Plugins/GroupPatterns.py b/src/lib/Bcfg2/Server/Plugins/GroupPatterns.py
index 2e8c56b4e..1b12e590a 100644
--- a/src/lib/Bcfg2/Server/Plugins/GroupPatterns.py
+++ b/src/lib/Bcfg2/Server/Plugins/GroupPatterns.py
@@ -6,6 +6,7 @@ import sys
import logging
import Bcfg2.Server.Lint
import Bcfg2.Server.Plugin
+from Bcfg2.Compat import any # pylint: disable=W0622
class PackedDigitRange(object):
@@ -25,10 +26,8 @@ class PackedDigitRange(object):
iother = int(other)
if iother in self.sparse:
return True
- for (start, end) in self.ranges:
- if iother in range(start, end + 1):
- return True
- return False
+ return any(iother in range(start, end + 1)
+ for start, end in self.ranges)
class PatternMap(object):
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestGroupPatterns.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestGroupPatterns.py
index 84d35ccc5..a7a6b3d6e 100644
--- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestGroupPatterns.py
+++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestGroupPatterns.py
@@ -22,13 +22,14 @@ class TestPackedDigitRange(Bcfg2TestCase):
def test_includes(self):
# tuples of (range description, numbers that are included,
# numebrs that are excluded)
- tests = [("1-3", [1, "2", 3], [4, "0"]),
- ("1", [1], [0, 2]),
+ tests = [("1-3", [1, "2", 3], [4]),
+ ("1", [1], [0, "2"]),
("10-11", [10, 11], [0, 1]),
("9-9", [9], [8, 10]),
("0-100", [0, 10, 99, 100], []),
("1,3,5", [1, 3, 5], [0, 2, 4, 6]),
("1-5,7", [1, 3, 5, 7], [0, 6, 8]),
+ ("1-5,7,9-11", [1, 3, 5, 7, 9, 11], [0, 6, 8, 12]),
("852-855,321-497,763", [852, 855, 321, 400, 497, 763], [])]
for rng, inc, exc in tests:
r = PackedDigitRange(rng)