summaryrefslogtreecommitdiffstats
path: root/tests/conftest.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 05:31:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 05:31:44 +0000
commitf77392695c09f9fef9386c112aef0e2b2f6fcd1a (patch)
tree04c428a7cfc9b7c6dbea73b5697f8c201d9106ff /tests/conftest.py
parentInitial commit. (diff)
downloadpython-pgspecial-f77392695c09f9fef9386c112aef0e2b2f6fcd1a.tar.xz
python-pgspecial-f77392695c09f9fef9386c112aef0e2b2f6fcd1a.zip
Adding upstream version 2.1.2.upstream/2.1.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/conftest.py')
-rw-r--r--tests/conftest.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 0000000..0516dad
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,40 @@
+import pytest
+from dbutils import create_db, db_connection, setup_db, teardown_db, TEST_DB_NAME
+import locale
+from pgspecial.main import PGSpecial
+
+
+locale.setlocale(locale.LC_ALL, "")
+
+
+@pytest.fixture(scope="module")
+def connection():
+ create_db(TEST_DB_NAME)
+ connection = db_connection(TEST_DB_NAME)
+ setup_db(connection)
+ yield connection
+ teardown_db(connection)
+ connection.close()
+
+
+@pytest.fixture
+def cursor(connection):
+ with connection.cursor() as cur:
+ return cur
+
+
+@pytest.fixture
+def executor(connection):
+ cur = connection.cursor()
+ pgspecial = PGSpecial()
+
+ def query_runner(sql):
+ results = []
+ for title, rows, headers, status in pgspecial.execute(cur=cur, sql=sql):
+ if rows:
+ results.extend((title, list(rows), headers, status))
+ else:
+ results.extend((title, None, headers, status))
+ return results
+
+ return query_runner