Skip to content

Commit

Permalink
remove more kwarg
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Nov 27, 2024
1 parent bc8fd00 commit 2a6f06c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
20 changes: 17 additions & 3 deletions spalloc_client/protocol_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,29 @@ def version(self, timeout: Optional[float] = None) -> str:
return cast(str, self.call("version", timeout))

def create_job(self, timeout: Optional[float], *args: int,
**kwargs: Union[float, str, List[str], None]) -> int:
owner: Optional[str] = None,
keepalive: Optional[float] = None,
machine: Optional[str] = None,
tags: Optional[List[str]] = None,
min_ratio: Optional[float] = None,
max_dead_boards: Optional[int] = None,
max_dead_links: Optional[int] = None,
require_torus: Optional[bool] = None) -> int:
"""
Start a new job
"""
# If no owner, don't bother with the call
if "owner" not in kwargs:
if owner is None:
raise SpallocServerException(
"owner must be specified for all jobs.")
return cast(int, self.call("create_job", timeout, *args, **kwargs))
if tags is not None and machine is not None:
raise SpallocServerException(
f"Unexpected {tags=} and {machine=} are both not None")
return cast(int, self.call(
"create_job", timeout, *args, owner=owner,
keepalive=keepalive, machine=machine, tags=tags,
min_ratio=min_ratio, max_dead_boards=max_dead_boards,
max_dead_links =max_dead_links, require_torus=require_torus))

def job_keepalive(self, job_id: int,
timeout: Optional[float] = None) -> JsonObject:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import pytest
from mock import Mock # type: ignore[import]
from spalloc_client import (
Job, JobState, JobDestroyedError, ProtocolTimeoutError)
Job, JobState, JobDestroyedError, ProtocolTimeoutError,
SpallocServerException)
from spalloc_client._keepalive_process import keep_job_alive
from spalloc_client.job import (
_JobStateTuple, _JobMachineInfoTuple, StateChangeTimeoutError,
Expand Down
9 changes: 6 additions & 3 deletions tests/test_protocol_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,13 @@ def test_commands_as_methods(c, s, bg_accept):

s.send({"return": "Woo"})
no_timeout = None
assert c.create_job(no_timeout, 1, bar=2, owner="dummy") == "Woo"
assert s.recv() == {
assert c.create_job(no_timeout, 1, keepalive=2, owner="dummy") == "Woo"
commands = s.recv()
commands["kwargs"] = {k: v for k, v in commands["kwargs"].items()
if v is not None}
assert commands == {
"command": "create_job", "args": [1], "kwargs": {
"bar": 2, "owner": "dummy"}}
"keepalive": 2, "owner": "dummy"}}

# Should fail for arbitrary internal method names
with pytest.raises(AttributeError):
Expand Down

0 comments on commit 2a6f06c

Please sign in to comment.