Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #104 from evgeniyz321/exceptions-intersection
Browse files Browse the repository at this point in the history
Add support for intersection between exceptions
  • Loading branch information
orsinium committed Dec 3, 2020
2 parents 143a5b3 + 09cc286 commit 62d2a93
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
8 changes: 5 additions & 3 deletions flakehell/_logic/_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,20 @@ def get_exceptions(
reverse=True,
)

aggregated_rules = dict()

# prefix
for path_rule, rules in exceptions:
if '*' in path_rule:
continue
if path.startswith(path_rule):
return rules
aggregated_rules.update(rules)

# glob
for path_rule, rules in exceptions:
if '*' not in path_rule:
continue
if fnmatch(filename=path, patterns=[path_rule]):
return rules
aggregated_rules.update(rules)

return dict()
return aggregated_rules
16 changes: 16 additions & 0 deletions tests/test_logic/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,19 @@ def test_get_exceptions(tmp_path: Path):
source_path.touch()
result = get_exceptions(path=source_path, exceptions=exceptions, root=tmp_path)
assert result == {}


def test_get_exceptions_with_intersections(tmp_path: Path):
exceptions = {
'tests/': {'pyflakes': ['+*']},
'**/test.py': {'pycodestyle': ['+*']},
}

tests_dir = tmp_path / 'tests'
tests_dir.mkdir()

test_file_path = tests_dir / 'test.py'
test_file_path.touch()

result = get_exceptions(path=test_file_path, exceptions=exceptions, root=tmp_path)
assert result == {'pyflakes': ['+*'], 'pycodestyle': ['+*']}

0 comments on commit 62d2a93

Please sign in to comment.