|
22 | 22 |
|
23 | 23 | from neo4j.bolt import ProtocolError
|
24 | 24 | from neo4j.bolt.connection import connect
|
25 |
| -from neo4j.v1.routing import RoundRobinSet, RoutingTable, RoutingConnectionPool |
| 25 | +from neo4j.v1.routing import OrderedSet, RoutingTable, RoutingConnectionPool |
26 | 26 | from neo4j.v1.security import basic_auth
|
27 | 27 | from neo4j.v1.api import Driver, READ_ACCESS, WRITE_ACCESS
|
28 | 28 |
|
@@ -58,87 +58,80 @@ def connector(address):
|
58 | 58 | class RoundRobinSetTestCase(TestCase):
|
59 | 59 |
|
60 | 60 | def test_should_repr_as_set(self):
|
61 |
| - rrs = RoundRobinSet([1, 2, 3]) |
62 |
| - assert repr(rrs) == "{1, 2, 3}" |
| 61 | + s = OrderedSet([1, 2, 3]) |
| 62 | + assert repr(s) == "{1, 2, 3}" |
63 | 63 |
|
64 | 64 | def test_should_contain_element(self):
|
65 |
| - rrs = RoundRobinSet([1, 2, 3]) |
66 |
| - assert 2 in rrs |
| 65 | + s = OrderedSet([1, 2, 3]) |
| 66 | + assert 2 in s |
67 | 67 |
|
68 | 68 | def test_should_not_contain_non_element(self):
|
69 |
| - rrs = RoundRobinSet([1, 2, 3]) |
70 |
| - assert 4 not in rrs |
71 |
| - |
72 |
| - def test_should_be_able_to_get_next_if_empty(self): |
73 |
| - rrs = RoundRobinSet([]) |
74 |
| - assert next(rrs) is None |
75 |
| - |
76 |
| - def test_should_be_able_to_get_next_repeatedly(self): |
77 |
| - rrs = RoundRobinSet([1, 2, 3]) |
78 |
| - assert next(rrs) == 1 |
79 |
| - assert next(rrs) == 2 |
80 |
| - assert next(rrs) == 3 |
81 |
| - assert next(rrs) == 1 |
82 |
| - |
83 |
| - def test_should_be_able_to_get_next_repeatedly_via_old_method(self): |
84 |
| - rrs = RoundRobinSet([1, 2, 3]) |
85 |
| - assert rrs.next() == 1 |
86 |
| - assert rrs.next() == 2 |
87 |
| - assert rrs.next() == 3 |
88 |
| - assert rrs.next() == 1 |
| 69 | + s = OrderedSet([1, 2, 3]) |
| 70 | + assert 4 not in s |
| 71 | + |
| 72 | + def test_should_be_able_to_get_item_if_empty(self): |
| 73 | + s = OrderedSet([]) |
| 74 | + with self.assertRaises(IndexError): |
| 75 | + _ = s[0] |
| 76 | + |
| 77 | + def test_should_be_able_to_get_items_by_index(self): |
| 78 | + s = OrderedSet([1, 2, 3]) |
| 79 | + self.assertEqual(s[0], 1) |
| 80 | + self.assertEqual(s[1], 2) |
| 81 | + self.assertEqual(s[2], 3) |
89 | 82 |
|
90 | 83 | def test_should_be_iterable(self):
|
91 |
| - rrs = RoundRobinSet([1, 2, 3]) |
92 |
| - assert list(iter(rrs)) == [1, 2, 3] |
| 84 | + s = OrderedSet([1, 2, 3]) |
| 85 | + assert list(iter(s)) == [1, 2, 3] |
93 | 86 |
|
94 | 87 | def test_should_have_length(self):
|
95 |
| - rrs = RoundRobinSet([1, 2, 3]) |
96 |
| - assert len(rrs) == 3 |
| 88 | + s = OrderedSet([1, 2, 3]) |
| 89 | + assert len(s) == 3 |
97 | 90 |
|
98 | 91 | def test_should_be_able_to_add_new(self):
|
99 |
| - rrs = RoundRobinSet([1, 2, 3]) |
100 |
| - rrs.add(4) |
101 |
| - assert list(rrs) == [1, 2, 3, 4] |
| 92 | + s = OrderedSet([1, 2, 3]) |
| 93 | + s.add(4) |
| 94 | + assert list(s) == [1, 2, 3, 4] |
102 | 95 |
|
103 | 96 | def test_should_be_able_to_add_existing(self):
|
104 |
| - rrs = RoundRobinSet([1, 2, 3]) |
105 |
| - rrs.add(2) |
106 |
| - assert list(rrs) == [1, 2, 3] |
| 97 | + s = OrderedSet([1, 2, 3]) |
| 98 | + s.add(2) |
| 99 | + assert list(s) == [1, 2, 3] |
107 | 100 |
|
108 | 101 | def test_should_be_able_to_clear(self):
|
109 |
| - rrs = RoundRobinSet([1, 2, 3]) |
110 |
| - rrs.clear() |
111 |
| - assert list(rrs) == [] |
| 102 | + s = OrderedSet([1, 2, 3]) |
| 103 | + s.clear() |
| 104 | + assert list(s) == [] |
112 | 105 |
|
113 | 106 | def test_should_be_able_to_discard_existing(self):
|
114 |
| - rrs = RoundRobinSet([1, 2, 3]) |
115 |
| - rrs.discard(2) |
116 |
| - assert list(rrs) == [1, 3] |
| 107 | + s = OrderedSet([1, 2, 3]) |
| 108 | + s.discard(2) |
| 109 | + assert list(s) == [1, 3] |
117 | 110 |
|
118 | 111 | def test_should_be_able_to_discard_non_existing(self):
|
119 |
| - rrs = RoundRobinSet([1, 2, 3]) |
120 |
| - rrs.discard(4) |
121 |
| - assert list(rrs) == [1, 2, 3] |
| 112 | + s = OrderedSet([1, 2, 3]) |
| 113 | + s.discard(4) |
| 114 | + assert list(s) == [1, 2, 3] |
122 | 115 |
|
123 | 116 | def test_should_be_able_to_remove_existing(self):
|
124 |
| - rrs = RoundRobinSet([1, 2, 3]) |
125 |
| - rrs.remove(2) |
126 |
| - assert list(rrs) == [1, 3] |
| 117 | + s = OrderedSet([1, 2, 3]) |
| 118 | + s.remove(2) |
| 119 | + assert list(s) == [1, 3] |
127 | 120 |
|
128 | 121 | def test_should_not_be_able_to_remove_non_existing(self):
|
129 |
| - rrs = RoundRobinSet([1, 2, 3]) |
| 122 | + s = OrderedSet([1, 2, 3]) |
130 | 123 | with self.assertRaises(ValueError):
|
131 |
| - rrs.remove(4) |
| 124 | + s.remove(4) |
132 | 125 |
|
133 | 126 | def test_should_be_able_to_update(self):
|
134 |
| - rrs = RoundRobinSet([1, 2, 3]) |
135 |
| - rrs.update([3, 4, 5]) |
136 |
| - assert list(rrs) == [1, 2, 3, 4, 5] |
| 127 | + s = OrderedSet([1, 2, 3]) |
| 128 | + s.update([3, 4, 5]) |
| 129 | + assert list(s) == [1, 2, 3, 4, 5] |
137 | 130 |
|
138 | 131 | def test_should_be_able_to_replace(self):
|
139 |
| - rrs = RoundRobinSet([1, 2, 3]) |
140 |
| - rrs.replace([3, 4, 5]) |
141 |
| - assert list(rrs) == [3, 4, 5] |
| 132 | + s = OrderedSet([1, 2, 3]) |
| 133 | + s.replace([3, 4, 5]) |
| 134 | + assert list(s) == [3, 4, 5] |
142 | 135 |
|
143 | 136 |
|
144 | 137 | class RoutingTableConstructionTestCase(TestCase):
|
|
0 commit comments