From b34aa32b25977f3a4877c4e278593e5f850114d6 Mon Sep 17 00:00:00 2001 From: Nigel Small Date: Thu, 16 Jun 2016 15:06:29 +0100 Subject: [PATCH] Updated examples to use try block --- examples/test_examples.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/test_examples.py b/examples/test_examples.py index 46fed58b..ba68fac0 100644 --- a/examples/test_examples.py +++ b/examples/test_examples.py @@ -176,9 +176,9 @@ def test_transaction_commit(self): driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) session = driver.session() # tag::transaction-commit[] - tx = session.begin_transaction() - tx.run("CREATE (:Person {name: 'Guinevere'})") - tx.commit() + with session.begin_transaction() as tx: + tx.run("CREATE (:Person {name: 'Guinevere'})") + tx.success = True # end::transaction-commit[] result = session.run("MATCH (p:Person {name: 'Guinevere'}) RETURN count(p)") record = next(iter(result)) @@ -189,9 +189,9 @@ def test_transaction_rollback(self): driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) session = driver.session() # tag::transaction-rollback[] - tx = session.begin_transaction() - tx.run("CREATE (:Person {name: 'Merlin'})") - tx.rollback() + with session.begin_transaction() as tx: + tx.run("CREATE (:Person {name: 'Merlin'})") + tx.success = False # end::transaction-rollback[] result = session.run("MATCH (p:Person {name: 'Merlin'}) RETURN count(p)") record = next(iter(result))