Skip to content

Commit

Permalink
Add several async os functions
Browse files Browse the repository at this point in the history
Calls of rename, mkdir, rmdir are added together with tests
  • Loading branch information
harryzcy authored and Tinche committed Apr 9, 2019
1 parent a60f19b commit 5db1e38
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions aiofiles/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ def run(*args, loop=None, executor=None, **kwargs):


stat = wrap(os.stat)
rename = wrap(os.rename)
remove = wrap(os.remove)
mkdir = wrap(os.mkdir)
rmdir = wrap(os.rmdir)

if hasattr(os, "sendfile"):
sendfile = wrap(os.sendfile)
26 changes: 25 additions & 1 deletion tests/test_os.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Tests for asyncio's os module."""
import aiofiles.os
import asyncio
from os.path import join, dirname, exists
from os.path import join, dirname, exists, isdir
import pytest
import platform

Expand Down Expand Up @@ -29,6 +29,30 @@ def test_remove():
yield from aiofiles.os.remove(filename)
assert exists(filename) is False


@asyncio.coroutine
@pytest.mark.asyncio
def test_mkdir_and_rmdir():
"""Test the mkdir and rmdir call."""
directory = join(dirname(__file__), 'resources', 'test_dir')
yield from aiofiles.os.mkdir(directory)
assert isdir(directory)
yield from aiofiles.os.rmdir(directory)
assert exists(directory) is False


@asyncio.coroutine
@pytest.mark.asyncio
def test_rename():
"""Test the rename call."""
old_filename = join(dirname(__file__), 'resources', 'test_file1.txt')
new_filename = join(dirname(__file__), 'resources', 'test_file2.txt')
yield from aiofiles.os.rename(old_filename, new_filename)
assert exists(old_filename) is False and exists(new_filename)
yield from aiofiles.os.rename(new_filename, old_filename)
assert exists(old_filename) and exists(new_filename) is False


@asyncio.coroutine
@pytest.mark.skipif('2.4' < platform.release() < '2.6.33',
reason = "sendfile() syscall doesn't allow file->file")
Expand Down

0 comments on commit 5db1e38

Please sign in to comment.