|
19 | 19 | # a replica set. Thus each method asserts everything we want to assert for a |
20 | 20 | # given replica-set configuration. |
21 | 21 |
|
| 22 | +import itertools |
22 | 23 | import time |
23 | 24 |
|
24 | 25 | import ha_tools |
@@ -53,33 +54,6 @@ def partition_nodes(nodes): |
53 | 54 | return [_partition_node(node) for node in nodes] |
54 | 55 |
|
55 | 56 |
|
56 | | -# Backport permutations to Python 2.4. |
57 | | -# http://docs.python.org/2.7/library/itertools.html#itertools.permutations |
58 | | -def permutations(iterable, r=None): |
59 | | - pool = tuple(iterable) |
60 | | - n = len(pool) |
61 | | - if r is None: |
62 | | - r = n |
63 | | - if r > n: |
64 | | - return |
65 | | - indices = range(n) |
66 | | - cycles = range(n, n-r, -1) |
67 | | - yield tuple(pool[i] for i in indices[:r]) |
68 | | - while n: |
69 | | - for i in reversed(range(r)): |
70 | | - cycles[i] -= 1 |
71 | | - if cycles[i] == 0: |
72 | | - indices[i:] = indices[i+1:] + indices[i:i+1] |
73 | | - cycles[i] = n - i |
74 | | - else: |
75 | | - j = cycles[i] |
76 | | - indices[i], indices[-j] = indices[-j], indices[i] |
77 | | - yield tuple(pool[i] for i in indices[:r]) |
78 | | - break |
79 | | - else: |
80 | | - return |
81 | | - |
82 | | - |
83 | 57 | class HATestCase(unittest.TestCase): |
84 | 58 | """A test case for connections to replica sets or mongos.""" |
85 | 59 |
|
@@ -783,7 +757,7 @@ def test_pinning(self): |
783 | 757 |
|
784 | 758 | # Verify that changing the mode unpins the member. We'll try it for |
785 | 759 | # every relevant change of mode. |
786 | | - for mode0, mode1 in permutations( |
| 760 | + for mode0, mode1 in itertools.permutations( |
787 | 761 | (PRIMARY, SECONDARY, SECONDARY_PREFERRED, NEAREST), 2 |
788 | 762 | ): |
789 | 763 | # Try reading and then changing modes and reading again, see if we |
|
0 commit comments