Skip to content

Commit

Permalink
FIX: unit tests and remove most FBT003 linter exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
amilcarlucas committed Feb 7, 2025
1 parent 6c20194 commit 43aa856
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
10 changes: 9 additions & 1 deletion ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,22 @@ For example, to add support for German:
mkdir de
```

Now add the language to the end of the `LANGUAGE_CHOICES` array in the `ardupilot_methodic_configurator/internationalization.py` file.
Add the language to the end of the `LANGUAGE_CHOICES` array in the `ardupilot_methodic_configurator/internationalization.py` file.

For example, to add support for German:

```python
LANGUAGE_CHOICES = ['en', 'zh_CN', 'pt', 'de']
```

Add it also to the test on `tests\test_internationalization.py` file:

```python
def test_language_choices(self) -> None:
expected_languages = ["en", "zh_CN", "pt", "de", "it"]
assert expected_languages == LANGUAGE_CHOICES
```

### 3. Create a New PO File

Inside your newly created language directory, create a new `.po` file using the `.pot` template:
Expand Down
24 changes: 12 additions & 12 deletions tests/test_backend_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TestLocalFilesystem(unittest.TestCase): # pylint: disable=too-many-public
def test_read_params_from_files(self) -> None:
"""Test reading parameters from files with proper filtering."""
mock_vehicle_dir = "/mock/dir"
filesystem = LocalFilesystem(mock_vehicle_dir, "ArduCopter", "4.3.0", False) # noqa: FBT003
filesystem = LocalFilesystem(mock_vehicle_dir, "ArduCopter", "4.3.0", allow_editing_template_files=False)

with (
patch(
Expand Down Expand Up @@ -57,7 +57,7 @@ def test_str_to_bool(self) -> None:
def test_re_init(self) -> None:
"""Test reinitializing the filesystem with new parameters."""
mock_vehicle_dir = "/mock/dir"
filesystem = LocalFilesystem(mock_vehicle_dir, "ArduCopter", "4.3.0", False) # noqa: FBT003
filesystem = LocalFilesystem(mock_vehicle_dir, "ArduCopter", "4.3.0", allow_editing_template_files=False)

with (
patch.object(filesystem, "load_vehicle_components_json_data", return_value=True),
Expand All @@ -73,7 +73,7 @@ def test_re_init(self) -> None:
def test_vehicle_configuration_files_exist(self) -> None:
"""Test checking if vehicle configuration files exist."""
mock_vehicle_dir = "/mock/dir"
filesystem = LocalFilesystem(mock_vehicle_dir, "ArduCopter", "4.3.0", False) # noqa: FBT003
filesystem = LocalFilesystem(mock_vehicle_dir, "ArduCopter", "4.3.0", allow_editing_template_files=False)

with (
patch("ardupilot_methodic_configurator.backend_filesystem.os_path.exists", return_value=True),
Expand All @@ -96,7 +96,7 @@ def test_vehicle_configuration_files_exist(self) -> None:
def test_rename_parameter_files(self) -> None:
"""Test renaming parameter files."""
mock_vehicle_dir = "/mock/dir"
filesystem = LocalFilesystem(mock_vehicle_dir, "ArduCopter", "4.3.0", False) # noqa: FBT003
filesystem = LocalFilesystem(mock_vehicle_dir, "ArduCopter", "4.3.0", allow_editing_template_files=False)
filesystem.configuration_steps = {"new_file.param": {"old_filenames": ["old_file.param"]}}

with (
Expand Down Expand Up @@ -185,7 +185,7 @@ def test_getcwd(self) -> None:
"""Test getting current working directory."""
mock_vehicle_dir = "/mock/dir"
mock_cwd = "/test/dir"
filesystem = LocalFilesystem(mock_vehicle_dir, "ArduCopter", "4.3.0", False) # noqa: FBT003
filesystem = LocalFilesystem(mock_vehicle_dir, "ArduCopter", "4.3.0", allow_editing_template_files=False)

with patch("ardupilot_methodic_configurator.backend_filesystem.os_getcwd", return_value=mock_cwd) as mock_getcwd:
result = filesystem.getcwd()
Expand Down Expand Up @@ -308,7 +308,7 @@ def test_get_start_file_empty_files(self) -> None:
"""Test get_start_file with empty files list."""
lfs = LocalFilesystem("vehicle_dir", "vehicle_type", None, allow_editing_template_files=False)
lfs.file_parameters = {}
result = lfs.get_start_file(1, True) # noqa: FBT003
result = lfs.get_start_file(1, tcal_available=True)
assert result == ""

def test_get_eval_variables_with_none(self) -> None:
Expand Down Expand Up @@ -386,19 +386,19 @@ def test_get_start_file(self) -> None:
lfs.file_parameters = {"01_file.param": {}, "02_file.param": {}, "03_file.param": {}}

# Test with explicit index
result = lfs.get_start_file(1, True) # noqa: FBT003
result = lfs.get_start_file(1, tcal_available=True)
assert result == "02_file.param"

# Test with out of range index
result = lfs.get_start_file(5, True) # noqa: FBT003
result = lfs.get_start_file(5, tcal_available=True)
assert result == "03_file.param"

# Test with tcal available
result = lfs.get_start_file(-1, True) # noqa: FBT003
result = lfs.get_start_file(-1, tcal_available=True)
assert result == "01_file.param"

# Test with tcal not available
result = lfs.get_start_file(-1, False) # noqa: FBT003
result = lfs.get_start_file(-1, tcal_available=False)
assert result == "03_file.param"

def test_get_eval_variables(self) -> None:
Expand Down Expand Up @@ -522,15 +522,15 @@ def test_export_to_param(self) -> None:
mock_format.return_value = "formatted_params"

# Test with documentation annotation
lfs.export_to_param(test_params, "test.param", True) # noqa: FBT003
lfs.export_to_param(test_params, "test.param", annotate_doc=True)
mock_format.assert_called_with(test_params)
mock_export.assert_called_with("formatted_params", os_path.join("vehicle_dir", "test.param"))
mock_update.assert_called_once()

# Test without documentation annotation
mock_export.reset_mock()
mock_update.reset_mock()
lfs.export_to_param(test_params, "test.param", False) # noqa: FBT003
lfs.export_to_param(test_params, "test.param", annotate_doc=False)
mock_export.assert_called_once()
mock_update.assert_not_called()

Expand Down
2 changes: 1 addition & 1 deletion tests/test_backend_internet.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def test_download_file_unicode_error(mock_get) -> None:
def test_get_release_info_invalid_release(mock_get) -> None:
mock_get.side_effect = requests_RequestException()
with pytest.raises(requests_RequestException):
get_release_info("latest", False) # noqa: FBT003
get_release_info("latest", should_be_pre_release=False)


@patch("ardupilot_methodic_configurator.backend_internet.requests_get")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_internationalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_load_translation_fallback(self) -> None:
assert translation_function == identity_function # pylint: disable=comparison-with-callable

def test_language_choices(self) -> None:
expected_languages = ["en", "zh_CN", "pt", "de"]
expected_languages = ["en", "zh_CN", "pt", "de", "it"]
assert expected_languages == LANGUAGE_CHOICES


Expand Down

0 comments on commit 43aa856

Please sign in to comment.