Skip to content

Commit 6c5ef22

Browse files
committed
add requested clean up after code review
For #dodal #1384
1 parent eca65ff commit 6c5ef22

File tree

5 files changed

+16
-24
lines changed

5 files changed

+16
-24
lines changed

src/dodal/devices/i19/access_controlled/attenuator_motor_squad.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,16 @@ class AttenuatorMotorPositionDemands(BaseModel):
1818

1919
@model_validator(mode="after")
2020
def no_keys_clash(self) -> Self:
21-
common_key_filter = filter(
22-
lambda k: k in self.continuous_demands, self.indexed_demands
23-
)
24-
common_key_count = sum(1 for _ in common_key_filter)
21+
common_keys = set(self.continuous_demands).intersection(self.indexed_demands)
22+
common_key_count = sum(1 for _ in common_keys)
2523
if common_key_count < 1:
2624
return self
2725
else:
2826
ks: str = "key" if common_key_count == 1 else "keys"
29-
error_msg = (
30-
f"{common_key_count} common {ks} found in distinct motor demands"
31-
)
27+
error_msg = f"Common {ks} found in distinct motor demands: {common_keys}"
3228
raise ValueError(error_msg)
3329

34-
def restful_format(self) -> dict[PermittedKeyStr, Any]:
30+
def validated_complete_demand(self) -> dict[PermittedKeyStr, Any]:
3531
return self.continuous_demands | self.indexed_demands
3632

3733

@@ -56,9 +52,9 @@ async def set(self, value: AttenuatorMotorPositionDemands):
5652
request_params = {
5753
"name": "operate_motor_squad_plan",
5854
"params": {
59-
"experiment_hutch": self._get_invoking_hutch(),
55+
"experiment_hutch": self._invoking_hutch,
6056
"access_device": ACCESS_DEVICE_NAME,
61-
"attenuator_demands": value.restful_format(),
57+
"attenuator_demands": value.validated_complete_demand(),
6258
},
6359
"instrument_session": self.instrument_session,
6460
}

src/dodal/devices/i19/access_controlled/blueapi_device.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ def __init__(
3838
self.headers = HEADERS
3939
super().__init__(name)
4040

41-
def _get_invoking_hutch(self) -> str:
41+
@property
42+
def _invoking_hutch(self) -> str:
4243
return self.hutch_request.value
4344

4445
@AsyncStatus.wrap

src/dodal/devices/i19/access_controlled/shutter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async def set(self, value: ShutterDemand):
4343
request_params = {
4444
"name": "operate_shutter_plan",
4545
"params": {
46-
"experiment_hutch": self._get_invoking_hutch(),
46+
"experiment_hutch": self._invoking_hutch,
4747
"access_device": ACCESS_DEVICE_NAME,
4848
"shutter_demand": value.value,
4949
},

tests/devices/i19/access_controlled/test_attenuator_motor_squad.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
def given_position_demands() -> AttenuatorMotorPositionDemands:
1515
position_demand = MagicMock()
1616
restful_payload = {"x": 54.3, "y": 72.1, "w": 4}
17-
position_demand.restful_format = MagicMock(return_value=restful_payload)
17+
position_demand.validated_complete_demand = MagicMock(return_value=restful_payload)
1818
return position_demand
1919

2020

tests/devices/i19/access_controlled/test_attenuator_position_demand.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_that_attenuator_position_demand_with_only_one_wedge_provides_expected_r
2222
continuous_demands=wedge_position_demands,
2323
indexed_demands=wheel_position_demands,
2424
)
25-
restful_payload = position_demand.restful_format()
25+
restful_payload = position_demand.validated_complete_demand()
2626
assert restful_payload["y"] == 14.9
2727

2828

@@ -43,7 +43,7 @@ def test_that_attenuator_position_demand_with_only_one_wheel_provides_expected_r
4343
continuous_demands=wedge_position_demands,
4444
indexed_demands=wheel_position_demands,
4545
)
46-
restful_payload = position_demand.restful_format()
46+
restful_payload = position_demand.validated_complete_demand()
4747
assert restful_payload["w"] == 6
4848

4949

@@ -64,7 +64,7 @@ def test_that_empty_attenuator_position_demand_provides_empty_rest_format():
6464
continuous_demands=wedge_position_demands,
6565
indexed_demands=wheel_position_demands,
6666
)
67-
restful_payload = position_demand.restful_format()
67+
restful_payload = position_demand.validated_complete_demand()
6868
assert restful_payload == {}
6969

7070

@@ -85,7 +85,7 @@ def test_that_attenuator_position_demand_triplet_provides_expected_rest_format()
8585
continuous_demands=wedge_position_demands,
8686
indexed_demands=wheel_position_demands,
8787
)
88-
restful_payload = position_demand.restful_format()
88+
restful_payload = position_demand.validated_complete_demand()
8989
assert restful_payload == {"x": 0.1, "y": 90.1, "w": 6}
9090

9191

@@ -97,13 +97,8 @@ def test_that_attenuator_position_demand_triplet_provides_expected_rest_format()
9797
def test_that_attenuator_position_raises_error_when_discrete_and_continuous_demands_overload_axis_label():
9898
wedge_position_demands = {"x": 0.1, "v": 90.1}
9999
wheel_position_demands = {"w": 6, "v": 7}
100-
preamble: str = (
101-
"1 validation error for AttenuatorMotorPositionDemands\n Value error,"
102-
)
103-
anticipated_message: str = (
104-
f"{preamble} 1 common key found in distinct motor demands"
105-
)
106-
with pytest.raises(expected_exception=ValueError, match=anticipated_message):
100+
anticipated_preamble: str = "1 validation error for AttenuatorMotorPositionDemands"
101+
with pytest.raises(expected_exception=ValueError, match=anticipated_preamble):
107102
AttenuatorMotorPositionDemands(
108103
continuous_demands=wedge_position_demands,
109104
indexed_demands=wheel_position_demands,

0 commit comments

Comments
 (0)