Context manager for mocking/wrapping stdin/stdout/stderr
Project description
Python context manager for mocking/wrapping stdin/stdout/stderr
README draft in progress.
Have a command-line Python application? Want to test […continued]
[more about mocking stdio]
In addition to mocking stdio for testing, stdio_mgr can also be used to wrap functions that directly interact with stdio. Example:
>>> def embellish(func):
... def func_wrapper(s):
... from stdio_mgr import stdio_mgr
...
... with stdio_mgr() as (i, o, e):
... func(s)
... content = o.getvalue()
... newcontent = '*** ' + content.replace('\n', ' ***\n*** ')
... newcontent = newcontent[:-5]
... print(newcontent)
... return func_wrapper
>>> @embellish
... def testfunc(s):
... print(s)
>>> testfunc("""\
... Foo bar baz quux.
... Lorem ipsum dolor sit amet....""")
*** Foo bar baz quux. ***
*** Lorem ipsum dolor sit amet.... ***
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
stdio-mgr-1.0rc1.tar.gz
(4.1 kB
view hashes)
Built Distribution
Close
Hashes for stdio_mgr-1.0rc1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53905e5d41dad9a2ca75304d0fc2de7a63c941243b75901107f46ca053b4d64a |
|
MD5 | 08f3bc37b58692f7c1150119ab578de1 |
|
BLAKE2b-256 | 1aaf8d2bb815d9993747a8946d2977fba86b1a1542c1012181a0d7eea4166a87 |