diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-03-21 14:35:04 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-03-21 14:35:04 -0400 |
commit | 38f99b402d3118e2c26ff42d72ddf9b666adac13 (patch) | |
tree | 705d18bed66337192816325facb1733280291ff5 /testsuite/Testsrc/Testlib/TestUtils.py | |
parent | a3f2a731bbef5d9c2033eed23432aa7792d47989 (diff) | |
parent | 71d7285c405bd639f1f9f2642ea8fb567b97caec (diff) | |
download | bcfg2-38f99b402d3118e2c26ff42d72ddf9b666adac13.tar.gz bcfg2-38f99b402d3118e2c26ff42d72ddf9b666adac13.tar.bz2 bcfg2-38f99b402d3118e2c26ff42d72ddf9b666adac13.zip |
Merge branch '1.3.2' into maint
Conflicts:
src/lib/Bcfg2/Client/Tools/__init__.py
src/sbin/bcfg2-test
testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Test__init.py
testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py
testsuite/Testsrc/test_code_checks.py
Diffstat (limited to 'testsuite/Testsrc/Testlib/TestUtils.py')
-rw-r--r-- | testsuite/Testsrc/Testlib/TestUtils.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/testsuite/Testsrc/Testlib/TestUtils.py b/testsuite/Testsrc/Testlib/TestUtils.py new file mode 100644 index 000000000..349d6cd40 --- /dev/null +++ b/testsuite/Testsrc/Testlib/TestUtils.py @@ -0,0 +1,48 @@ +import os +import sys +import copy +import lxml.etree +import subprocess +from mock import Mock, MagicMock, patch +from Bcfg2.Utils import * + +# add all parent testsuite directories to sys.path to allow (most) +# relative imports in python 2.4 +path = os.path.dirname(__file__) +while path != "/": + if os.path.basename(path).lower().startswith("test"): + sys.path.append(path) + if os.path.basename(path) == "testsuite": + break + path = os.path.dirname(path) +from common import * + + +class TestPackedDigitRange(Bcfg2TestCase): + def test_ranges(self): + # test cases. tuples of (ranges, included numbers, excluded + # numbers) + # tuples of (range description, numbers that are included, + # numebrs that are excluded) + tests = [(["0-3"], ["0", 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]), + (["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], + [851, 320, 766, 999]), + (["0-"], [0, 1, 100, 100000], []), + ([1, "5-10", "1000-"], [1, 5, 10, 1000, 10000000], + [4, 11, 999])] + for ranges, inc, exc in tests: + rng = PackedDigitRange(*ranges) + for test in inc: + self.assertIn(test, rng) + self.assertTrue(rng.includes(test)) + for test in exc: + self.assertNotIn(test, rng) + self.assertFalse(rng.includes(test)) |