Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def fake_open(module):
- """Patch module's `open` builtin so that it returns StringIOs instead of
- creating real files, which is useful for testing. Returns a dict that maps
- opened file names to StringIO objects."""
- from contextlib import closing
- from StringIO import StringIO
- streams = {}
- def fakeopen(filename,mode):
- stream = StringIO()
- stream.close = lambda: None
- streams[filename] = stream
- return closing(stream)
- module.open = fakeopen
- return streams
Add Comment
Please, Sign In to add comment