From 80865bf6699794204c388afccc9610a21ea5176a Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Wed, 8 Mar 2023 13:07:24 +0100 Subject: [PATCH 1/2] Drop `allow_none` for finding repository This was only used in the RealizedRepository class where it is being caught anyway. Should make debugging mismatched in name/owner of .shed.yml much easier. --- planemo/shed/__init__.py | 8 ++------ tests/shed_app_test_utils.py | 12 ++++++------ tests/test_shed_operations.py | 8 -------- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/planemo/shed/__init__.py b/planemo/shed/__init__.py index b398728b6..0bdd28ca7 100644 --- a/planemo/shed/__init__.py +++ b/planemo/shed/__init__.py @@ -533,11 +533,8 @@ def _find_repository_id(ctx, shed_context, name, repo_config, **kwds): owner = _owner(ctx, repo_config, shed_context, **kwds) matching_repository = find_repository(shed_context.tsi, owner, name) if matching_repository is None: - if not kwds.get("allow_none", False): - message = "Failed to find repository for owner/name %s/%s" - raise Exception(message % (owner, name)) - else: - return None + message = "Failed to find repository for owner/name %s/%s" + raise Exception(message % (owner, name)) else: repo_id = matching_repository["id"] return repo_id @@ -1237,7 +1234,6 @@ def find_repository_id(self, ctx, shed_context): shed_context, name=self.name, repo_config=self.config, - allow_none=True, ) return repo_id except Exception as e: diff --git a/tests/shed_app_test_utils.py b/tests/shed_app_test_utils.py index 903b90bcc..1990d5edf 100644 --- a/tests/shed_app_test_utils.py +++ b/tests/shed_app_test_utils.py @@ -1,6 +1,6 @@ import contextlib -import multiprocessing import shutil +import threading from tempfile import mkdtemp from typing import NamedTuple @@ -39,10 +39,10 @@ def run(): app.config["model"] = model run_simple("localhost", port, app, use_reloader=False, use_debugger=True) - p = multiprocessing.Process(target=run) - p.start() + t = threading.Thread(target=run, daemon=True) + t.start() network_util.wait_net_service("localhost", port, DEFAULT_OP_TIMEOUT) - return MockShed(f"http://localhost:{port}", directory, p, model) + return MockShed(f"http://localhost:{port}", directory, t, model) @contextlib.contextmanager @@ -59,11 +59,11 @@ def mock_shed(): class MockShed(NamedTuple): url: str directory: str - process: multiprocessing.Process + thread: threading.Thread model: InMemoryShedDataModel def shutdown(self): - self.process.terminate() + self.thread.join(timeout=1) shutil.rmtree(self.directory) diff --git a/tests/test_shed_operations.py b/tests/test_shed_operations.py index c7c72bad3..51466b31e 100644 --- a/tests/test_shed_operations.py +++ b/tests/test_shed_operations.py @@ -21,14 +21,6 @@ def test_find_repository_id(): assert repo_id == "r1" -def test_find_repository_id_missing(): - with mock_shed_context() as shed_context: - repo_id = shed.find_repository_id( - ctx=None, shed_context=shed_context, path=".", name="test_repo_absent", owner="iuc", allow_none=True - ) - assert repo_id is None - - def test_find_repository_id_missing_exception(): with mock_shed_context() as shed_context: exception = None From 622aa4a5c8c46cdc7807bd8634f79bd1320e1089 Mon Sep 17 00:00:00 2001 From: Marius van den Beek Date: Wed, 8 Mar 2023 13:32:23 +0100 Subject: [PATCH 2/2] Use f-string for exception message Co-authored-by: Nicola Soranzo --- planemo/shed/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/planemo/shed/__init__.py b/planemo/shed/__init__.py index 0bdd28ca7..03c414c3a 100644 --- a/planemo/shed/__init__.py +++ b/planemo/shed/__init__.py @@ -533,8 +533,7 @@ def _find_repository_id(ctx, shed_context, name, repo_config, **kwds): owner = _owner(ctx, repo_config, shed_context, **kwds) matching_repository = find_repository(shed_context.tsi, owner, name) if matching_repository is None: - message = "Failed to find repository for owner/name %s/%s" - raise Exception(message % (owner, name)) + raise Exception(f"Failed to find repository for owner/name {owner}/{name}") else: repo_id = matching_repository["id"] return repo_id