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

create_file(..., contents=None) unintentionally crates a "large file" #424

Closed
kamichal opened this issue Aug 24, 2018 · 1 comment · Fixed by #425
Closed

create_file(..., contents=None) unintentionally crates a "large file" #424

kamichal opened this issue Aug 24, 2018 · 1 comment · Fixed by #425

Comments

@kamichal
Copy link

Seems it's a lack in the API:

    # pytest
    def test_thinks_is_a_large_file(fs):
        fs.create_file("/tmp/file.txt", contents=None)
    
        with open("/tmp/file.txt", 'rt') as ff:
            ff.read()

If the contents is None there is no chance to later read the file.
In my opinion None in this API should be equivalent to "" - giving an empty file. However at read attempt it raises:

    self = <pyfakefs.fake_filesystem.FakeFileWrapper object at 0x7f5a8c6dd310>
    name = 'read'
    
        def __getattr__(self, name):
            if self.file_object.is_large_file():
    >           raise FakeLargeFileIoException(self._file_path)
    E           FakeLargeFileIoException: Read and write operations not supported for fake large file: /tmp/file.txt

Of course setting contents='' works OK.

@kamichal kamichal changed the title create_file(..., contents=None) unintentionally crates a "large file" create_file(..., contents=None) unintentionally crates a "large file" Aug 24, 2018
@mrbean-bremen
Copy link
Member

Well, given that the default value for contents is an empty string, you have to explicitely pass None to contents in create_file(), so this has to be a conscious decision. But I agree that handling None contents as empty contents as long as st_size is also None makes sense.

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

Successfully merging a pull request may close this issue.

2 participants