aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gn3/commands.py22
-rw-r--r--tests/unit/test_file_utils.py34
2 files changed, 30 insertions, 26 deletions
diff --git a/gn3/commands.py b/gn3/commands.py
index 7287348..219f4fd 100644
--- a/gn3/commands.py
+++ b/gn3/commands.py
@@ -12,29 +12,29 @@ from redis.client import Redis # Used only in type hinting
from gn3.exceptions import RedisConnectionError
-def compose_gemma_cmd(
- gemma_wrapper_cmd: str = "gemma-wrapper",
- gemma_wrapper_kwargs: Optional[Dict] = None,
- gemma_kwargs: Optional[Dict] = None,
- gemma_args: Optional[List] = None) -> str:
+def compose_gemma_cmd(gemma_wrapper_cmd: str = "gemma-wrapper",
+ gemma_wrapper_kwargs: Optional[Dict] = None,
+ gemma_kwargs: Optional[Dict] = None,
+ gemma_args: Optional[List] = None) -> str:
"""Compose a valid GEMMA command given the correct values"""
cmd = f"{gemma_wrapper_cmd} --json"
if gemma_wrapper_kwargs:
cmd += " " # Add extra space between commands
- cmd += " ".join([f"--{key} {val}" for key, val
- in gemma_wrapper_kwargs.items()])
+ cmd += " ".join(
+ [f"--{key} {val}" for key, val in gemma_wrapper_kwargs.items()])
cmd += " -- "
if gemma_kwargs:
- cmd += " ".join([f"-{key} {val}"
- for key, val in gemma_kwargs.items()])
+ cmd += " ".join([f"-{key} {val}" for key, val in gemma_kwargs.items()])
if gemma_args:
cmd += " "
cmd += " ".join([f"{arg}" for arg in gemma_args])
return cmd
-def queue_cmd(conn: Redis, job_queue: str,
- cmd: str, email: Optional[str] = None) -> str:
+def queue_cmd(conn: Redis,
+ job_queue: str,
+ cmd: str,
+ email: Optional[str] = None) -> str:
"""Given a command CMD; (optional) EMAIL; and a redis connection CONN, queue
it in Redis with an initial status of 'queued'. The following status codes
are supported:
diff --git a/tests/unit/test_file_utils.py b/tests/unit/test_file_utils.py
index b319693..a0f83ee 100644
--- a/tests/unit/test_file_utils.py
+++ b/tests/unit/test_file_utils.py
@@ -27,20 +27,22 @@ class TestFileUtils(unittest.TestCase):
def test_get_dir_hash_non_existent_dir(self):
"""Test thata an error is raised when the dir does not exist"""
- self.assertRaises(FileNotFoundError, get_dir_hash,
+ self.assertRaises(FileNotFoundError,
+ get_dir_hash,
"/non-existent-file")
def test_jsonfile_to_dict(self):
- """Test that a json file is parsed correctly""" ""
- json_file = os.path.join(os.path.dirname(__file__), "test_data",
- "metadata.json")
+ """Test that a json file is parsed correctly"""""
+ json_file = os.path.join(os.path.dirname(__file__),
+ "test_data", "metadata.json")
self.assertEqual("Longer description",
jsonfile_to_dict(json_file).get("description"))
def test_jsonfile_to_dict_nonexistent_file(self):
"""Test that a ValueError is raised when the json file is
non-existent"""
- self.assertRaises(FileNotFoundError, jsonfile_to_dict,
+ self.assertRaises(FileNotFoundError,
+ jsonfile_to_dict,
"/non-existent-dir")
@mock.patch("gn3.file_utils.tarfile")
@@ -51,8 +53,7 @@ non-existent"""
mock_fileobj = MockFile(save=mock.MagicMock(),
filename="upload-data.tar.gz")
mock_tarfile.return_value = mock.Mock()
- result = extract_uploaded_file(mock_fileobj,
- "/tmp",
+ result = extract_uploaded_file(mock_fileobj, "/tmp",
token="abcdef-abcdef")
mock_fileobj.save.assert_called_once_with("/tmp/abcdef-abcdef/"
"upload-data.tar.gz")
@@ -61,17 +62,20 @@ non-existent"""
mock_tarfile.open.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"})
+ self.assertEqual(result,
+ {"status": 0,
+ "token": "abcdef-abcdef"})
@mock.patch("gn3.file_utils.secure_filename")
def test_extract_uploaded_file_non_existent_gzip(self, mock_file):
"""Test that the right error message is returned when there is a problem
extracting the file"""
- mock_file.return_value = os.path.join(os.path.dirname(__file__),
- "CTtyodSTh5") # Does not exist!
- mock_fileobj = MockFile(save=mock.MagicMock(), filename="")
+ mock_file.return_value = os.path.join(
+ os.path.dirname(__file__),
+ "CTtyodSTh5") # Does not exist!
+ mock_fileobj = MockFile(save=mock.MagicMock(),
+ filename="")
result = extract_uploaded_file(mock_fileobj, "/tmp")
- self.assertEqual(result, {
- "status": 128,
- "error": "gzip failed to unpack file"
- })
+ self.assertEqual(result,
+ {"status": 128,
+ "error": "gzip failed to unpack file"})