From 32eccbd133014136e6fb391ce197bd24abe0f412 Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Wed, 3 Jan 2018 14:06:29 +0100 Subject: [PATCH] Changed most tests to use a drive root under Windows --- CHANGES.md | 2 ++ tests/fake_filesystem_shutil_test.py | 5 +++-- tests/fake_open_test.py | 4 ++-- tests/fake_os_test.py | 4 ---- tests/fake_pathlib_test.py | 8 ++++---- tests/test_utils.py | 6 +----- 6 files changed, 12 insertions(+), 17 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index ea0556c5..fe681c58 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,8 @@ must use pyfakefs 3.3 or earlier. * Removed Python 2.6 support [#293](../../issues/293) #### Fixes + * Symlinks to absolute paths were incorrectly resolved under Windows ([#341](../../issues/341)) + * Unittest mock didn't work after setUpPyfakefs ([#334](../../issues/334)) * `os.path.split()` and `os.path.dirname()` gave incorrect results under Windows ([#335](../../issues/335)) ## [Version 3.3](https://pypi.python.org/pypi/pyfakefs/3.3) diff --git a/tests/fake_filesystem_shutil_test.py b/tests/fake_filesystem_shutil_test.py index c600df49..612b04c8 100644 --- a/tests/fake_filesystem_shutil_test.py +++ b/tests/fake_filesystem_shutil_test.py @@ -40,8 +40,8 @@ def setUp(self): self.filesystem = self.fs self.os = os self.open = open - self.fs.set_disk_usage(1000) self.create_basepath() + self.fs.set_disk_usage(1000, self.base_path) def tearDown(self): if self.use_real_fs(): @@ -322,7 +322,8 @@ def test_disk_usage(self): self.skip_real_fs() file_path = self.make_path('foo', 'bar') self.fs.create_file(file_path, st_size=400) - disk_usage = shutil.disk_usage('/') + # root = self.os.path.splitdrive(file_path)[0] + self.fs.path_separator + disk_usage = shutil.disk_usage(file_path) self.assertEqual(1000, disk_usage.total) self.assertEqual(400, disk_usage.used) self.assertEqual(600, disk_usage.free) diff --git a/tests/fake_open_test.py b/tests/fake_open_test.py index 42fb7875..18a1b239 100644 --- a/tests/fake_open_test.py +++ b/tests/fake_open_test.py @@ -1434,8 +1434,8 @@ def test_too_many_links(self): def test_that_drive_letters_are_preserved(self): self.filesystem.is_windows_fs = True - self.assertEqual('c:!foo!bar', - self.filesystem.resolve_path('c:!foo!!bar')) + self.assertEqual('C:!foo!bar', + self.filesystem.resolve_path('C:!foo!!bar')) @unittest.skipIf(sys.version_info < (2, 7, 8), 'UNC path support since Python 2.7.8') diff --git a/tests/fake_os_test.py b/tests/fake_os_test.py index d1bc38ab..5e9c508b 100644 --- a/tests/fake_os_test.py +++ b/tests/fake_os_test.py @@ -55,10 +55,6 @@ def setUp(self): self.rwx = self.os.R_OK | self.os.W_OK | self.os.X_OK self.rw = self.os.R_OK | self.os.W_OK - @property - def use_drive_root(self): - return True - def test_chdir(self): """chdir should work on a directory.""" directory = self.make_path('foo') diff --git a/tests/fake_pathlib_test.py b/tests/fake_pathlib_test.py index 202394c8..868ee55f 100644 --- a/tests/fake_pathlib_test.py +++ b/tests/fake_pathlib_test.py @@ -342,11 +342,11 @@ def test_lstat_windows(self): self.skip_if_symlink_not_supported() self.check_lstat(0) + @unittest.skipIf(is_windows, 'Linux specific behavior') def test_chmod(self): self.check_linux_only() - self.path(self.file_link_path).chmod(0o444) file_stat = self.os.stat(self.file_path) - self.assertEqual(file_stat.st_mode, stat.S_IFREG | 0o444) + self.assertEqual(file_stat.st_mode, stat.S_IFREG | 0o666) link_stat = self.os.lstat(self.file_link_path) # we get stat.S_IFLNK | 0o755 under MacOs self.assertEqual(link_stat.st_mode, stat.S_IFLNK | 0o777) @@ -385,7 +385,7 @@ def test_resolve_nonexisting_file(self): path = self.path('/foo/bar') self.assertRaises(FileNotFoundError, path.resolve) - @unittest.skipIf(sys.version_info >= (3, 6), + @unittest.skipIf(not is_windows or sys.version_info >= (3, 6), 'Changed behavior in Python 3.6') def test_resolve_file_as_parent_windows(self): self.check_windows_only() @@ -393,7 +393,7 @@ def test_resolve_file_as_parent_windows(self): path = self.path(self.make_path('a_file', 'this can not exist')) self.assertRaises(FileNotFoundError, path.resolve) - @unittest.skipIf(sys.version_info >= (3, 6), + @unittest.skipIf(is_windows or sys.version_info >= (3, 6), 'Changed behavior in Python 3.6') def test_resolve_file_as_parent_posix(self): self.check_posix_only() diff --git a/tests/test_utils.py b/tests/test_utils.py index 535edc69..c6f8dcaa 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -90,10 +90,6 @@ def set_windows_fs(self, value): self.filesystem.is_macos = False self.create_basepath() - @property - def use_drive_root(self): - return False - @property def is_macos(self): return TestCase.is_macos @@ -269,7 +265,7 @@ def create_basepath(self): if self.filesystem is not None: old_base_path = self.base_path self.base_path = self.filesystem.path_separator + 'basepath' - if self.is_windows_fs and self.use_drive_root: + if self.is_windows_fs: self.base_path = 'C:' + self.base_path if old_base_path != self.base_path: if not self.filesystem.exists(self.base_path):