From 6e10237d10a81308dba5e30f820ad4118708162a Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 31 Jul 2018 14:04:12 +0930 Subject: [PATCH] pytest: allow db_query to manipulate db. Needed for the next test. Signed-off-by: Rusty Russell --- tests/utils.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/utils.py b/tests/utils.py index 0aab9f924..9c1e35104 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -379,13 +379,16 @@ class LightningNode(object): def getactivechannels(self): return [c for c in self.rpc.listchannels()['channels'] if c['active']] - def db_query(self, query): - from shutil import copyfile + def db_query(self, query, use_copy=True): orig = os.path.join(self.daemon.lightning_dir, "lightningd.sqlite3") - copy = os.path.join(self.daemon.lightning_dir, "lightningd-copy.sqlite3") - copyfile(orig, copy) + if use_copy: + from shutil import copyfile + copy = os.path.join(self.daemon.lightning_dir, "lightningd-copy.sqlite3") + copyfile(orig, copy) + db = sqlite3.connect(copy) + else: + db = sqlite3.connect(orig) - db = sqlite3.connect(copy) db.row_factory = sqlite3.Row c = db.cursor() c.execute(query) @@ -395,6 +398,7 @@ class LightningNode(object): for row in rows: result.append(dict(zip(row.keys(), row))) + db.commit() c.close() db.close() return result