Skip to content

Commit d851237

Browse files
authored
Check knob and button IDs separately for conflicts (#105)
Closes #104 As noted in [#104 (comment)](#104 (comment)), the validator attempts to ensure that the knob and button IDs are unique jointly, but the IDs of the knobs and those of the buttons actually overlap in the controller (see the controller definition [here](https://github.com/napari/midi-app-controller/blob/0e5029961aa2bc30fec743cb4dba30b427dd407c/midi_app_controller/config_files/controllers/x_touch_mini.yaml)). This PR therefore removes the Pydantic requirement for the button IDs to not clash with the knob IDs.
1 parent cd96bf0 commit d851237

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

midi_app_controller/models/_tests/test_binds.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ def test_valid_binds(binds_data):
5959
},
6060
],
6161
),
62+
],
63+
)
64+
def test_binds_duplicate_id(binds_data, button_binds, knob_binds):
65+
binds_data["button_binds"] = button_binds
66+
binds_data["knob_binds"] = knob_binds
67+
68+
with pytest.raises(ValidationError):
69+
Binds(**binds_data)
70+
71+
72+
@pytest.mark.parametrize(
73+
"button_binds, knob_binds",
74+
[
6275
(
6376
[{"button_id": 1, "action_id": "Action1"}],
6477
[
@@ -71,12 +84,10 @@ def test_valid_binds(binds_data):
7184
),
7285
],
7386
)
74-
def test_binds_duplicate_id(binds_data, button_binds, knob_binds):
87+
def test_allow_knob_button_collision(binds_data, button_binds, knob_binds):
7588
binds_data["button_binds"] = button_binds
7689
binds_data["knob_binds"] = knob_binds
77-
78-
with pytest.raises(ValidationError):
79-
Binds(**binds_data)
90+
Binds(**binds_data)
8091

8192

8293
@pytest.mark.parametrize("id", [-1, 128])

midi_app_controller/models/binds.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,14 @@ def check_duplicate_ids(cls, values):
6969
button_ids = [bind.button_id for bind in values.button_binds]
7070
knob_ids = [bind.knob_id for bind in values.knob_binds]
7171

72-
duplicate = find_duplicate(button_ids + knob_ids)
73-
if duplicate is not None:
74-
raise ValueError(f"id={duplicate} was bound to multiple actions")
72+
duplicate_buttons = find_duplicate(button_ids)
73+
if duplicate_buttons is not None:
74+
raise ValueError(
75+
f"button id={duplicate_buttons} was bound to multiple actions"
76+
)
77+
78+
duplicate_knobs = find_duplicate(knob_ids)
79+
if duplicate_knobs is not None:
80+
raise ValueError(f"knob id={duplicate_knobs} was bound to multiple actions")
7581

7682
return values

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ midi-app-controller = "midi_app_controller:napari.yaml"
3535
testing = [
3636
"pytest>=8.2.0",
3737
"pytest-cov>=5.0.0",
38-
"pytest-qt>=4.0.2"
38+
"pytest-qt>=4.0.2",
39+
"flexparser!=0.4.0" # see https://napari.zulipchat.com/#narrow/channel/212875-general/topic/broken.20pint.2Fflexparser/near/481110284
3940
]
4041
dev = [
4142
"midi-app-controller[testing]",

0 commit comments

Comments
 (0)