Skip to content

Commit

Permalink
TST: symlink in md5() and list_file_names() (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenw authored Jan 22, 2024
1 parent e6c534e commit cebd0a3
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,30 @@ def test_list_file_names(tmpdir, files, path, filetype, expected, recursive, hid
assert f == expected


def test_list_file_names_symlinks(tmpdir):
# symlinks in folder
folder = audeer.mkdir(tmpdir, "folder")
file = audeer.touch(folder, "file.txt")
link = audeer.path(folder, "link.txt")
os.symlink(file, link)
files = audeer.list_file_names(folder, basenames=True)
assert files == ["file.txt", "link.txt"]
os.remove(link)
# symlinks to sub-folders
sub_folder = audeer.mkdir(folder, "sub-folder")
audeer.touch(sub_folder, "file2.txt")
link = audeer.path(folder, "link")
os.symlink(sub_folder, link)
files = audeer.list_file_names(folder, basenames=True)
assert files == ["file.txt"]
files = audeer.list_file_names(folder, basenames=True, recursive=True)
assert files == [
"file.txt",
os.path.join("link", "file2.txt"),
os.path.join("sub-folder", "file2.txt"),
]


def test_md5_errors():
with pytest.raises(FileNotFoundError):
audeer.md5("does/not/exist")
Expand Down Expand Up @@ -1072,6 +1096,33 @@ def test_md5_folder(tmpdir, tree, content, expected):
assert audeer.md5(tmpdir) == expected


def test_md5_symbolic_link(tmpdir):
# Link to a file
file = audeer.touch(tmpdir, "file.txt")
link = audeer.path(tmpdir, "link.txt")
os.symlink(file, link)
assert audeer.md5(file) == audeer.md5(link)
os.remove(file)
os.remove(link)
# Link to a folder
folder = audeer.mkdir(tmpdir, "folder")
file = audeer.touch(folder, "file.txt")
link = audeer.path(tmpdir, "link")
os.symlink(folder, link)
assert audeer.md5(folder) == audeer.md5(link)
os.remove(link)
# Link to file in folder
md5_single_file = audeer.md5(folder)
link = audeer.path(folder, "link.txt")
os.symlink(file, link)
md5_link = audeer.md5(folder)
os.remove(link)
audeer.touch(folder, "link.txt")
md5_file = audeer.md5(folder)
assert md5_link == md5_file
assert md5_file != md5_single_file


def test_mkdir(tmpdir):
# New dir
path = str(tmpdir.mkdir("folder1"))
Expand Down

0 comments on commit cebd0a3

Please sign in to comment.