Skip to content

Commit

Permalink
Ruff formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
olliesilvester committed Jan 10, 2025
1 parent f0f411c commit 0630dce
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 42 deletions.
6 changes: 3 additions & 3 deletions src/dodal/common/crystal_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def make_crystal_metadata_from_material(
d_spacing = d_spacing_param or CrystalMetadata.calculate_default_d_spacing(
material.value.lattice_parameter, reflection_plane
)
assert all(isinstance(i, int) and i > 0 for i in reflection_plane), (
"Reflection plane indices must be positive integers"
)
assert all(
isinstance(i, int) and i > 0 for i in reflection_plane
), "Reflection plane indices must be positive integers"
return CrystalMetadata(usage, material.value.name, reflection_plane, d_spacing)
4 changes: 1 addition & 3 deletions src/dodal/common/udc_directory_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ async def update(self, *, directory: Path, suffix: str = "", **kwargs):
self._filename_provider.suffix = suffix

def __call__(self, device_name: str | None = None) -> PathInfo:
assert self._output_directory, (
"Directory unknown for PandA to write into, update() needs to be called at least once"
)
assert self._output_directory, "Directory unknown for PandA to write into, update() needs to be called at least once"
return PathInfo(
directory_path=self._output_directory,
filename=self._filename_provider(device_name),
Expand Down
6 changes: 3 additions & 3 deletions src/dodal/devices/eiger_odin.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ def check_frames_dropped(self) -> tuple[bool, str]:
def wait_for_no_errors(self, timeout) -> dict[SubscriptionStatus, str]:
errors = {}
for node_number, node_pv in enumerate(self.nodes):
errors[await_value(node_pv.error_status, False, timeout)] = (
f"Filewriter {node_number} is in an error state with error message\
errors[
await_value(node_pv.error_status, False, timeout)
] = f"Filewriter {node_number} is in an error state with error message\
- {node_pv.error_message.get()}"
)

return errors

Expand Down
6 changes: 3 additions & 3 deletions src/dodal/plans/wrapped.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def count(
Wraps bluesky.plans.count(det, num, delay, md=metadata) exposing only serializable
parameters and metadata."""
if isinstance(delay, Sequence):
assert len(delay) == num - 1, (
f"Number of delays given must be {num - 1}: was given {len(delay)}"
)
assert (
len(delay) == num - 1
), f"Number of delays given must be {num - 1}: was given {len(delay)}"
metadata = metadata or {}
metadata["shape"] = (num,)
yield from bp.count(tuple(detectors), num, delay=delay, md=metadata)
12 changes: 6 additions & 6 deletions tests/common/beamlines/test_device_instantiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def test_device_creation(RE, module_and_devices_for_beamline):
for name, device in devices.items()
if not follows_bluesky_protocols(device)
]
assert len(devices_not_following_bluesky_protocols) == 0, (
f"{devices_not_following_bluesky_protocols} do not follow bluesky protocols"
)
assert (
len(devices_not_following_bluesky_protocols) == 0
), f"{devices_not_following_bluesky_protocols} do not follow bluesky protocols"


@pytest.mark.parametrize(
Expand All @@ -56,6 +56,6 @@ def test_devices_are_identical(RE, module_and_devices_for_beamline):
]
total_number_of_devices = len(devices_a)
non_identical_number_of_devies = len(devices_a)
assert len(non_identical_names) == 0, (
f"{non_identical_number_of_devies}/{total_number_of_devices} devices were not identical: {non_identical_names}"
)
assert (
len(non_identical_names) == 0
), f"{non_identical_number_of_devies}/{total_number_of_devices} devices were not identical: {non_identical_names}"
12 changes: 6 additions & 6 deletions tests/devices/unit_tests/detector/test_det_resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def test_resolution(
detector_params.use_roi_mode = roi
get_detector_max_size.return_value = 434.6
actual_res = resolution(detector_params, wavelength_angstroms, det_distance_mm)
assert isclose(expected_res, actual_res), (
f"expected={expected_res}, actual={actual_res}"
)
assert isclose(
expected_res, actual_res
), f"expected={expected_res}, actual={actual_res}"


@pytest.mark.parametrize(
Expand Down Expand Up @@ -126,6 +126,6 @@ def test_resolution_with_roi_realistic(

actual_res = resolution(detector_params, wavelength_angstroms, det_distance_mm)

assert isclose(actual_res, expected_res, rtol=1e-3), (
f"expected={expected_res}, actual={actual_res}"
)
assert isclose(
actual_res, expected_res, rtol=1e-3
), f"expected={expected_res}, actual={actual_res}"
6 changes: 3 additions & 3 deletions tests/devices/unit_tests/test_shutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ async def test_set_shutter_open(
reading = await sim_shutter.read()

shutter_position = reading.get("shutter-position_readback", {})
assert shutter_position["value"] is new_state, (
f"Unexpected value: {shutter_position['value']}"
)
assert (
shutter_position["value"] is new_state
), f"Unexpected value: {shutter_position['value']}"


async def test_given_shutter_in_auto_then_when_set_raises(sim_shutter: ZebraShutter):
Expand Down
6 changes: 3 additions & 3 deletions tests/fake_zocalo/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ def get_dcgid_and_prefix(dcid: int, session_maker: sessionmaker) -> tuple[int, s
.filter(DataCollection.dataCollectionId == dcid)
.first()
)
assert query is not None, (
f"Failed to find dcid {dcid} which matches any in dev ispyb"
)
assert (
query is not None
), f"Failed to find dcid {dcid} which matches any in dev ispyb"
dcgid, prefix = query

except Exception as e:
Expand Down
12 changes: 6 additions & 6 deletions tests/plans/test_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ def assert_hard_requirements(plan: PlanGenerator, signature: inspect.Signature):


def assert_metadata_requirements(plan: PlanGenerator, signature: inspect.Signature):
assert "metadata" in signature.parameters, (
f"'{plan.__name__}' does not allow metadata"
)
assert (
"metadata" in signature.parameters
), f"'{plan.__name__}' does not allow metadata"
metadata = signature.parameters["metadata"]
assert metadata.annotation == dict[str, Any] | None and metadata.default is None, (
f"'{plan.__name__}' metadata is not optional"
)
assert (
metadata.annotation == dict[str, Any] | None and metadata.default is None
), f"'{plan.__name__}' metadata is not optional"
assert metadata.default is None, f"'{plan.__name__}' metadata default is mutable"


Expand Down
14 changes: 8 additions & 6 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,15 @@ def test_get_run_number_uses_prefix(mock_list_dir: MagicMock):
OPHYD_ASYNC_DEVICE_B = OphydV2Device(name="OPHYD_ASYNC_DEVICE_B")


def _filtering_test_cases() -> Iterable[
tuple[
Mapping[str, AnyDevice],
Mapping[str, OphydV1Device],
Mapping[str, OphydV2Device],
def _filtering_test_cases() -> (
Iterable[
tuple[
Mapping[str, AnyDevice],
Mapping[str, OphydV1Device],
Mapping[str, OphydV2Device],
]
]
]:
):
yield {}, {}, {}
yield (
{"oa": OPHYD_DEVICE_A},
Expand Down

0 comments on commit 0630dce

Please sign in to comment.