Skip to main content

Context manager for mocking/wrapping stdin/stdout/stderr

Project description

Python context manager for mocking/wrapping stdin/stdout/stderr

https://travis-ci.org/bskinn/stdio-mgr.svg?branch=dev https://codecov.io/gh/bskinn/stdio-mgr/branch/dev/graph/badge.svg https://img.shields.io/pypi/v/stdio_mgr.svg https://img.shields.io/pypi/pyversions/stdio-mgr.svg https://img.shields.io/github/license/mashape/apistatus.svg

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


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)

Uploaded Source

Built Distribution

stdio_mgr-1.0rc1-py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page