aboutsummaryrefslogtreecommitdiff
path: root/tests/integration/conftest.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-03-25 16:13:00 +0300
committerFrederick Muriuki Muriithi2022-03-26 15:04:47 +0300
commitfd39b8ce0ad86c85636a09ca3ac15975fabf776a (patch)
tree6cd594142b5eea2e1f5ee135b9ee758f81926eda /tests/integration/conftest.py
parent7a93ecb4399241541af56c12247202874fbfe2d9 (diff)
downloadgenenetwork3-fd39b8ce0ad86c85636a09ca3ac15975fabf776a.tar.gz
Create a fixture for pcorrs datafixture-for-pcorrs
Diffstat (limited to 'tests/integration/conftest.py')
-rw-r--r--tests/integration/conftest.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py
index 4274233..90cf985 100644
--- a/tests/integration/conftest.py
+++ b/tests/integration/conftest.py
@@ -78,3 +78,27 @@ def db_conn():
#
# b.) Delete the test database
db_cursor.execute(f"DROP DATABASE IF EXISTS {test_db_name}")
+
+@pytest.fixture(scope="function")
+def db_conn_with_pcorrs_data(db_conn):
+ """Fixture with data for partial correlations tests"""
+ with open(
+ "tests/integration/test_data/pcorrs_data.json",
+ encoding="utf8") as data_file:
+ data = json.loads(data_file.read())
+ with db_conn.cursor() as cursor:
+ for item in data:
+ row_keys = item["rows"][0].keys()
+ query = (
+ f"INSERT INTO {item['dbtable']}({', '.join(row_keys)}) "
+ f"VALUES ({', '.join(['%s' for key in row_keys])})")
+ cursor.executemany(
+ query,
+ tuple(
+ tuple(row[key] for key in row_keys)
+ for row in item["rows"]))
+
+ yield db_conn
+
+ for item in data:
+ cursor.execute(f"DELETE FROM {item['dbtable']}")