Skip to content

Commit a498cd5

Browse files
committed
Fix the last test.
1 parent 56e407f commit a498cd5

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

test/examples/cypher_error_example.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@ class CypherErrorExample(BaseApplication):
2727
def __init__(self, uri, user, password):
2828
super(CypherErrorExample, self).__init__(uri, user, password)
2929

30-
# FIXME: this doesn't work because read_transaction behaves
31-
# differently than in Java, so this throws a ClientError
32-
3330
# tag::cypher-error[]
3431
def get_employee_number(self, name):
35-
with self._driver.session() as session:
36-
return session.read_transaction(lambda tx: self.select_employee(tx, name))
32+
session = self._driver.session()
33+
session.read_transaction(lambda tx: self.select_employee(tx, name))
3734

3835
def select_employee(self, tx, name):
3936
try:

test/examples/test_examples.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,21 @@ def test_config_unencrypted_example(self):
6868

6969
self.assertIsInstance(example, ConfigUnencryptedExample)
7070

71-
def Xtest_cypher_error_example(self):
71+
def test_cypher_error_example(self):
7272
from cypher_error_example import CypherErrorExample
7373

74-
example = CypherErrorExample(self.bolt_uri, self.user, self.password)
75-
employee_number = example.get_employee_number('Alice')
76-
77-
# FIXME: also check the error output like in the Java example
78-
self.assertEqual(employee_number, -1)
74+
f = get_string_io()
75+
with stdout_redirector(f):
76+
example = CypherErrorExample(self.bolt_uri, self.user, self.password)
77+
try:
78+
example.get_employee_number('Alice')
79+
except:
80+
pass
81+
82+
self.assertTrue(f.getvalue().startswith(
83+
"""Invalid input 'L': expected 't/T' (line 1, column 3 (offset: 2))
84+
"SELECT * FROM Employees WHERE name = $name"
85+
^"""))
7986

8087
def test_driver_lifecycle_example(self):
8188
from driver_lifecycle_example import DriverLifecycleExample

0 commit comments

Comments
 (0)