Skip to content

Commit

Permalink
added and tested os.getcwd and os.path.abspath (#182)
Browse files Browse the repository at this point in the history
* added and tested os.getcwd and os.path.abspath

* Update README.md

---------

Co-authored-by: Godefroy Clair <[email protected]>
Co-authored-by: Tin Tvrtković <[email protected]>
  • Loading branch information
3 people committed Jun 7, 2024
1 parent e2bcd7f commit 501e9bc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ several useful `os` functions that deal with files:
- `listdir`
- `scandir`
- `access`
- `getcwd`
- `path.abspath`
- `path.exists`
- `path.isfile`
- `path.isdir`
Expand Down Expand Up @@ -183,6 +185,8 @@ async def test_stuff():
[#175](https://github.com/Tinche/aiofiles/issues/175)
- Remove spurious items from `aiofiles.os.__all__` when running on Windows.
- Switch to more modern async idioms: Remove types.coroutine and make AiofilesContextManager an awaitable instead a coroutine.
- Add `aiofiles.os.path.abspath` and `aiofiles.os.getcwd`.
[#174](https://github.com/Tinche/aiofiles/issues/181)

#### 23.2.1 (2023-08-09)

Expand Down
3 changes: 3 additions & 0 deletions src/aiofiles/os.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Async executor versions of file functions from the os module."""

import os

from . import ospath as path
Expand All @@ -22,6 +23,7 @@
"scandir",
"access",
"wrap",
"getcwd",
]
if hasattr(os, "link"):
__all__ += ["link"]
Expand All @@ -46,6 +48,7 @@
listdir = wrap(os.listdir)
scandir = wrap(os.scandir)
access = wrap(os.access)
getcwd = wrap(os.getcwd)

if hasattr(os, "link"):
link = wrap(os.link)
Expand Down
2 changes: 2 additions & 0 deletions src/aiofiles/ospath.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Async executor versions of file functions from the os.path module."""

import asyncio
from functools import partial, wraps
from os import path
Expand Down Expand Up @@ -26,3 +27,4 @@ async def run(*args, loop=None, executor=None, **kwargs):
getctime = wrap(path.getctime)
samefile = wrap(path.samefile)
sameopenfile = wrap(path.sameopenfile)
abspath = wrap(path.abspath)
25 changes: 25 additions & 0 deletions tests/test_os.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for asyncio's os module."""

import asyncio
import os
import platform
Expand Down Expand Up @@ -511,3 +512,27 @@ async def test_access():
print("mode:{}".format(mode))
assert not await aiofiles.os.access(temp_file, mode)
assert not await aiofiles.os.access(temp_dir, mode)


@pytest.mark.asyncio
async def test_getcwd():
"""Test the getcwd call."""
cwd = await aiofiles.os.getcwd()
assert cwd == os.getcwd()


@pytest.mark.asyncio
async def test_abspath_given_abspath():
"""Test the abspath call with an absolute path."""
filename = join(dirname(__file__), "resources", "test_file1.txt")
file_abs_path = await aiofiles.os.path.abspath(filename)
assert file_abs_path == filename


@pytest.mark.asyncio
async def test_abspath():
"""Test the abspath call."""
relative_filename = "./tests/resources/test_file1.txt"
abs_filename = join(dirname(__file__), "resources", "test_file1.txt")
result = await aiofiles.os.path.abspath(relative_filename)
assert result == abs_filename

0 comments on commit 501e9bc

Please sign in to comment.