diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-08 00:54:26 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-08 01:33:00 +0200 |
commit | 52fd7a89473c4b7e18862a5c1f9a2b6715cc41c4 (patch) | |
tree | c823138a799d80763ee801c77f6185695f754839 /test/py/lib | |
parent | clang-format: don't break string literals (diff) | |
download | cimple-52fd7a89473c4b7e18862a5c1f9a2b6715cc41c4.tar.gz cimple-52fd7a89473c4b7e18862a5c1f9a2b6715cc41c4.zip |
test: verify that added runs are in the database
And that they're marked as finished. It immediately exposed some
concurrency bugs, so some locking has been fixed.
Diffstat (limited to '')
-rw-r--r-- | test/py/lib/db.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/py/lib/db.py b/test/py/lib/db.py new file mode 100644 index 0000000..b9059c5 --- /dev/null +++ b/test/py/lib/db.py @@ -0,0 +1,28 @@ +# Copyright (c) 2023 Egor Tensin <Egor.Tensin@gmail.com> +# This file is part of the "cimple" project. +# For details, see https://github.com/egor-tensin/cimple. +# Distributed under the MIT License. + +from contextlib import closing, contextmanager +import sqlite3 + + +class Database: + def __init__(self, path): + self.conn = sqlite3.connect(f'file:{path}?mode=ro') + + def __enter__(self): + return self + + def __exit__(*args): + self.conn.close() + + @contextmanager + def get_cursor(self): + with closing(self.conn.cursor()) as cur: + yield cur + + def get_all_runs(self): + with self.get_cursor() as cur: + cur.execute('SELECT * FROM cimple_runs_readable') + return cur.fetchall() |