Skip to content

Commit

Permalink
FIX: fix pylint and ruff checks
Browse files Browse the repository at this point in the history
  • Loading branch information
amilcarlucas committed Jan 18, 2025
1 parent 1792b1c commit 59cb2b0
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
- id: check-yaml

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.1
rev: v0.9.2
hooks:
- id: ruff
args: [ --fix ]
Expand Down
4 changes: 4 additions & 0 deletions ardupilot_methodic_configurator/frontend_tkinter_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,16 @@ def on_mouse_wheel(self, event: tk.Event) -> None: # cross platform scroll whee

if rows_height > canvas_height: # only scroll if the rows overflow the frame
if platform_system() == "Windows":
# Windows: positive delta means scroll up, negative means scroll down
self.canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")
elif platform_system() == "Darwin":
# macOS: similar to Windows but different scaling
self.canvas.yview_scroll(int(-1 * event.delta), "units")
elif event.num == 4:
# Linux: Button-4 means scroll up
self.canvas.yview_scroll(-1, "units")
elif event.num == 5:
# Linux: Button-5 means scroll down
self.canvas.yview_scroll(1, "units")

def on_enter(self, _event: tk.Event) -> None: # bind wheel events when the cursor enters the control
Expand Down
6 changes: 3 additions & 3 deletions tests/test_annotate_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def test_split_into_lines_edge_cases(self) -> None:
def test_format_columns_edge_cases(self) -> None:
"""Test format_columns with edge cases."""
# Empty dictionary
assert format_columns({}) == []
assert not format_columns({})

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

# Test with missing attributes
param = ET.SubElement(empty_root, "param")
assert create_doc_dict(empty_root, "ArduCopter") == {}
assert not create_doc_dict(empty_root, "ArduCopter")

# Test with minimal valid param
param.set("name", "TEST_PARAM")
Expand Down
8 changes: 4 additions & 4 deletions tests/test_backend_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from ardupilot_methodic_configurator.backend_filesystem import LocalFilesystem


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

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

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

Expand Down Expand Up @@ -322,7 +322,7 @@ def test_get_eval_variables(self) -> None:

# Test with empty components and doc_dict
result = lfs.get_eval_variables()
assert result == {}
assert not result

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

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


Expand Down
15 changes: 12 additions & 3 deletions tests/test_frontend_tkinter_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from tkinter import ttk
from unittest.mock import MagicMock, patch

import pytest

from ardupilot_methodic_configurator.frontend_tkinter_base import (
AutoResizeCombobox,
BaseWindow,
Expand Down Expand Up @@ -471,7 +473,7 @@ def test_put_image_in_label(self, mock_label, mock_photo, mock_open) -> None:

# Set up PhotoImage mock
mock_photo_instance = MagicMock()
mock_photo_instance._PhotoImage__photo = "photo1" # Required for Tkinter
mock_photo_instance._PhotoImage__photo = "photo1" # pylint: disable=protected-access
mock_photo.return_value = mock_photo_instance

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


@pytest.fixture
def mock_set_display() -> MagicMock:
"""Mock the set_display_usage_popup method."""
with patch("ardupilot_methodic_configurator.frontend_tkinter_base.ProgramSettings.set_display_usage_popup") as mock_fun:
yield mock_fun


class TestUsagePopupWindow(unittest.TestCase):
"""Test cases for the UsagePopupWindow class."""

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

@patch("tkinter.BooleanVar")
@patch("ardupilot_methodic_configurator.frontend_tkinter_base.ProgramSettings.set_display_usage_popup")
def test_display_popup(self, mock_set_display, mock_bool_var) -> None:
@pytest.mark.usefixtures("mock_set_display")
def test_display_popup(self, mock_bool_var) -> None:
"""Test display method."""
mock_bool_var.return_value.get.return_value = True
usage_window = BaseWindow(self.root)
Expand Down
12 changes: 6 additions & 6 deletions tests/test_param_pid_adjustment_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_invalid_input(self) -> None:

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

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

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

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

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

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

0 comments on commit 59cb2b0

Please sign in to comment.