Skip to content

Commit

Permalink
Add support for softlinks (copy them instead of their target)
Browse files Browse the repository at this point in the history
closes #1
  • Loading branch information
omarkohl committed Oct 7, 2018
1 parent fbfee9f commit a1703e8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pytest_datafiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
def _copy(src, target):
if not src.exists():
raise ValueError("'%s' does not exist!" % src)

if src.isdir():
src.copy(target / src.basename)
elif src.islink():
(target / src.basename).mksymlinkto(src.realpath())
else: # file
src.copy(target)

Expand Down
1 change: 1 addition & 0 deletions tests/_fixture_files/dir6/sparrow_link.jpg
1 change: 1 addition & 0 deletions tests/_fixture_files/sparrow_link.jpg
30 changes: 30 additions & 0 deletions tests/test_pytest_datafiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,33 @@ def test_invalid_param(datafiles):
result.stdout.fnmatch_lines([
"E*ValueError: 'on_duplicate' must be 'exception', 'ignore' or *",
])

@pytest.mark.datafiles(os.path.join(FIXTURE_DIR, 'sparrow_link.jpg'))
def test_copy_symlink(datafiles):
"""
Verify that symlinks are copied and not their targets.
"""
assert len(datafiles.listdir()) == 1
assert (datafiles / 'sparrow_link.jpg').check(link=1)


@pytest.mark.datafiles(os.path.join(FIXTURE_DIR, 'dir6'))
def test_copy_symlink_in_dir(datafiles):
"""
Verify that symlinks are copied and not their targets.
"""
assert len(datafiles.listdir()) == 1
assert (datafiles / 'sparrow_link.jpg').check(link=1)


@pytest.mark.datafiles(
os.path.join(FIXTURE_DIR, 'dir6'),
keep_top_dir=True,
)
def test_copy_symlink_in_dir2(datafiles):
"""
Verify that symlinks are copied and not their targets.
"""
assert len(datafiles.listdir()) == 1
assert len((datafiles / 'dir6').listdir()) == 1
assert (datafiles / 'dir6' / 'sparrow_link.jpg').check(link=1)

0 comments on commit a1703e8

Please sign in to comment.