Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rmtree fails on directory with trailing slash #177

Closed
matteosimone opened this issue Apr 21, 2017 · 1 comment · Fixed by #178
Closed

rmtree fails on directory with trailing slash #177

matteosimone opened this issue Apr 21, 2017 · 1 comment · Fixed by #178
Labels

Comments

@matteosimone
Copy link

Hi,

I am having issues with the fake shutil module. It seems to fail if the directory has a trailing slash. Am I using this incorrectly?

Here is the exception from when I run the sample program below on Python 3.5, pyfakefs 3.1:

Traceback (most recent call last):
  File "/Users/dev/.virtualenvs/xyz/lib/python3.5/site-packages/pyfakefs/fake_filesystem.py", line 1533, in RemoveObject
    target_directory.RemoveEntry(basename)
  File "/Users/dev/.virtualenvs/xyz/lib/python3.5/site-packages/pyfakefs/fake_filesystem.py", line 474, in RemoveEntry
    entry = self.contents[pathname_name]
KeyError: ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test_rmtree.py", line 28, in <module>
    test_fakefs()
  File "test_rmtree.py", line 15, in test_fakefs
    FakeShutilModule(fs2).rmtree('x/')
  File "/Users/dev/.virtualenvs/xyz/lib/python3.5/site-packages/pyfakefs/fake_filesystem_shutil.py", line 112, in rmtree
    self.filesystem.RemoveObject(path)
  File "/Users/dev/.virtualenvs/xyz/lib/python3.5/site-packages/pyfakefs/fake_filesystem.py", line 1537, in RemoveObject
    file_path)
import os
import shutil

from pyfakefs.fake_filesystem_shutil import FakeShutilModule
import pyfakefs.fake_filesystem as fake_fs


def test_fakefs():
    fs = fake_fs.FakeFilesystem()
    fake_fs.FakeOsModule(fs).mkdir('x')
    FakeShutilModule(fs).rmtree('x')

    fs2 = fake_fs.FakeFilesystem()
    fake_fs.FakeOsModule(fs2).mkdir('x')
    FakeShutilModule(fs2).rmtree('x/')


def test_real():
    os.mkdir('x')
    shutil.rmtree('x')

    os.mkdir('x')
    shutil.rmtree('x/')


if __name__ == '__main__':
    test_real()
    test_fakefs()
@mrbean-bremen
Copy link
Member

Seems like a bug in pyfakefs. I may have a look in a couple of days, hopefully (currently fighting a virus - real, not computer)...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants