Skip to content

Commit 44a7c48

Browse files
committed
Basic routing functionality
1 parent 0953a73 commit 44a7c48

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1156
-521
lines changed

.coveragerc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
branch = True
33
omit =
44
test/*
5+
neo4j/util.py
56
neo4j/v1/compat.py
7+
neo4j/v1/ssl_compat.py

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ docs/build
1313
dist
1414
*.egg-info
1515
build
16+
17+
*/run/*
18+
19+
neo4j-community-*
20+
neo4j-enterprise-*

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "neokit"]
2-
path = neokit
3-
url = https://github.com/neo-technology/neokit.git

examples/test_examples.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@
3232
# (* "good reason" is defined as knowing what you are doing)
3333

3434

35-
auth_token = basic_auth("neo4j", "neo4j")
35+
auth_token = basic_auth("neotest", "neotest")
36+
37+
38+
# Deliberately shadow the built-in print function to
39+
# mute noise from example code.
40+
def print(*args, **kwargs):
41+
pass
3642

3743

3844
class FreshDatabaseTestCase(ServerTestCase):
@@ -48,7 +54,7 @@ class MinimalWorkingExampleTestCase(FreshDatabaseTestCase):
4854

4955
def test_minimal_working_example(self):
5056
# tag::minimal-example[]
51-
driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"))
57+
driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neotest", "neotest"))
5258
session = driver.session()
5359

5460
session.run("CREATE (a:Person {name:'Arthur', title:'King'})")
@@ -65,33 +71,33 @@ class ExamplesTestCase(FreshDatabaseTestCase):
6571

6672
def test_construct_driver(self):
6773
# tag::construct-driver[]
68-
driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"))
74+
driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neotest", "neotest"))
6975
# end::construct-driver[]
7076
return driver
7177

7278
def test_configuration(self):
7379
# tag::configuration[]
74-
driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"), max_pool_size=10)
80+
driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neotest", "neotest"), max_pool_size=10)
7581
# end::configuration[]
7682
return driver
7783

7884
@skipUnless(SSL_AVAILABLE, "Bolt over TLS is not supported by this version of Python")
7985
def test_tls_require_encryption(self):
8086
# tag::tls-require-encryption[]
81-
driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"), encrypted=True)
87+
driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neotest", "neotest"), encrypted=True)
8288
# end::tls-require-encryption[]
8389

8490
@skipUnless(SSL_AVAILABLE, "Bolt over TLS is not supported by this version of Python")
8591
def test_tls_trust_on_first_use(self):
8692
# tag::tls-trust-on-first-use[]
87-
driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"), encrypted=True, trust=TRUST_ON_FIRST_USE)
93+
driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neotest", "neotest"), encrypted=True, trust=TRUST_ON_FIRST_USE)
8894
# end::tls-trust-on-first-use[]
8995
assert driver
9096

9197
@skip("testing verified certificates not yet supported ")
9298
def test_tls_signed(self):
9399
# tag::tls-signed[]
94-
driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"), encrypted=True, trust=TRUST_SIGNED_CERTIFICATES)
100+
driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neotest", "neotest"), encrypted=True, trust=TRUST_SIGNED_CERTIFICATES)
95101
# end::tls-signed[]
96102
assert driver
97103

neo4j/util.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
# limitations under the License.
2020

2121

22+
try:
23+
from collections.abc import MutableSet
24+
except ImportError:
25+
from collections import MutableSet, OrderedDict
26+
else:
27+
from collections import OrderedDict
2228
import logging
2329
from sys import stdout
2430

@@ -55,6 +61,13 @@ def __init__(self, logger_name):
5561
self.logger = logging.getLogger(self.logger_name)
5662
self.formatter = ColourFormatter("%(asctime)s %(message)s")
5763

64+
def __enter__(self):
65+
self.watch()
66+
return self
67+
68+
def __exit__(self, exc_type, exc_val, exc_tb):
69+
self.stop()
70+
5871
def watch(self, level=logging.INFO, out=stdout):
5972
self.stop()
6073
handler = logging.StreamHandler(out)
@@ -81,3 +94,61 @@ def watch(logger_name, level=logging.INFO, out=stdout):
8194
watcher = Watcher(logger_name)
8295
watcher.watch(level, out)
8396
return watcher
97+
98+
99+
class RoundRobinSet(MutableSet):
100+
101+
def __init__(self, elements=()):
102+
self._elements = OrderedDict.fromkeys(elements)
103+
self._current = None
104+
105+
def __repr__(self):
106+
return "{%s}" % ", ".join(map(repr, self._elements))
107+
108+
def __contains__(self, element):
109+
return element in self._elements
110+
111+
def __next__(self):
112+
current = None
113+
if self._elements:
114+
if self._current is None:
115+
self._current = 0
116+
else:
117+
self._current = (self._current + 1) % len(self._elements)
118+
current = list(self._elements.keys())[self._current]
119+
return current
120+
121+
def __iter__(self):
122+
return iter(self._elements)
123+
124+
def __len__(self):
125+
return len(self._elements)
126+
127+
def add(self, element):
128+
self._elements[element] = None
129+
130+
def clear(self):
131+
self._elements.clear()
132+
133+
def discard(self, element):
134+
try:
135+
del self._elements[element]
136+
except KeyError:
137+
pass
138+
139+
def next(self):
140+
return self.__next__()
141+
142+
def remove(self, element):
143+
try:
144+
del self._elements[element]
145+
except KeyError:
146+
raise ValueError(element)
147+
148+
def update(self, elements=()):
149+
self._elements.update(OrderedDict.fromkeys(elements))
150+
151+
def replace(self, elements=()):
152+
e = self._elements
153+
e.clear()
154+
e.update(OrderedDict.fromkeys(elements))

0 commit comments

Comments
 (0)