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

shutil.make_archive does not work with pyfakefs #104

Closed
borismod opened this issue May 18, 2016 · 5 comments · Fixed by #115
Closed

shutil.make_archive does not work with pyfakefs #104

borismod opened this issue May 18, 2016 · 5 comments · Fixed by #115
Labels

Comments

@borismod
Copy link

Hi, guys

It's me again with ZIP issues. I started using shutil.make_archive and it seems that it does not work with fakefs.

Any idea how it can be fixed?

import shutil
import unittest
from pyfakefs import fake_filesystem_unittest


class TestPackageBuilder(fake_filesystem_unittest.TestCase):
    def setUp(self):
        self.setUpPyfakefs()

    def test_zip(self):
        self.fs.CreateFile(u'c:\\test\\readme.txt', contents='')

        shutil.make_archive(u'c:\\test\\some_file.zip', 'zip', u'c:\\test')

        self.assertFileExists(u'c:\\test\\some_file.zip')

    def assertFileExists(self, file_path):
        self.assertTrue(os.path.exists(file_path), msg='File {0} does not exist'.format(file_path))

Fails with the following error:

Error
Traceback (most recent call last):
File "C:\Python27\lib\unittest\case.py", line 329, in run
File "C:\work\GitHub\shellfoundry\tests\test_package_builder.py", line 32, in test_zip
File "C:\Python27\lib\shutil.py", line 527, in make_archive
WindowsError: [Error 2] The system cannot find the file specified: u'c:\test'

@mrbean-bremen
Copy link
Member

Seems like you are out of luck here - shutil.make_archive() is not implemented in fakefs (yet), and I don't see any workaround at the moment other than using zipfile directly.

@borismod
Copy link
Author

@mrbean-bremen should I open an issue to shutil maintainers?

@mrbean-bremen
Copy link
Member

No, this is an issue with pyfakefs, so this is already the right place for the issue.
Disclaimer: I'm just a user of pyfakefs, so don't rely on my judgment :)

@mrbean-bremen
Copy link
Member

mrbean-bremen commented Jun 14, 2016

I just had another look at this, and the reason why it does not work is the usage of the real os module inside shutil.py. If removing 'shutil' from SKIPNAMES, it will work (if also removing the unneeded .zip extension from the filename in the above test code).
I see no immediate problem with this, as shutil is kind of a derived module and IMO it makes sense to stub out os inside this module, but there may be side effects I'm not aware of. @jmcgeheeiv: can you comment on this? I think you wrote all the unit test code.
Maybe SKIPNAMES shall be configurable for different needs, as there seem to be other related issues (#43, #106) ?

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Jun 29, 2016
- added possibility to add own skipnames in derived test class
- fixes pytest-dev#104
- can be used to fix pytest-dev#106
@jmcgeheeiv
Copy link
Contributor

Closing since @mrbean-bremen removed shutil from SKIPNAMES.

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.

3 participants