Skip to content

Commit

Permalink
Merge pull request #1358 from mvdbeek/fail_with_better_error
Browse files Browse the repository at this point in the history
Drop `allow_none` for finding repository
  • Loading branch information
mvdbeek authored Mar 8, 2023
2 parents 9db63d2 + 622aa4a commit 0bf7c24
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
7 changes: 1 addition & 6 deletions planemo/shed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +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:
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
raise Exception(f"Failed to find repository for owner/name {owner}/{name}")
else:
repo_id = matching_repository["id"]
return repo_id
Expand Down Expand Up @@ -1237,7 +1233,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:
Expand Down
12 changes: 6 additions & 6 deletions tests/shed_app_test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import contextlib
import multiprocessing
import shutil
import threading
from tempfile import mkdtemp
from typing import NamedTuple

Expand Down Expand Up @@ -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
Expand All @@ -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)


Expand Down
8 changes: 0 additions & 8 deletions tests/test_shed_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0bf7c24

Please sign in to comment.