Skip to content

Commit

Permalink
Change case handling for pathlib
Browse files Browse the repository at this point in the history
- make it depend on posic vs. windows instead of case sensitivity of
file system
- see pytest-dev#167
  • Loading branch information
mrbean-bremen committed Mar 13, 2017
1 parent 7213f47 commit 986efb0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
18 changes: 18 additions & 0 deletions fake_pathlib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 6 additions & 6 deletions pyfakefs/fake_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 986efb0

Please sign in to comment.