Skip to content

Commit

Permalink
test(write_exclude_list): add test for write_exclude_list config option
Browse files Browse the repository at this point in the history
  • Loading branch information
frq-asgard-josi committed Oct 31, 2024
1 parent 4a73f5c commit c84f660
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any
from unittest import mock
from unittest.mock import Mock, patch

import pytest

Expand Down Expand Up @@ -297,6 +298,48 @@ def test_effective_write_set(write_list: list[str], expected: set[str]) -> None:
assert actual == expected


@pytest.mark.parametrize(
("write_list", "write_exclude_list", "expected"),
(
(["all"], ["none"], {"all"}),
(["all"], ["all"], {"none"}),
(["none"], ["none"], {"none"}),
(["none"], ["all"], {"none"}),
(["rule-id"], ["none"], {"rule-id"}),
(["rule-id"], ["all"], {"none"}),
),
)
@patch.object(TransformMixin, "transform")
def test_write_exclude_list(
_,
write_list: list[str],
write_exclude_list: list[str],
expected: set[str]
) -> None:
"""Test item matching write_exclude_list are excluded correctly"""
matches: list[MatchError] = []
for rule_id in ["rule-id", "rule1", "rule-03"]:
match = MatchError()
match.id = rule_id
match.rule = TransformMixin # rule must be an instance of TransformMixin to be considered for transformations
matches.append(match)

transformer = Mock()
transformer.write_set.return_value = Transformer.effective_write_set(write_list)
transformer.write_exclude_set.return_value = Transformer.effective_write_set(
write_exclude_list
)

# noinspection PyTypeChecker
Transformer._do_transforms(transformer, Mock(), None, False, matches)

for match in matches:
if match.id in expected or expected == set("all"):
match.rule.transform.assert_called()
else:
match.rule.transform.assert_not_called()


def test_pruned_err_after_fix(monkeypatch: pytest.MonkeyPatch, tmpdir: Path) -> None:
"""Test that pruned errors are not reported after fixing.
Expand Down

0 comments on commit c84f660

Please sign in to comment.