Skip to content

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

Closed
@kamichal

Description

@kamichal

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions