Skip to content

Commit 8e287f4

Browse files
committed
Apply static analysis
1 parent 41ff89d commit 8e287f4

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

src/ephys_link/utils/constants.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ def client_disconnected_without_being_connected_error(client_sid: str) -> str:
9191
"Unable to check for updates. Ignore updates or use the the -i flag to disable checks.\n"
9292
)
9393

94-
def ump_4_3_deprecation_error(cli_name: str):
95-
return f"CLI option '{cli_name}' is deprecated and will be removed in v3.0.0. Use 'ump' instead.",
94+
95+
def ump_4_3_deprecation_error(cli_name: str):
96+
return f"CLI option '{cli_name}' is deprecated and will be removed in v3.0.0. Use 'ump' instead."
97+
9698

9799
def unrecognized_platform_type_error(cli_name: str) -> str:
98100
"""Generate an error message for when the platform type is not recognized.
@@ -101,4 +103,4 @@ def unrecognized_platform_type_error(cli_name: str) -> str:
101103
Returns:
102104
str: The error message.
103105
"""
104-
return f'Platform type "{cli_name}" not recognized.'
106+
return f'Platform type "{cli_name}" not recognized.'

src/ephys_link/utils/startup.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212
from ephys_link.bindings.mpm_binding import MPMBinding
1313
from ephys_link.front_end.console import Console
1414
from ephys_link.utils.base_binding import BaseBinding
15-
from ephys_link.utils.constants import ASCII, BINDINGS_DIRECTORY, ump_4_3_deprecation_error, \
16-
unrecognized_platform_type_error
15+
from ephys_link.utils.constants import (
16+
ASCII,
17+
BINDINGS_DIRECTORY,
18+
ump_4_3_deprecation_error,
19+
unrecognized_platform_type_error,
20+
)
1721

1822

1923
def preamble() -> None:

tests/utils/test_startup.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99
from ephys_link.__about__ import __version__
1010
from ephys_link.bindings.fake_binding import FakeBinding
1111
from ephys_link.bindings.mpm_binding import MPMBinding
12-
from ephys_link.bindings.ump_binding import UmpBinding
1312
from ephys_link.front_end.console import Console
1413
from ephys_link.utils.base_binding import BaseBinding
15-
from ephys_link.utils.constants import ASCII, UNABLE_TO_CHECK_FOR_UPDATES_ERROR, ump_4_3_deprecation_error, \
16-
unrecognized_platform_type_error
17-
from ephys_link.utils.startup import check_for_updates, get_bindings, preamble, get_binding_instance
14+
from ephys_link.utils.constants import (
15+
ASCII,
16+
UNABLE_TO_CHECK_FOR_UPDATES_ERROR,
17+
ump_4_3_deprecation_error,
18+
unrecognized_platform_type_error,
19+
)
20+
from ephys_link.utils.startup import check_for_updates, get_binding_instance, get_bindings, preamble
1821

1922

2023
class TestStartup:
@@ -99,9 +102,11 @@ def test_get_bindings_returns_valid_bindings(self):
99102
assert isinstance(bindings, list)
100103
assert all(issubclass(b, BaseBinding) for b in bindings)
101104
assert BaseBinding not in bindings
102-
103-
@pytest.mark.parametrize("cli_name,binding", [("fake", FakeBinding), ("pathfinder-mpm", MPMBinding)])
104-
def test_get_binding_instance(self, cli_name:str, binding:BaseBinding, console: Console, mocker: MockerFixture):
105+
106+
@pytest.mark.parametrize(("cli_name", "binding"), [("fake", FakeBinding), ("pathfinder-mpm", MPMBinding)])
107+
def test_get_binding_instance(
108+
self, cli_name: str, binding: FakeBinding | MPMBinding, console: Console, mocker: MockerFixture
109+
):
105110
"""Test that get_binding_instance returns an instance of the requested binding class."""
106111
# Arrange.
107112
spied_error_print = mocker.spy(console, "error_print")
@@ -111,20 +116,21 @@ def test_get_binding_instance(self, cli_name:str, binding:BaseBinding, console:
111116
binding_instance = get_binding_instance(fake_options, console)
112117

113118
# Assert.
114-
assert isinstance(binding_instance, binding)
119+
# noinspection PyTypeChecker
120+
assert isinstance(binding_instance, binding) # pyright: ignore [reportArgumentType]
115121
spied_error_print.assert_not_called()
116-
122+
117123
@pytest.mark.parametrize("cli_name", ["ump-4", "ump-3"])
118124
def test_get_binding_instance_ump(self, cli_name: str, console: Console, mocker: MockerFixture):
119125
"""Test that get_binding_instance returns an instance of the UmpBinding class and handles deprecation."""
120126
# Arrange.
121127
spied_error_print = mocker.spy(console, "error_print")
122128
fake_options = EphysLinkOptions(type=cli_name)
123-
mock_ump = mocker.patch("ephys_link.bindings.ump_binding.UmpBinding", autospec=True)
129+
_ = mocker.patch("ephys_link.bindings.ump_binding.UmpBinding", autospec=True)
124130

125131
# Act.
126-
with pytest.raises(ValueError) as e:
127-
get_binding_instance(fake_options, console)
132+
with pytest.raises(ValueError, match=unrecognized_platform_type_error("ump")) as e:
133+
_ = get_binding_instance(fake_options, console)
128134

129135
# Assert.
130136
spied_error_print.assert_called_once_with("DEPRECATION", ump_4_3_deprecation_error(cli_name))

0 commit comments

Comments
 (0)