Skip to content

Commit

Permalink
Proxy name and mode properties
Browse files Browse the repository at this point in the history
Fixes #69.
  • Loading branch information
Lonami authored and Tinche committed Jul 16, 2020
1 parent 72f88e5 commit c48f5b0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
4 changes: 2 additions & 2 deletions aiofiles/threadpool/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"writelines",
)
@proxy_method_directly("detach", "fileno", "readable")
@proxy_property_directly("closed", "raw")
@proxy_property_directly("closed", "raw", "name", "mode")
class AsyncBufferedIOBase(AsyncBase):
"""The asyncio executor version of io.BufferedWriter."""

Expand Down Expand Up @@ -52,6 +52,6 @@ class AsyncBufferedReader(AsyncBufferedIOBase):
"writelines",
)
@proxy_method_directly("fileno", "readable")
@proxy_property_directly("closed")
@proxy_property_directly("closed", "name", "mode")
class AsyncFileIO(AsyncBase):
"""The asyncio executor version of io.FileIO."""
2 changes: 1 addition & 1 deletion aiofiles/threadpool/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
)
@proxy_method_directly("detach", "fileno", "readable")
@proxy_property_directly(
"buffer", "closed", "encoding", "errors", "line_buffering", "newlines"
"buffer", "closed", "encoding", "errors", "line_buffering", "newlines", "name", "mode"
)
class AsyncTextIOWrapper(AsyncBase):
"""The asyncio executor version of io.TextIOWrapper."""
26 changes: 26 additions & 0 deletions tests/threadpool/test_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,29 @@ async def test_simple_readall(tmpdir):

await file.close()
assert file.closed


@pytest.mark.asyncio
@pytest.mark.parametrize("mode", ["rb", "rb+", "ab+"])
@pytest.mark.parametrize("buffering", [-1, 0])
async def test_name_property(mode, buffering):
"""Test iterating over lines from a file."""
filename = join(dirname(__file__), "..", "resources", "multiline_file.txt")

async with aioopen(filename, mode=mode, buffering=buffering) as file:
assert file.name == filename

assert file.closed


@pytest.mark.asyncio
@pytest.mark.parametrize("mode", ["rb", "rb+", "ab+"])
@pytest.mark.parametrize("buffering", [-1, 0])
async def test_mode_property(mode, buffering):
"""Test iterating over lines from a file."""
filename = join(dirname(__file__), "..", "resources", "multiline_file.txt")

async with aioopen(filename, mode=mode, buffering=buffering) as file:
assert file.mode == mode

assert file.closed
24 changes: 24 additions & 0 deletions tests/threadpool/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,27 @@ async def test_simple_iteration_ctx_mgr(mode):
counter += 1

assert file.closed


@pytest.mark.asyncio
@pytest.mark.parametrize('mode', ['r', 'r+', 'a+'])
async def test_name_property(mode):
"""Test iterating over lines from a file."""
filename = join(dirname(__file__), '..', 'resources', 'multiline_file.txt')

async with aioopen(filename, mode=mode) as file:
assert file.name == filename

assert file.closed


@pytest.mark.asyncio
@pytest.mark.parametrize('mode', ['r', 'r+', 'a+'])
async def test_mode_property(mode):
"""Test iterating over lines from a file."""
filename = join(dirname(__file__), '..', 'resources', 'multiline_file.txt')

async with aioopen(filename, mode=mode) as file:
assert file.mode == mode

assert file.closed

0 comments on commit c48f5b0

Please sign in to comment.