Skip to content

Commit 98648b4

Browse files
committed
fix(ty): fix issues found by ty 0.0.32 type linter
1 parent a88a043 commit 98648b4

6 files changed

Lines changed: 44 additions & 40 deletions

tests/test_backend_filesystem.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,13 +531,13 @@ def test_tolerance_check_with_zero_values(self) -> None:
531531
# Test writing
532532
test_filename = "test_param.param"
533533
expected_path = os_path.join("vehicle_dir", "last_uploaded_filename.txt")
534-
with patch("builtins.open", unittest.mock.mock_open()) as mock_file:
534+
with patch("builtins.open", mock_open()) as mock_file:
535535
lfs.write_last_uploaded_filename(test_filename)
536536
mock_file.assert_called_once_with(expected_path, "w", encoding="utf-8", newline="\n")
537537
mock_file().write.assert_called_once_with(test_filename)
538538

539539
# Test reading
540-
with patch("builtins.open", unittest.mock.mock_open(read_data=test_filename)) as mock_file:
540+
with patch("builtins.open", mock_open(read_data=test_filename)) as mock_file:
541541
result = lfs._LocalFilesystem__read_last_uploaded_filename() # pylint: disable=protected-access
542542
assert result == test_filename
543543
mock_file.assert_called_once_with(expected_path, encoding="utf-8")

tests/test_backend_filesystem_configuration_steps.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import unittest
1414
from json import JSONDecodeError
15-
from unittest.mock import mock_open, patch
15+
from unittest.mock import Mock, call, mock_open, patch
1616

1717
from ardupilot_methodic_configurator.backend_filesystem_configuration_steps import ConfigurationSteps
1818

@@ -31,10 +31,10 @@ def setUp(self) -> None:
3131
@patch("os.path.abspath")
3232
def test_re_init(
3333
self,
34-
mock_abspath: unittest.mock.Mock,
35-
mock_dirname: unittest.mock.Mock,
36-
mock_join: unittest.mock.Mock,
37-
mock_open2: unittest.mock.Mock,
34+
mock_abspath: Mock,
35+
mock_dirname: Mock,
36+
mock_join: Mock,
37+
mock_open2: Mock,
3838
) -> None:
3939
mock_abspath.return_value = "abs_path"
4040
mock_dirname.return_value = "dir_name"
@@ -43,8 +43,8 @@ def test_re_init(
4343
assert self.config_steps.configuration_steps
4444
mock_open2.assert_has_calls(
4545
[
46-
unittest.mock.call("vehicle_dir/configuration_steps_vehicle_type.json", encoding="utf-8-sig"),
47-
unittest.mock.call("dir_name/configuration_steps_schema.json", encoding="utf-8"),
46+
call("vehicle_dir/configuration_steps_vehicle_type.json", encoding="utf-8-sig"),
47+
call("dir_name/configuration_steps_schema.json", encoding="utf-8"),
4848
],
4949
any_order=True,
5050
)

tests/test_backend_flightcontroller_connection.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616
from __future__ import annotations
1717

1818
from time import time as real_time
19-
from typing import NoReturn
19+
from typing import TYPE_CHECKING, NoReturn, Optional
2020
from unittest.mock import Mock, patch
2121

2222
import pytest
2323
import serial.tools.list_ports_common
2424
from pymavlink import mavutil
2525

26+
if TYPE_CHECKING:
27+
from ardupilot_methodic_configurator.backend_flightcontroller_protocols import MavlinkConnection
28+
2629
from ardupilot_methodic_configurator.backend_flightcontroller_connection import (
2730
DEFAULT_BAUDRATE,
2831
SUPPORTED_BAUDRATES,
@@ -855,14 +858,14 @@ def test_failed_connection_includes_root_cause(self) -> None:
855858
class ExplodingFactory(SystemMavlinkConnectionFactory): # pylint: disable=too-few-public-methods
856859
"""MAVLink factory that always raises ConnectionError."""
857860

858-
def create( # type: ignore[override] # pylint: disable=too-many-arguments, too-many-positional-arguments
861+
def create( # pylint: disable=too-many-arguments, too-many-positional-arguments
859862
self,
860863
device: str,
861864
baudrate: int,
862865
timeout: float = 5.0,
863866
retries: int = 3,
864-
progress_callback: object = None,
865-
) -> object:
867+
progress_callback: Optional[object] = None, # noqa: UP045
868+
) -> Optional[MavlinkConnection]: # noqa: UP045
866869
_ = (baudrate, timeout, retries, progress_callback)
867870
msg = f"{device}: Permission denied"
868871
raise ConnectionError(msg)

tests/test_extract_param_defaults.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"""
1212

1313
import unittest
14-
from unittest.mock import MagicMock, Mock, patch
14+
from unittest.mock import MagicMock, Mock, call, patch
1515

1616
import pytest
1717

@@ -297,7 +297,7 @@ def test_output_params(self, mock_print_) -> None:
297297
output_params(defaults, "missionplanner")
298298

299299
# Check if the print function was called with the correct parameters
300-
expected_calls = [unittest.mock.call("PARAM2,1"), unittest.mock.call("PARAM1,2")]
300+
expected_calls = [call("PARAM2,1"), call("PARAM1,2")]
301301
mock_print_.assert_has_calls(expected_calls, any_order=False)
302302

303303
@patch("builtins.print")
@@ -309,7 +309,7 @@ def test_output_params_missionplanner_non_numeric(self, mock_print_) -> None:
309309
output_params(defaults, "missionplanner")
310310

311311
# Check if the print function was called with the correct parameters
312-
expected_calls = [unittest.mock.call("PARAM1,non-numeric")]
312+
expected_calls = [call("PARAM1,non-numeric")]
313313
mock_print_.assert_has_calls(expected_calls, any_order=False)
314314

315315
@patch("builtins.print")
@@ -323,8 +323,8 @@ def test_output_params_mavproxy(self, mock_print_) -> None:
323323

324324
# Check if the print function was called with the correct parameters
325325
expected_calls = [
326-
unittest.mock.call("%-15s %.6f" % ("PARAM1", 1.0)), # pylint: disable=consider-using-f-string
327-
unittest.mock.call("%-15s %.6f" % ("PARAM2", 2.0)), # pylint: disable=consider-using-f-string
326+
call("%-15s %.6f" % ("PARAM1", 1.0)), # pylint: disable=consider-using-f-string
327+
call("%-15s %.6f" % ("PARAM2", 2.0)), # pylint: disable=consider-using-f-string
328328
]
329329
mock_print_.assert_has_calls(expected_calls, any_order=False)
330330

@@ -339,9 +339,9 @@ def test_output_params_qgcs(self, mock_print_) -> None:
339339

340340
# Check if the print function was called with the correct parameters
341341
expected_calls = [
342-
unittest.mock.call("\n# # Vehicle-Id Component-Id Name Value Type\n"),
343-
unittest.mock.call("%u %u %-15s %.6f %u" % (1, 1, "PARAM1", 1.0, 9)), # pylint: disable=consider-using-f-string
344-
unittest.mock.call("%u %u %-15s %.6f %u" % (1, 1, "PARAM2", 2.0, 9)), # pylint: disable=consider-using-f-string
342+
call("\n# # Vehicle-Id Component-Id Name Value Type\n"),
343+
call("%u %u %-15s %.6f %u" % (1, 1, "PARAM1", 1.0, 9)), # pylint: disable=consider-using-f-string
344+
call("%u %u %-15s %.6f %u" % (1, 1, "PARAM2", 2.0, 9)), # pylint: disable=consider-using-f-string
345345
]
346346
mock_print_.assert_has_calls(expected_calls, any_order=False)
347347

@@ -356,9 +356,9 @@ def test_output_params_qgcs_2_4(self, mock_print_) -> None:
356356

357357
# Check if the print function was called with the correct parameters
358358
expected_calls = [
359-
unittest.mock.call("\n# # Vehicle-Id Component-Id Name Value Type\n"),
360-
unittest.mock.call("%u %u %-15s %.6f %u" % (2, 4, "PARAM1", 1.0, 9)), # pylint: disable=consider-using-f-string
361-
unittest.mock.call("%u %u %-15s %.6f %u" % (2, 4, "PARAM2", 2.0, 9)), # pylint: disable=consider-using-f-string
359+
call("\n# # Vehicle-Id Component-Id Name Value Type\n"),
360+
call("%u %u %-15s %.6f %u" % (2, 4, "PARAM1", 1.0, 9)), # pylint: disable=consider-using-f-string
361+
call("%u %u %-15s %.6f %u" % (2, 4, "PARAM2", 2.0, 9)), # pylint: disable=consider-using-f-string
362362
]
363363
mock_print_.assert_has_calls(expected_calls, any_order=False)
364364

@@ -373,10 +373,10 @@ def test_output_params_qgcs_SYSID_THISMAV(self, mock_print_) -> None: # noqa: N
373373

374374
# Check if the print function was called with the correct parameters
375375
expected_calls = [
376-
unittest.mock.call("\n# # Vehicle-Id Component-Id Name Value Type\n"),
377-
unittest.mock.call("%u %u %-15s %.6f %u" % (3, 7, "PARAM1", 1.0, 9)), # pylint: disable=consider-using-f-string
378-
unittest.mock.call("%u %u %-15s %.6f %u" % (3, 7, "PARAM2", 2.0, 9)), # pylint: disable=consider-using-f-string
379-
unittest.mock.call("%u %u %-15s %.6f %u" % (3, 7, "SYSID_THISMAV", 3.0, 9)), # pylint: disable=consider-using-f-string
376+
call("\n# # Vehicle-Id Component-Id Name Value Type\n"),
377+
call("%u %u %-15s %.6f %u" % (3, 7, "PARAM1", 1.0, 9)), # pylint: disable=consider-using-f-string
378+
call("%u %u %-15s %.6f %u" % (3, 7, "PARAM2", 2.0, 9)), # pylint: disable=consider-using-f-string
379+
call("%u %u %-15s %.6f %u" % (3, 7, "SYSID_THISMAV", 3.0, 9)), # pylint: disable=consider-using-f-string
380380
]
381381
mock_print_.assert_has_calls(expected_calls, any_order=False)
382382

@@ -420,7 +420,7 @@ def test_output_params_integer(self, mock_print_) -> None:
420420
output_params(defaults, "missionplanner")
421421

422422
# Check if the print function was called with the correct parameters
423-
expected_calls = [unittest.mock.call("PARAM1,1.01"), unittest.mock.call("PARAM2,2")]
423+
expected_calls = [call("PARAM1,1.01"), call("PARAM2,2")]
424424
mock_print_.assert_has_calls(expected_calls, any_order=False)
425425

426426
@patch("builtins.print")

tests/test_frontend_tkinter_stage_progress.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import tkinter as tk
1414
from collections.abc import Generator
15+
from tkinter import ttk
1516

1617
import pytest
1718

@@ -244,7 +245,7 @@ def test_user_sees_labels_adjust_when_window_resizes(self, progress_bar) -> None
244245
initial_wraplengths = {}
245246
for phase_name, frame in progress_bar.phase_frames.items():
246247
for child in frame.winfo_children():
247-
if isinstance(child, tk.ttk.Label):
248+
if isinstance(child, ttk.Label):
248249
initial_wraplengths[phase_name] = child.cget("wraplength")
249250

250251
# Simulate window resize by updating width and calling resize handler
@@ -254,7 +255,7 @@ def test_user_sees_labels_adjust_when_window_resizes(self, progress_bar) -> None
254255
# Verify wraplength has been updated for all phase labels
255256
for phase_name, frame in progress_bar.phase_frames.items():
256257
for child in frame.winfo_children():
257-
if isinstance(child, tk.ttk.Label):
258+
if isinstance(child, ttk.Label):
258259
# Wraplength should be set to a positive value
259260
current_wraplength = child.cget("wraplength")
260261
initial_wraplength = initial_wraplengths[phase_name]
@@ -283,10 +284,10 @@ def test_user_sees_optional_phases_displayed_in_gray(self, progress_bar) -> None
283284
optional_label = None
284285
normal_label = None
285286
for child in optional_frame.winfo_children():
286-
if isinstance(child, tk.ttk.Label):
287+
if isinstance(child, ttk.Label):
287288
optional_label = child
288289
for child in normal_frame.winfo_children():
289-
if isinstance(child, tk.ttk.Label):
290+
if isinstance(child, ttk.Label):
290291
normal_label = child
291292

292293
assert optional_label is not None
@@ -314,9 +315,9 @@ def test_user_sees_correct_frame_structure_for_each_phase(self, progress_bar) ->
314315
progressbar = None
315316
label = None
316317
for child in children:
317-
if isinstance(child, tk.ttk.Progressbar):
318+
if isinstance(child, ttk.Progressbar):
318319
progressbar = child
319-
elif isinstance(child, tk.ttk.Label):
320+
elif isinstance(child, ttk.Label):
320321
label = child
321322

322323
assert progressbar is not None, "Progressbar should exist"
@@ -363,7 +364,7 @@ def test_user_sees_very_short_labels_formatted_with_padding(self, root_window) -
363364
frame = progress.phase_frames["A"]
364365
label = None
365366
for child in frame.winfo_children():
366-
if isinstance(child, tk.ttk.Label):
367+
if isinstance(child, ttk.Label):
367368
label = child
368369
break
369370

@@ -385,7 +386,7 @@ def test_user_sees_short_labels_formatted_with_newlines(self, root_window) -> No
385386
frame = progress.phase_frames["Short"]
386387
label = None
387388
for child in frame.winfo_children():
388-
if isinstance(child, tk.ttk.Label):
389+
if isinstance(child, ttk.Label):
389390
label = child
390391
break
391392

@@ -407,7 +408,7 @@ def test_user_sees_medium_labels_with_spaces_split_at_first_space(self, root_win
407408
frame = progress.phase_frames["Medium Text"]
408409
label = None
409410
for child in frame.winfo_children():
410-
if isinstance(child, tk.ttk.Label):
411+
if isinstance(child, ttk.Label):
411412
label = child
412413
break
413414

tests/unit_frontend_tkinter_software_update.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import tkinter as tk
1414
import unittest
15-
from unittest.mock import MagicMock, patch
15+
from unittest.mock import MagicMock, call, patch
1616

1717
from ardupilot_methodic_configurator.frontend_tkinter_base_window import BaseWindow
1818
from ardupilot_methodic_configurator.frontend_tkinter_software_update import UpdateDialog
@@ -141,7 +141,7 @@ def test_init_window_config(self) -> None:
141141

142142
# Check that grid_columnconfigure was called exactly twice with the right arguments
143143
assert dialog.frame.grid_columnconfigure.call_count == 2 # pylint: disable=no-member
144-
dialog.frame.grid_columnconfigure.assert_has_calls([unittest.mock.call(0, weight=1), unittest.mock.call(1, weight=1)]) # pylint: disable=no-member
144+
dialog.frame.grid_columnconfigure.assert_has_calls([call(0, weight=1), call(1, weight=1)]) # pylint: disable=no-member
145145

146146
def test_init_scroll_frame(self) -> None:
147147
"""Test ScrollFrame setup during initialization."""

0 commit comments

Comments
 (0)