Skip to content

Commit

Permalink
Changed most tests to use a drive root under Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbean-bremen committed Jan 3, 2018
1 parent 35b57ad commit 32eccbd
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions tests/fake_filesystem_shutil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/fake_open_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 0 additions & 4 deletions tests/fake_os_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
8 changes: 4 additions & 4 deletions tests/fake_pathlib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -385,15 +385,15 @@ 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()
self.create_file(self.make_path('a_file'))
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()
Expand Down
6 changes: 1 addition & 5 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 32eccbd

Please sign in to comment.