Skip to content
Open
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ The released versions correspond to PyPI releases.

### Fixes

* fixed `fnmatch.filter` and `glob.glob` missing uppercase names
when simulating Windows on a POSIX host
(see [#1345](https://github.com/pytest-dev/pyfakefs/issues/1345))
* fixed a crash if the stack limit was set to a low value
(see [#1313](https://github.com/pytest-dev/pyfakefs/issues/1313))
* fixed `os.ftruncate` to inspect the `FakeFileWrapper` returned by
Expand Down
5 changes: 5 additions & 0 deletions pyfakefs/fake_filesystem_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import _io # type:ignore[import]
import doctest
import fnmatch
import functools
import genericpath
import glob
Expand Down Expand Up @@ -1121,6 +1122,10 @@ def patch_modules(self) -> None:
for name, modules in self.FS_MODULES.items():
for module, attr in modules:
try:
# fnmatch.filter skips normcase when os.path is posixpath.
# The fake path module can use Windows case rules instead.
if module is fnmatch and name == "posixpath":
continue
if not skip_prefixes or not module.__name__.startswith(
skip_prefixes
):
Expand Down
24 changes: 24 additions & 0 deletions pyfakefs/tests/fake_filesystem_glob_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
"""Test for glob using fake_filesystem."""

import contextlib
import fnmatch
import glob
import os
import sys
import unittest

from pyfakefs import fake_filesystem_unittest
from pyfakefs.fake_filesystem import OSType


class FakeGlobUnitTest(fake_filesystem_unittest.TestCase):
Expand Down Expand Up @@ -86,6 +88,28 @@ def test_has_magic(self):
self.assertTrue(glob.has_magic("["))
self.assertFalse(glob.has_magic("a"))

def test_fnmatch_filter_windows(self):
self.fs.os = OSType.WINDOWS
for pattern in ("*.txt", "*.TXT"):
with self.subTest(pattern=pattern):
self.assertEqual(
["B.TXT"], fnmatch.filter(["B.TXT", "other.log"], pattern)
)
self.assertEqual(
[b"B.TXT"],
fnmatch.filter([b"B.TXT", b"other.log"], pattern.encode()),
)

def test_glob_windows_case_insensitive(self):
self.fs.os = OSType.WINDOWS
self.fs.create_file(r"C:\d\B.TXT")
self.assertEqual([r"C:\d\B.TXT"], glob.glob(r"C:\d\*.txt"))

def test_fnmatch_filter_linux_case_sensitive(self):
self.fs.os = OSType.LINUX
self.assertEqual([], fnmatch.filter(["B.TXT"], "*.txt"))
self.assertEqual(["B.TXT"], fnmatch.filter(["B.TXT"], "*.TXT"))


if __name__ == "__main__":
unittest.main()
Loading