Skip to content

Commit

Permalink
Add patching getcwd/getcwdb for nt
Browse files Browse the repository at this point in the history
- fixes Windows problem if called from fspath, if
  the real current drive is not C:
- fixes test for #892 under Windows
  • Loading branch information
mrbean-bremen committed Oct 10, 2023
1 parent 4e99991 commit 567480c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 3 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ The released versions correspond to PyPI releases.
* make sure tests work without HOME environment set (see [#870](../../issues/870))
* automount drive or UNC path under Windows if needed for `pathlib.Path.mkdir()`
(see [#890](../../issues/890))
* adapt patching `io.open` to work with Python 3.12 (see [#836](../../issues/836))
* adapt patching `io.open` and `io.open_code` to work with Python 3.12
(see [#836](../../issues/836) and [#892](../../issues/892))

## [Version 5.2.3](https://pypi.python.org/pypi/pyfakefs/5.2.3) (2023-08-18)
Fixes a rare problem on pytest shutdown.

### Fixes
* Clear the patched module cache on session shutdown (pytest only)
(see [#866](../../issues/866)). Added a class method `Patcher.cler_fs_cache`
(see [#866](../../issues/866)). Added a class method `Patcher.clear_fs_cache`
for clearing the patched module cache.

## [Version 5.2.3](https://pypi.python.org/pypi/pyfakefs/5.2.3) (2023-07-10)
Expand Down
9 changes: 9 additions & 0 deletions pyfakefs/fake_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
make_string_path,
to_string,
matching_string,
to_bytes,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -507,6 +508,14 @@ def __init__(self, filesystem: "FakeFilesystem"):
self.filesystem = filesystem
self.nt_module: Any = nt

def getcwd(self) -> str:
"""Return current working directory."""
return to_string(self.filesystem.cwd)

def getcwdb(self) -> bytes:
"""Return current working directory as bytes."""
return to_bytes(self.filesystem.cwd)

if sys.version_info >= (3, 12):

def _path_isdir(self, path: AnyStr) -> bool:
Expand Down
1 change: 0 additions & 1 deletion pyfakefs/tests/fake_filesystem_unittest_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,6 @@ def import_foo(self):
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)

@unittest.skipIf(sys.platform == "win32", "Not yet working under Windows")
def test_exec_module_in_fake_fs(self):
self.fs.create_file("/foo/bar.py", contents="print('hello')")
with redirect_stdout(StringIO()) as stdout:
Expand Down

0 comments on commit 567480c

Please sign in to comment.