Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix move excludes #232

Merged
merged 2 commits into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions synthtool/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def _copy_dir_to_existing_dir(
e
for e in excludes
if (
Path(e).relative_to(".") == Path(rel_path)
or Path(e).relative_to(".") == Path(rel_path) / name
Path(e) == _tracked_paths.relativize(root)
or Path(e) == _tracked_paths.relativize(Path(root) / name)
)
]
if not exclude:
Expand Down
19 changes: 18 additions & 1 deletion tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os
import stat
from pathlib import Path
import tempfile

import pytest

Expand Down Expand Up @@ -121,7 +122,7 @@ def test__move_to_dest(expand_path_fixtures):

files = sorted([str(x) for x in transforms._expand_paths("**/*", root="dest")])

# Assert destination does not contain dira/e.py (excluded)
# Assert destination does not contain dira/f.py (excluded)
assert files == [
"dest/a.txt",
"dest/b.py",
Expand All @@ -132,3 +133,19 @@ def test__move_to_dest(expand_path_fixtures):
"dest/dirb/suba",
"dest/dirb/suba/g.py",
]


def test__move_to_dest_subdir(expand_path_fixtures):
tmp_path = Path(str(expand_path_fixtures))
_tracked_paths.add(expand_path_fixtures)
dest = Path(str(expand_path_fixtures / "dest/dira"))

# Move to a different dir to make sure that move doesn't depend on the cwd
os.chdir(tempfile.gettempdir())
transforms.move(tmp_path / "dira", dest, excludes=["f.py"])

os.chdir(str(tmp_path))
files = sorted([str(x) for x in transforms._expand_paths("**/*", root="dest")])

# Assert destination does not contain dira/f.py (excluded)
assert files == ["dest/dira", "dest/dira/e.txt"]