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

Add aiofiles.os.symlink function #124

Merged
merged 2 commits into from
Jan 6, 2022
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
1 change: 1 addition & 0 deletions src/aiofiles/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async def run(*args, loop=None, executor=None, **kwargs):
rmdir = wrap(os.rmdir)
removedirs = wrap(os.removedirs)
link = wrap(os.link)
symlink = wrap(os.symlink)

if hasattr(os, "sendfile"):
sendfile = wrap(os.sendfile)
29 changes: 25 additions & 4 deletions tests/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,33 @@ async def test_link():
"""Test the link call."""
src_filename = join(dirname(__file__), "resources", "test_file1.txt")
dst_filename = join(dirname(__file__), "resources", "test_file2.txt")
initial_src_nlink = stat(src_filename).st_nlink
await aiofiles.os.link(src_filename, dst_filename)
assert (
exists(src_filename) and
exists(dst_filename) and
stat(src_filename).st_ino == stat(dst_filename).st_ino
exists(src_filename)
and exists(dst_filename)
and (stat(src_filename).st_ino == stat(dst_filename).st_ino)
and (stat(src_filename).st_nlink == initial_src_nlink + 1)
and (stat(dst_filename).st_nlink == 2)
)
await aiofiles.os.remove(dst_filename)
assert exists(src_filename) and exists(dst_filename) is False
assert (
exists(src_filename)
and exists(dst_filename) is False
and (stat(src_filename).st_nlink == initial_src_nlink)
)


@pytest.mark.asyncio
async def test_symlink():
"""Test the symlink call."""
src_filename = join(dirname(__file__), "resources", "test_file1.txt")
dst_filename = join(dirname(__file__), "resources", "test_file2.txt")
await aiofiles.os.symlink(src_filename, dst_filename)
assert (
exists(src_filename)
and exists(dst_filename)
and stat(src_filename).st_ino == stat(dst_filename).st_ino
)
await aiofiles.os.remove(dst_filename)
assert exists(src_filename) and exists(dst_filename) is False