Skip to content

Commit 1deba12

Browse files
committed
test: add regression test for file permissions (issue #11)
Issue #11 reported that mode bits were not being copied. This was resolved automatically when the plugin migrated from py.path to pathlib.Path/shutil.copy in version 3.0, since shutil.copy preserves mode bits by default. This test ensures that file permissions continue to be preserved.
1 parent c233a15 commit 1deba12

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

tests/_fixture_files/executable.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
executable test

tests/test_pytest_datafiles.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,24 @@ def test_copy_symlink_in_dir2(datafiles):
402402
assert len(list(datafiles.iterdir())) == 1
403403
assert len(list((datafiles / "dir6").iterdir())) == 1
404404
assert (datafiles / "dir6" / "sparrow_link.jpg").is_symlink()
405+
406+
407+
@pytest.mark.datafiles(FIXTURE_DIR / "executable.sh")
408+
def test_file_mode_bits_preserved(datafiles):
409+
"""
410+
Verify that file permission bits are preserved when copying files.
411+
412+
Regression test for issue #11.
413+
"""
414+
original_file = FIXTURE_DIR / "executable.sh"
415+
copied_file = datafiles / "executable.sh"
416+
417+
# Get the mode of both files
418+
original_mode = original_file.stat().st_mode
419+
copied_mode = copied_file.stat().st_mode
420+
421+
# The mode bits should match
422+
assert original_mode == copied_mode, (
423+
f"File permissions not preserved: "
424+
f"original={oct(original_mode)}, copied={oct(copied_mode)}"
425+
)

0 commit comments

Comments
 (0)