Revision 691c81b7 test/ganeti.utils_unittest.py
b/test/ganeti.utils_unittest.py | ||
---|---|---|
2326 | 2326 |
"Hello, World, 99") |
2327 | 2327 |
|
2328 | 2328 |
|
2329 |
class TestFindMatch(unittest.TestCase): |
|
2330 |
def test(self): |
|
2331 |
data = { |
|
2332 |
"aaaa": "Four A", |
|
2333 |
"bb": {"Two B": True}, |
|
2334 |
re.compile(r"^x(foo|bar|bazX)([0-9]+)$"): (1, 2, 3), |
|
2335 |
} |
|
2336 |
|
|
2337 |
self.assertEqual(utils.FindMatch(data, "aaaa"), ("Four A", [])) |
|
2338 |
self.assertEqual(utils.FindMatch(data, "bb"), ({"Two B": True}, [])) |
|
2339 |
|
|
2340 |
for i in ["foo", "bar", "bazX"]: |
|
2341 |
for j in range(1, 100, 7): |
|
2342 |
self.assertEqual(utils.FindMatch(data, "x%s%s" % (i, j)), |
|
2343 |
((1, 2, 3), [i, str(j)])) |
|
2344 |
|
|
2345 |
def testNoMatch(self): |
|
2346 |
self.assert_(utils.FindMatch({}, "") is None) |
|
2347 |
self.assert_(utils.FindMatch({}, "foo") is None) |
|
2348 |
self.assert_(utils.FindMatch({}, 1234) is None) |
|
2349 |
|
|
2350 |
data = { |
|
2351 |
"X": "Hello World", |
|
2352 |
re.compile("^(something)$"): "Hello World", |
|
2353 |
} |
|
2354 |
|
|
2355 |
self.assert_(utils.FindMatch(data, "") is None) |
|
2356 |
self.assert_(utils.FindMatch(data, "Hello World") is None) |
|
2357 |
|
|
2358 |
|
|
2329 | 2359 |
if __name__ == '__main__': |
2330 | 2360 |
testutils.GanetiTestProgram() |
Also available in: Unified diff