Skip to content

Commit

Permalink
Uniform files list by using unix path (#201)
Browse files Browse the repository at this point in the history
* uniform files list by using unix path

* adding test if excluding depend of the OS path separator

---------

Co-authored-by: Ilya Kamen <ikamenshchikov@gmail.com>
  • Loading branch information
un-pogaz and ikamensh authored Feb 2, 2025
1 parent 7ff03ad commit 0033d9a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/flynt/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ def _resolve_files(
else:
files.append(abs_path)

files = [f.replace("\\", "/") for f in files]
_blacklist = {f.replace("\\", "/") for f in _blacklist}
files = [f for f in files if all(b not in f for b in _blacklist)]
return files

Expand Down
35 changes: 34 additions & 1 deletion test/integration/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

from flynt import api
from flynt.api import _fstringify_file
from flynt.api import _fstringify_file, _resolve_files
from flynt.state import State

# These "files" are byte-string constants instead of actual files to prevent e.g. Git or text editors from accidentally changing the encoding
Expand All @@ -13,6 +13,20 @@
mixed_line_endings_after = (
b"f'{1}'\nf'{2}'# Linux line ending\nf'{3}'# Windows line ending\r\n"
)
fake_path_tree = (
r"src/flynt/test/unix/code.py",
r"src/flynt/test/unix/exclude/code.py",
r"src/flynt/test/win/code.py",
r"src/flynt/test/win/exclude/code.py",
r"src/flynt/test/mixed/code.py",
r"src/flynt/test/mixed/exclude/code.py",
)
uniform_path_exclude = (
r"test/unix/exclude",
r"test\win\exclude",
r"test/mixed\exclude",
)
uniform_path_count_result = len(fake_path_tree) - len(uniform_path_exclude)


@pytest.fixture()
Expand Down Expand Up @@ -184,3 +198,22 @@ def test_bom(bom_file):

result = _fstringify_file(bom_file, state=State(multiline=True, len_limit=1000))
assert result.n_changes


@pytest.fixture()
def fake_folder_tree(tmpdir):
folder = os.path.join(tmpdir, "fake_tree")
for fake_file in fake_path_tree:
tmp_path = os.path.join(folder, fake_file)
os.makedirs(os.path.dirname(tmp_path), exist_ok=True)
with open(tmp_path, "wb") as file:
file.write(b"")

return folder


def test_uniform_path(fake_folder_tree):
"""Test if the arguments for excluding path is depending of the OS path separator."""

result = _resolve_files([fake_folder_tree], uniform_path_exclude)
assert len(result) == uniform_path_count_result

0 comments on commit 0033d9a

Please sign in to comment.