Skip to content

Commit

Permalink
Black fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
keithralphs committed Feb 9, 2024
1 parent 06a43c5 commit 54c8bd6
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/blueapi/worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TrackableTask(BlueapiBaseModel, Generic[T]):
"""

task_id: str
request_id: str = ''
request_id: str = ""
task: T
is_complete: bool = False
is_pending: bool = True
Expand Down
6 changes: 2 additions & 4 deletions tests/core/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ def read_configuration(self) -> SyncOrAsync[Dict[str, Reading]]: # type: ignore

def describe_configuration( # type: ignore
self,
) -> SyncOrAsync[Dict[str, Descriptor]]:
...
) -> SyncOrAsync[Dict[str, Descriptor]]: ...


@pytest.fixture
Expand Down Expand Up @@ -301,8 +300,7 @@ def test_concrete_type_conversion(empty_context: BlueskyContext) -> None:
def test_concrete_method_annotation(empty_context: BlueskyContext) -> None:
hasname_ref = empty_context._reference(Named)

def demo(named: Named) -> None:
...
def demo(named: Named) -> None: ...

spec = empty_context._type_spec_for_function(demo)
assert spec["named"][0] is hasname_ref
Expand Down
9 changes: 3 additions & 6 deletions tests/messaging/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,21 @@ class Foo:


def test_determine_deserialization_type() -> None:
def on_message(headers: Mapping[str, Any], message: Foo) -> None:
...
def on_message(headers: Mapping[str, Any], message: Foo) -> None: ...

deserialization_type = determine_deserialization_type(on_message) # type: ignore
assert deserialization_type is Foo


def test_determine_deserialization_type_with_no_type() -> None:
def on_message(headers: Mapping[str, Any], message) -> None:
...
def on_message(headers: Mapping[str, Any], message) -> None: ...

deserialization_type = determine_deserialization_type(on_message) # type: ignore
assert deserialization_type is str


def test_determine_deserialization_type_with_wrong_signature() -> None:
def on_message(message: Foo) -> None:
...
def on_message(message: Foo) -> None: ...

with pytest.raises(ValueError):
determine_deserialization_type(on_message) # type: ignore
12 changes: 6 additions & 6 deletions tests/service/test_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,9 @@ def test_delete_running_task(
aborts: int,
):
stop = mockable_state_machine._context.run_engine.stop = MagicMock() # type: ignore
abort = (
mockable_state_machine._context.run_engine.abort # type: ignore
) = MagicMock()
abort = mockable_state_machine._context.run_engine.abort = ( # type: ignore
MagicMock()
)

def start_task(_: str):
mockable_state_machine._worker._current = ( # type: ignore
Expand Down Expand Up @@ -440,9 +440,9 @@ def start_task(_: str):


def test_reason_passed_to_abort(mockable_state_machine: Handler, client: TestClient):
abort = (
mockable_state_machine._context.run_engine.abort # type: ignore
) = MagicMock()
abort = mockable_state_machine._context.run_engine.abort = ( # type: ignore
MagicMock()
)

def start_task(_: str):
mockable_state_machine._worker._current = ( # type: ignore
Expand Down
3 changes: 1 addition & 2 deletions tests/utils/test_thread_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@


@handle_all_exceptions
def shouldnt_error():
...
def shouldnt_error(): ...


@handle_all_exceptions
Expand Down
18 changes: 9 additions & 9 deletions tests/worker/test_reworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,20 @@ def test_submit_task(worker: Worker) -> None:
assert worker.get_pending_tasks() == []
task_id = worker.submit_task(_SIMPLE_TASK)
assert worker.get_pending_tasks() == [
TrackableTask(task_id=task_id, request_id='None', task=_SIMPLE_TASK)
TrackableTask(task_id=task_id, request_id="None", task=_SIMPLE_TASK)
]


def test_submit_multiple_tasks(worker: Worker) -> None:
assert worker.get_pending_tasks() == []
task_id_1 = worker.submit_task(_SIMPLE_TASK)
assert worker.get_pending_tasks() == [
TrackableTask(task_id=task_id_1, request_id='None', task=_SIMPLE_TASK)
TrackableTask(task_id=task_id_1, request_id="None", task=_SIMPLE_TASK)
]
task_id_2 = worker.submit_task(_LONG_TASK)
assert worker.get_pending_tasks() == [
TrackableTask(task_id=task_id_1, request_id='None', task=_SIMPLE_TASK),
TrackableTask(task_id=task_id_2, request_id='None', task=_LONG_TASK),
TrackableTask(task_id=task_id_1, request_id="None", task=_SIMPLE_TASK),
TrackableTask(task_id=task_id_2, request_id="None", task=_LONG_TASK),
]


Expand All @@ -138,31 +138,31 @@ def test_stop_with_task_pending(inert_worker: Worker) -> None:
def test_restart_leaves_task_pending(worker: Worker) -> None:
task_id = worker.submit_task(_SIMPLE_TASK)
assert worker.get_pending_tasks() == [
TrackableTask(task_id=task_id, request_id='None', task=_SIMPLE_TASK)
TrackableTask(task_id=task_id, request_id="None", task=_SIMPLE_TASK)
]
worker.stop()
worker.start()
assert worker.get_pending_tasks() == [
TrackableTask(task_id=task_id, request_id='None', task=_SIMPLE_TASK)
TrackableTask(task_id=task_id, request_id="None", task=_SIMPLE_TASK)
]


def test_submit_before_start_pending(inert_worker: Worker) -> None:
task_id = inert_worker.submit_task(_SIMPLE_TASK)
inert_worker.start()
assert inert_worker.get_pending_tasks() == [
TrackableTask(task_id=task_id, request_id='None', task=_SIMPLE_TASK)
TrackableTask(task_id=task_id, request_id="None", task=_SIMPLE_TASK)
]
inert_worker.stop()
assert inert_worker.get_pending_tasks() == [
TrackableTask(task_id=task_id, request_id='None', task=_SIMPLE_TASK)
TrackableTask(task_id=task_id, request_id="None", task=_SIMPLE_TASK)
]


def test_clear_task(worker: Worker) -> None:
task_id = worker.submit_task(_SIMPLE_TASK)
assert worker.get_pending_tasks() == [
TrackableTask(task_id=task_id, request_id='None', task=_SIMPLE_TASK)
TrackableTask(task_id=task_id, request_id="None", task=_SIMPLE_TASK)
]
assert worker.clear_task(task_id)
assert worker.get_pending_tasks() == []
Expand Down

0 comments on commit 54c8bd6

Please sign in to comment.