Skip to content

Commit

Permalink
ci: Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuloc committed Oct 1, 2024
1 parent d52842a commit b3af0e0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion j2lint/linter/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def create_from_directory(cls, rules_dir: Path, ignore_rules: list[str], warn_ru
A RulesColleciton object containing the rules from rules_dir except for the ignored ones.
"""
result = cls()
result.rules = load_plugins(str(rules_dir.expanduser()))
result.rules = load_plugins(rules_dir.expanduser())
for rule in result.rules:
if rule.short_description in ignore_rules or rule.rule_id in ignore_rules:
rule.ignore = True
Expand Down
7 changes: 3 additions & 4 deletions j2lint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
Statement = tuple[str, int, int, str, str]


def load_plugins(directory: str) -> list[Rule]:
def load_plugins(directory: Path) -> list[Rule]:
"""Load and execute all the Rule modules from the specified directory.
Parameters
----------
directory : string
directory : Path
Loads the modules a directory
Returns
Expand All @@ -36,8 +36,7 @@ def load_plugins(directory: str) -> list[Rule]:
"""
result = []
file_handle = None
directory_path = Path(directory)
for plugin_file in directory_path.glob(pattern="[A-Za-z_]*.py"):
for plugin_file in directory.glob(pattern="[A-Za-z_]*.py"):
plugin_name = plugin_file.name.replace(".py", "")
try:
logger.debug("Loading plugin %s", plugin_name)
Expand Down
3 changes: 1 addition & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import pytest
from rich.console import ConsoleDimensions

import j2lint
from j2lint import CONSOLE
from j2lint.cli import (
create_parser,
Expand Down Expand Up @@ -384,8 +385,6 @@ def test_run_stdin(capsys: pytest.LogCaptureFixture) -> None:
In this test, the isatty answer is mocked.
"""
import j2lint

with (
patch("sys.stdin") as patched_stdin,
patch.object(j2lint.cli.Path, "unlink", side_effect=j2lint.cli.Path.unlink, autospec=True) as mocked_os_unlink,
Expand Down
7 changes: 5 additions & 2 deletions tests/test_linter/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,18 @@ def test_create_from_directory(self, ignore_rules: list[str], warn_rules: list[s
with mock.patch("j2lint.linter.collection.load_plugins") as mocked_load_plugins:
# importing 3 rules for the need of the tests
# note that current pylint branch is returning classes
# not instances..
# not instances.
mocked_load_plugins.return_value = [
JinjaStatementDelimiterRule(),
JinjaOperatorHasSpacesRule(),
JinjaTemplateSyntaxErrorRule(),
]
collection = RulesCollection.create_from_directory(Path("dummy"), ignore_rules, warn_rules)
mocked_load_plugins.assert_called_once_with("dummy")
mocked_load_plugins.assert_called_once_with(Path("dummy"))
assert collection.rules == mocked_load_plugins.return_value
assert isinstance(collection, RulesCollection)
# Somehow pylint is convinced that rule are integers
# pylint: disable=no-member
for rule in collection.rules:
if rule.rule_id in ignore_rules or rule.short_description in ignore_rules:
assert rule.ignore is True
Expand Down
2 changes: 2 additions & 0 deletions tests/test_linter/test_indenter/test_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
that will parse a file content and return a list of statements - abusively called lines
"""

# pylint: disable=R0903

from __future__ import annotations

from typing import Any
Expand Down

0 comments on commit b3af0e0

Please sign in to comment.