From 986efb075c1266354d54c20d387d4905b7bb03b4 Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Mon, 13 Mar 2017 19:43:45 +0100 Subject: [PATCH] Change case handling for pathlib - make it depend on posic vs. windows instead of case sensitivity of file system - see #167 --- fake_pathlib_test.py | 18 ++++++++++++++++++ pyfakefs/fake_pathlib.py | 12 ++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/fake_pathlib_test.py b/fake_pathlib_test.py index ae3a4f34..860fb933 100644 --- a/fake_pathlib_test.py +++ b/fake_pathlib_test.py @@ -485,6 +485,24 @@ def test_glob(self): self.assertEqual(sorted(path.glob('*.py')), [self.path('!foo!all_tests.py'), self.path('!foo!setup.py')]) + def test_glob_case_windows(self): + self.filesystem.is_windows_fs = True + self.filesystem.CreateFile('!foo!setup.py') + self.filesystem.CreateFile('!foo!all_tests.PY') + self.filesystem.CreateFile('!foo!README.md') + self.filesystem.CreateFile('!foo!example.Py') + path = self.path('!foo') + self.assertEqual(sorted(path.glob('*.py')), + [self.path('!foo!all_tests.PY'), self.path('!foo!example.Py'), self.path('!foo!setup.py')]) + + def test_glob_case_posix(self): + self.filesystem.is_windows_fs = False + self.filesystem.CreateFile('!foo!setup.py') + self.filesystem.CreateFile('!foo!all_tests.PY') + self.filesystem.CreateFile('!foo!README.md') + self.filesystem.CreateFile('!foo!example.Py') + path = self.path('!foo') + self.assertEqual(sorted(path.glob('*.py')), [self.path('!foo!setup.py')]) @unittest.skipIf(sys.version_info < (3, 6), 'path-like objects new in Python 3.6') class FakePathlibUsageInOsFunctionsTest(unittest.TestCase): diff --git a/pyfakefs/fake_pathlib.py b/pyfakefs/fake_pathlib.py index 02492cb0..addc4896 100644 --- a/pyfakefs/fake_pathlib.py +++ b/pyfakefs/fake_pathlib.py @@ -208,15 +208,15 @@ def splitroot(self, path, sep=None): def casefold(self, s): """Return the lower-case version of s for a case-insensitive filesystem.""" - if self.filesystem.is_case_sensitive: - return s - return s.lower() + if self.filesystem.is_windows_fs: + return s.lower() + return s def casefold_parts(self, parts): """Return the lower-case version of parts for a case-insensitive filesystem.""" - if self.filesystem.is_case_sensitive: - return parts - return [p.lower() for p in parts] + if self.filesystem.is_windows_fs: + return [p.lower() for p in parts] + return parts def _resolve_posix(self, path, strict): """Original implementation in Python 3.6."""