forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust pylint plugin to enforce device_tracker type hints (home-assis…
…tant#64903) * Adjust pylint plugin to enforce device_tracker type hints * Use a constant for the type hint matchers * Add tests * Add x_of_y match * Adjust bluetooth_tracker * Adjust mysensors * Adjust tile Co-authored-by: epenet <[email protected]>
- Loading branch information
Showing
6 changed files
with
143 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Tests for pylint.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Tests for pylint hass_enforce_type_hints plugin.""" | ||
# pylint:disable=protected-access | ||
|
||
from importlib.machinery import SourceFileLoader | ||
import re | ||
|
||
import pytest | ||
|
||
loader = SourceFileLoader( | ||
"hass_enforce_type_hints", "pylint/plugins/hass_enforce_type_hints.py" | ||
) | ||
hass_enforce_type_hints = loader.load_module(None) | ||
_TYPE_HINT_MATCHERS: dict[str, re.Pattern] = hass_enforce_type_hints._TYPE_HINT_MATCHERS | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("string", "expected_x", "expected_y", "expected_z"), | ||
[ | ||
("Callable[..., None]", "Callable", "...", "None"), | ||
("Callable[..., Awaitable[None]]", "Callable", "...", "Awaitable[None]"), | ||
], | ||
) | ||
def test_regex_x_of_y_comma_z(string, expected_x, expected_y, expected_z): | ||
"""Test x_of_y_comma_z regexes.""" | ||
assert (match := _TYPE_HINT_MATCHERS["x_of_y_comma_z"].match(string)) | ||
assert match.group(0) == string | ||
assert match.group(1) == expected_x | ||
assert match.group(2) == expected_y | ||
assert match.group(3) == expected_z | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("string", "expected_a", "expected_b"), | ||
[("DiscoveryInfoType | None", "DiscoveryInfoType", "None")], | ||
) | ||
def test_regex_a_or_b(string, expected_a, expected_b): | ||
"""Test a_or_b regexes.""" | ||
assert (match := _TYPE_HINT_MATCHERS["a_or_b"].match(string)) | ||
assert match.group(0) == string | ||
assert match.group(1) == expected_a | ||
assert match.group(2) == expected_b |