Skip to content

Commit

Permalink
Removed most of FakeShutilModule functionality
Browse files Browse the repository at this point in the history
- adapted tests to work with fake_filesystem_unittest.TestCase
- fixed some tests
- fake_filesystem.ResolvePath: consider alternative path separator for resolving links
- fixes pytest-dev#194
  • Loading branch information
mrbean-bremen committed Jun 17, 2017
1 parent bf5ce85 commit c315342
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
6 changes: 3 additions & 3 deletions fake_filesystem_shutil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def testRaisesIfDestDirIsNotWritableUnderPosix(self):
self.filesystem.CreateDirectory(dst_dir, perm_bits=0o555)
self.assertTrue(self.filesystem.Exists(src_file))
self.assertTrue(self.filesystem.Exists(dst_dir))
self.assertRaises(IOError, self.shutil.copyfile, src_file, dst_file)
self.assertRaises(OSError, self.shutil.copyfile, src_file, dst_file)

def testRaisesIfSrcDoesntExist(self):
src_file = 'xyzzy'
Expand All @@ -391,7 +391,7 @@ def testRaisesIfSrcIsADirectory(self):
dst_file = 'xyzzy_copy'
self.filesystem.CreateDirectory(src_file)
self.assertTrue(self.filesystem.Exists(src_file))
self.assertRaises(IOError, self.shutil.copyfile, src_file, dst_file)
self.assertRaises(OSError, self.shutil.copyfile, src_file, dst_file)

def testRaisesIfDestIsADirectory(self):
src_file = 'xyzzy'
Expand All @@ -401,7 +401,7 @@ def testRaisesIfDestIsADirectory(self):
self.filesystem.CreateDirectory(dst_dir)
self.assertTrue(self.filesystem.Exists(src_file))
self.assertTrue(self.filesystem.Exists(dst_dir))
self.assertRaises(IOError, self.shutil.copyfile, src_file, dst_dir)
self.assertRaises(OSError, self.shutil.copyfile, src_file, dst_dir)


if __name__ == '__main__':
Expand Down
17 changes: 12 additions & 5 deletions pyfakefs/fake_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1756,6 +1756,13 @@ def LResolveObject(self, path):
if path == self.root.name:
# The root directory will never be a link
return self.root

# remove trailing separator
sep = self._path_separator(path)
alt_sep = self._alternative_path_separator(path)
if path.endswith(sep) or (alt_sep and path.endswith(alt_sep)):
path = path[:-1]

parent_directory, child_name = self.SplitPath(path)
if not parent_directory:
parent_directory = self.cwd
Expand Down Expand Up @@ -2858,11 +2865,6 @@ def samefile(self, path1, path2):
stat2 = self.filesystem.GetStat(path2)
return stat1.st_ino == stat2.st_ino and stat1.st_dev == stat2.st_dev

if sys.platform.startswith('linux') and sys.version_info >= (3, 3):
def listxattr(path=None, follow_symlinks=True):
"""Dummy implementation that returns an empty list - used by shutil."""
return []

def _joinrealpath(self, path, rest, seen):
"""Join two paths, normalizing and eliminating any symbolic links
encountered in the second path.
Expand Down Expand Up @@ -3270,6 +3272,11 @@ def listdir(self, target_directory):
"""
return self.filesystem.ListDir(target_directory)

if sys.platform.startswith('linux') and sys.version_info >= (3, 3):
def listxattr(self, path=None, follow_symlinks=True):
"""Dummy implementation that returns an empty list - used by shutil."""
return []

if sys.version_info >= (3, 5):
def scandir(self, path=''):
"""Return an iterator of DirEntry objects corresponding to the entries
Expand Down

0 comments on commit c315342

Please sign in to comment.