@contextmanager<EOL>def mockedopen(fakefiles=None):
fakefiles = fakefiles or {}<EOL>def mock_open(name, mode=None, buffering=None): <EOL><INDENT>"<STR_LIT>"<EOL>mode = mode or "<STR_LIT:r>"<EOL>if mode.startswith('<STR_LIT:r>'):<EOL><INDENT>if name not in fakefiles:<EOL><INDENT>raise OSError((errno.ENOENT, "<STR_LIT>", name))<EOL><DEDENT>try:<EOL><INDENT>fakefiles[name].close()<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT>return StringIO(fakefiles[name])<EOL><DEDENT>else:<EOL><INDENT>return DictItemIO(fakefiles, name)<EOL><DEDENT><DEDENT>with mock.patch("<STR_LIT>" if PY2 else "<STR_LIT>", mock_open):<EOL><INDENT>yield fakefiles<EOL><DEDENT>
Mock the open call to use a dict as the file system.

        @param fakefiles: Prepopulated filesystem, this is passed on as the context's target.