Skip to content

Commit 59cb2b0

Browse files
committed
FIX: fix pylint and ruff checks
1 parent 1792b1c commit 59cb2b0

File tree

6 files changed

+30
-17
lines changed

6 files changed

+30
-17
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repos:
1818
- id: check-yaml
1919

2020
- repo: https://github.com/astral-sh/ruff-pre-commit
21-
rev: v0.9.1
21+
rev: v0.9.2
2222
hooks:
2323
- id: ruff
2424
args: [ --fix ]

ardupilot_methodic_configurator/frontend_tkinter_base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,16 @@ def on_mouse_wheel(self, event: tk.Event) -> None: # cross platform scroll whee
189189

190190
if rows_height > canvas_height: # only scroll if the rows overflow the frame
191191
if platform_system() == "Windows":
192+
# Windows: positive delta means scroll up, negative means scroll down
192193
self.canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")
193194
elif platform_system() == "Darwin":
195+
# macOS: similar to Windows but different scaling
194196
self.canvas.yview_scroll(int(-1 * event.delta), "units")
195197
elif event.num == 4:
198+
# Linux: Button-4 means scroll up
196199
self.canvas.yview_scroll(-1, "units")
197200
elif event.num == 5:
201+
# Linux: Button-5 means scroll down
198202
self.canvas.yview_scroll(1, "units")
199203

200204
def on_enter(self, _event: tk.Event) -> None: # bind wheel events when the cursor enters the control

tests/test_annotate_params.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ def test_split_into_lines_edge_cases(self) -> None:
594594
def test_format_columns_edge_cases(self) -> None:
595595
"""Test format_columns with edge cases."""
596596
# Empty dictionary
597-
assert format_columns({}) == []
597+
assert not format_columns({})
598598

599599
# Single item
600600
assert format_columns({"Key": "Value"}) == ["Key: Value"]
@@ -612,11 +612,11 @@ def test_create_doc_dict_edge_cases(self) -> None:
612612
"""Test create_doc_dict with edge cases."""
613613
# Test with empty XML
614614
empty_root = ET.Element("root")
615-
assert create_doc_dict(empty_root, "ArduCopter") == {}
615+
assert not create_doc_dict(empty_root, "ArduCopter")
616616

617617
# Test with missing attributes
618618
param = ET.SubElement(empty_root, "param")
619-
assert create_doc_dict(empty_root, "ArduCopter") == {}
619+
assert not create_doc_dict(empty_root, "ArduCopter")
620620

621621
# Test with minimal valid param
622622
param.set("name", "TEST_PARAM")

tests/test_backend_filesystem.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from ardupilot_methodic_configurator.backend_filesystem import LocalFilesystem
1818

1919

20-
class TestLocalFilesystem(unittest.TestCase):
20+
class TestLocalFilesystem(unittest.TestCase): # pylint: disable=too-many-public-methods
2121
"""LocalFilesystem test class."""
2222

2323
@patch("os.path.isdir")
@@ -280,7 +280,7 @@ def test_write_and_read_last_uploaded_filename(self) -> None:
280280

281281
# Test reading
282282
with patch("builtins.open", unittest.mock.mock_open(read_data=test_filename)) as mock_file:
283-
result = lfs._LocalFilesystem__read_last_uploaded_filename()
283+
result = lfs._LocalFilesystem__read_last_uploaded_filename() # pylint: disable=protected-access
284284
assert result == test_filename
285285
mock_file.assert_called_once_with(expected_path, encoding="utf-8")
286286

@@ -322,7 +322,7 @@ def test_get_eval_variables(self) -> None:
322322

323323
# Test with empty components and doc_dict
324324
result = lfs.get_eval_variables()
325-
assert result == {}
325+
assert not result
326326

327327
# Test with components and doc_dict
328328
lfs.vehicle_components = {"Components": {"test": "value"}}
@@ -457,7 +457,7 @@ def test_all_intermediate_parameter_file_comments(self) -> None:
457457
"file2.param": {"PARAM2": MagicMock(comment="Override comment 2"), "PARAM3": MagicMock(comment="Comment 3")},
458458
}
459459

460-
result = lfs._LocalFilesystem__all_intermediate_parameter_file_comments()
460+
result = lfs._LocalFilesystem__all_intermediate_parameter_file_comments() # pylint: disable=protected-access
461461
assert result == {"PARAM1": "Comment 1", "PARAM2": "Override comment 2", "PARAM3": "Comment 3"}
462462

463463

tests/test_frontend_tkinter_base.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from tkinter import ttk
1717
from unittest.mock import MagicMock, patch
1818

19+
import pytest
20+
1921
from ardupilot_methodic_configurator.frontend_tkinter_base import (
2022
AutoResizeCombobox,
2123
BaseWindow,
@@ -471,7 +473,7 @@ def test_put_image_in_label(self, mock_label, mock_photo, mock_open) -> None:
471473

472474
# Set up PhotoImage mock
473475
mock_photo_instance = MagicMock()
474-
mock_photo_instance._PhotoImage__photo = "photo1" # Required for Tkinter
476+
mock_photo_instance._PhotoImage__photo = "photo1" # pylint: disable=protected-access
475477
mock_photo.return_value = mock_photo_instance
476478

477479
# Set up Label mock
@@ -495,6 +497,13 @@ def test_window_title(self) -> None:
495497
assert self.base_window.root.title() == title
496498

497499

500+
@pytest.fixture
501+
def mock_set_display() -> MagicMock:
502+
"""Mock the set_display_usage_popup method."""
503+
with patch("ardupilot_methodic_configurator.frontend_tkinter_base.ProgramSettings.set_display_usage_popup") as mock_fun:
504+
yield mock_fun
505+
506+
498507
class TestUsagePopupWindow(unittest.TestCase):
499508
"""Test cases for the UsagePopupWindow class."""
500509

@@ -513,8 +522,8 @@ def test_should_display(self, mock_display_popup) -> None:
513522
mock_display_popup.assert_called_once_with("test_type")
514523

515524
@patch("tkinter.BooleanVar")
516-
@patch("ardupilot_methodic_configurator.frontend_tkinter_base.ProgramSettings.set_display_usage_popup")
517-
def test_display_popup(self, mock_set_display, mock_bool_var) -> None:
525+
@pytest.mark.usefixtures("mock_set_display")
526+
def test_display_popup(self, mock_bool_var) -> None:
518527
"""Test display method."""
519528
mock_bool_var.return_value.get.return_value = True
520529
usage_window = BaseWindow(self.root)

tests/test_param_pid_adjustment_update.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_invalid_input(self) -> None:
7474

7575
def test_empty_file(self) -> None:
7676
# Create an empty temporary file
77-
with open("temp.param", "w", encoding="utf-8") as f: # noqa: F841
77+
with open("temp.param", "w", encoding="utf-8") as _f:
7878
pass
7979

8080
# Call the function and check the result
@@ -274,9 +274,9 @@ def test_parameter_missing_from_optimized_file(self) -> None:
274274

275275
def test_empty_files(self) -> None:
276276
# Both the default and optimized parameter files are empty
277-
with open(self.default_param_file, "w", encoding="utf-8") as f: # F841
277+
with open(self.default_param_file, "w", encoding="utf-8") as _f: # F841
278278
pass
279-
with open(self.optimized_param_file, "w", encoding="utf-8") as f: # noqa: F841
279+
with open(self.optimized_param_file, "w", encoding="utf-8") as _f:
280280
pass
281281
with pytest.raises(SystemExit) as cm:
282282
update_pid_adjustment_params(self.test_dir, os.path.basename(self.optimized_param_file), 0.5)
@@ -286,7 +286,7 @@ def test_empty_files(self) -> None:
286286

287287
def test_empty_default_file(self) -> None:
288288
# Create an empty default parameter file
289-
with open(self.default_param_file, "w", encoding="utf-8") as f: # noqa: F841
289+
with open(self.default_param_file, "w", encoding="utf-8") as _f:
290290
pass
291291
with pytest.raises(SystemExit) as cm:
292292
update_pid_adjustment_params(self.test_dir, os.path.basename(self.optimized_param_file), 0.5)
@@ -296,7 +296,7 @@ def test_empty_default_file(self) -> None:
296296

297297
def test_empty_optimized_file(self) -> None:
298298
# Create an empty optimized parameter file
299-
with open(self.optimized_param_file, "w", encoding="utf-8") as f: # noqa: F841
299+
with open(self.optimized_param_file, "w", encoding="utf-8") as _f:
300300
pass
301301
with pytest.raises(SystemExit) as cm:
302302
update_pid_adjustment_params(self.test_dir, os.path.basename(self.optimized_param_file), 0.5)
@@ -307,7 +307,7 @@ def test_empty_optimized_file(self) -> None:
307307

308308
def test_empty_adjustment_file(self) -> None:
309309
# Create an empty adjustment parameter file
310-
with open(self.adjustment_param_file, "w", encoding="utf-8") as f: # noqa: F841
310+
with open(self.adjustment_param_file, "w", encoding="utf-8") as _f:
311311
pass
312312
with pytest.raises(SystemExit) as cm:
313313
update_pid_adjustment_params(self.test_dir, os.path.basename(self.optimized_param_file), 0.5)

0 commit comments

Comments
 (0)