aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gn3/api/async_commands.py6
-rw-r--r--gn3/api/correlation.py6
-rw-r--r--gn3/commands.py1
-rw-r--r--gn3/db_utils.py5
-rw-r--r--gn3/fs_helpers.py5
-rw-r--r--tests/unit/test_db_utils.py2
-rw-r--r--tests/unit/test_file_utils.py2
7 files changed, 9 insertions, 18 deletions
diff --git a/gn3/api/async_commands.py b/gn3/api/async_commands.py
index 81c3c44..c0cf4bb 100644
--- a/gn3/api/async_commands.py
+++ b/gn3/api/async_commands.py
@@ -1,6 +1,4 @@
"""Endpoints and functions concerning commands run in external processes."""
-import json
-
import redis
from flask import jsonify, Blueprint
@@ -8,11 +6,11 @@ async_commands = Blueprint("async_commands", __name__)
@async_commands.route("/state/<command_id>")
def command_state(command_id):
+ """Respond with the current state of command identified by `command_id`."""
with redis.Redis(decode_responses=True) as rconn:
state = rconn.hgetall(name=command_id)
if not state:
return jsonify(
status=404,
error="The command id provided does not exist.")
- state = {key: val for key,val in state.items()}
- return jsonify(state)
+ return jsonify(dict(state.items()))
diff --git a/gn3/api/correlation.py b/gn3/api/correlation.py
index 67897e8..7eb7cd6 100644
--- a/gn3/api/correlation.py
+++ b/gn3/api/correlation.py
@@ -1,6 +1,5 @@
"""Endpoints for running correlations"""
import sys
-import json
from functools import reduce
import redis
@@ -17,7 +16,6 @@ from gn3.computations.correlations import map_shared_keys_to_values
from gn3.computations.correlations import compute_tissue_correlation
from gn3.computations.correlations import compute_all_lit_correlation
from gn3.computations.correlations import compute_all_sample_correlation
-from gn3.computations.partial_correlations import partial_correlations_entry
correlation = Blueprint("correlation", __name__)
@@ -132,7 +130,3 @@ def partial_correlation():
int(args.get("criteria", 500))),
job_queue=current_app.config.get("REDIS_JOB_QUEUE"),
env = {"PYTHONPATH": ":".join(sys.path), "SQL_URI": SQL_URI})})
-
-@correlation.route("/partial/<job_id>", methods=["GET"])
-def partial_correlation_results():
- raise Exception("Not implemented!!")
diff --git a/gn3/commands.py b/gn3/commands.py
index 0e0b53c..e622068 100644
--- a/gn3/commands.py
+++ b/gn3/commands.py
@@ -54,6 +54,7 @@ def compose_rqtl_cmd(rqtl_wrapper_cmd: str,
def compose_pcorrs_command(
primary_trait: str, control_traits: Tuple[str, ...], method: str,
target_database: str, criteria: int = 500):
+ """Compose the command to run partias correlations"""
rundir = os.path.abspath(".")
return (
f"{sys.executable}", f"{rundir}/scripts/partial_correlations.py",
diff --git a/gn3/db_utils.py b/gn3/db_utils.py
index 3703cbb..3b72d28 100644
--- a/gn3/db_utils.py
+++ b/gn3/db_utils.py
@@ -17,7 +17,4 @@ def parse_db_url() -> Tuple:
def database_connector() -> mdb.Connection:
"""function to create db connector"""
host, user, passwd, db_name = parse_db_url()
- conn = mdb.connect(host, user, passwd, db_name)
- cursor = conn.cursor()
-
- return conn
+ return mdb.connect(host, user, passwd, db_name)
diff --git a/gn3/fs_helpers.py b/gn3/fs_helpers.py
index 578269b..f313086 100644
--- a/gn3/fs_helpers.py
+++ b/gn3/fs_helpers.py
@@ -71,9 +71,8 @@ contents to TARGET_DIR/<dir-hash>.
os.mkdir(os.path.join(target_dir, token))
gzipped_file.save(tar_target_loc)
# Extract to "tar_target_loc/token"
- tar = tarfile.open(tar_target_loc)
- tar.extractall(path=os.path.join(target_dir, token))
- tar.close()
+ with tarfile.open(tar_target_loc) as tar:
+ tar.extractall(path=os.path.join(target_dir, token))
# pylint: disable=W0703
except Exception:
return {"status": 128, "error": "gzip failed to unpack file"}
diff --git a/tests/unit/test_db_utils.py b/tests/unit/test_db_utils.py
index 44d6703..7dc66c0 100644
--- a/tests/unit/test_db_utils.py
+++ b/tests/unit/test_db_utils.py
@@ -27,6 +27,8 @@ class TestDatabase(TestCase):
mock_sql.connect.assert_called_with(
"localhost", "guest", "4321", "users")
+ self.assertIsInstance(
+ results, SimpleNamespace, "database not created successfully")
@pytest.mark.unit_test
@mock.patch("gn3.db_utils.SQL_URI",
diff --git a/tests/unit/test_file_utils.py b/tests/unit/test_file_utils.py
index 7048d43..2c6f0b6 100644
--- a/tests/unit/test_file_utils.py
+++ b/tests/unit/test_file_utils.py
@@ -66,7 +66,7 @@ non-existent"""
"upload-data.tar.gz")
mock_tarfile.open.assert_called_once_with("/tmp/abcdef-abcdef/"
"upload-data.tar.gz")
- mock_tarfile.open.return_value.extractall.assert_called_once_with(
+ mock_tarfile.open.return_value.__enter__.return_value.extractall.assert_called_once_with(
path='/tmp/abcdef-abcdef')
mock_file.assert_called_once_with("upload-data.tar.gz")
self.assertEqual(result, {"status": 0, "token": "abcdef-abcdef"})