summaryrefslogtreecommitdiffstats
path: root/tests/conftest.py
diff options
context:
space:
mode:
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