diff options
author | mrbean-bremen <hansemrbean@googlemail.com> | 2022-07-19 19:33:50 +0200 |
---|---|---|
committer | mrbean-bremen <mrbean-bremen@users.noreply.github.com> | 2022-07-20 19:15:02 +0200 |
commit | c640ddc48206ad97ab9bb4ec22c86c70788512ff (patch) | |
tree | 5d899357d3f86b200d1c9ac52fe268f23b609e5a /pyfakefs | |
parent | f5640e3ad4fc2a604f6d5fa00184bc13d715cb4d (diff) | |
download | pyfakefs-c640ddc48206ad97ab9bb4ec22c86c70788512ff.tar.gz |
Fix handling of Windows drive as root path
- was always detected as existing
- caused part of #692
Diffstat (limited to 'pyfakefs')
-rw-r--r-- | pyfakefs/fake_filesystem.py | 8 | ||||
-rw-r--r-- | pyfakefs/tests/fake_filesystem_test.py | 14 | ||||
-rw-r--r-- | pyfakefs/tests/fake_filesystem_unittest_test.py | 3 |
3 files changed, 19 insertions, 6 deletions
diff --git a/pyfakefs/fake_filesystem.py b/pyfakefs/fake_filesystem.py index 3eea18e..4365b34 100644 --- a/pyfakefs/fake_filesystem.py +++ b/pyfakefs/fake_filesystem.py @@ -1923,9 +1923,11 @@ class FakeFilesystem: if (file_path == mount_point or not self.is_case_sensitive and file_path.lower() == mount_point.lower()): return True - if self.is_windows_fs: - return (2 <= len(file_path) <= 3 and - self.starts_with_drive_letter(file_path)) + if (self.is_windows_fs and len(file_path) == 3 and + len(mount_point) == 2 and + self.starts_with_drive_letter(file_path) and + file_path[:2].lower() == mount_point.lower()): + return True return False def ends_with_path_separator(self, path: Union[int, AnyPath]) -> bool: diff --git a/pyfakefs/tests/fake_filesystem_test.py b/pyfakefs/tests/fake_filesystem_test.py index 445fcd1..2e9642f 100644 --- a/pyfakefs/tests/fake_filesystem_test.py +++ b/pyfakefs/tests/fake_filesystem_test.py @@ -23,7 +23,9 @@ import sys import unittest from pyfakefs import fake_filesystem -from pyfakefs.fake_filesystem import set_uid, set_gid, is_root, reset_ids +from pyfakefs.fake_filesystem import ( + set_uid, set_gid, is_root, reset_ids, OSType +) from pyfakefs.helpers import IS_WIN from pyfakefs.tests.test_utils import TestCase, RealFsTestCase, time_mock @@ -1023,6 +1025,16 @@ class FakePathModuleTest(TestCase): self.assertTrue(self.path.exists(file_path_bytes)) self.assertFalse(self.path.exists('!some!other!bogus!path')) + def test_exists_with_drive(self): + self.filesystem.os = OSType.WINDOWS + self.filesystem.add_mount_point('F:') + self.assertTrue(self.path.exists('C:')) + self.assertTrue(self.path.exists('c:\\')) + self.assertTrue(self.path.exists('f:')) + self.assertTrue(self.path.exists('F:\\')) + self.assertFalse(self.path.exists('Z:')) + self.assertFalse(self.path.exists('z:\\')) + def test_lexists(self): file_path = 'foo!bar!baz' file_path_bytes = b'foo!bar!baz' diff --git a/pyfakefs/tests/fake_filesystem_unittest_test.py b/pyfakefs/tests/fake_filesystem_unittest_test.py index 97b5f7b..0f4678e 100644 --- a/pyfakefs/tests/fake_filesystem_unittest_test.py +++ b/pyfakefs/tests/fake_filesystem_unittest_test.py @@ -866,8 +866,7 @@ class TestOtherFS(fake_filesystem_unittest.TestCase): file_path = folder / 'C:/testfile' file_path.parent.mkdir(parents=True) file_path.touch() - # use str() to be Python 3.5 compatible - os.chdir(str(folder)) + os.chdir(folder) self.assertTrue(os.path.exists(str(file_path.relative_to(folder)))) |