Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality for selective mocking/wrapping of individual streams or stream combinations #4

Open
bskinn opened this issue Mar 25, 2018 · 3 comments
Labels
enhancement New feature or request needs tests Tests are absent or incomplete for this
Milestone

Comments

@bskinn
Copy link
Owner

bskinn commented Mar 25, 2018

Only stdout, or only stderr; or stdout and stdin but not stderr; etc.

contextlib in the standard library already exists for singly mocking stdout and stderr, but there's potential for stdio_mgr to represent a more concise and customizeable means for mocking multiple streams. The stdin mock appears to be a novel capability, though?

@bskinn bskinn added the maybe This may or may not be implemented label Mar 25, 2018
@bskinn bskinn changed the title Add functionality for selective mocking/wrapping of individual streams Add functionality for selective mocking/wrapping of individual streams or stream combinations Mar 28, 2018
@bskinn bskinn added this to the Future milestone Apr 3, 2018
@bskinn bskinn modified the milestones: Future, v2.0 Jul 29, 2019
@bskinn bskinn added enhancement New feature or request needs tests Tests are absent or incomplete for this and removed maybe This may or may not be implemented labels Jul 29, 2019
@jayvdb
Copy link
Contributor

jayvdb commented Aug 22, 2019

For this, I would like to explore either

  1. always conceptualising the three as a discrete object, and using class methods to instantiate different tuples, or
  2. borrowing semantics from Popen and how it allows the three streams to be instantiated & managed.

jayvdb added a commit to jayvdb/stdio-mgr that referenced this issue Aug 26, 2019
TeeStdin is only needed when both stdin and stdout are being
programmatically managed.  If only stdin is being mocked, and
stdout should behave normally, the context manager should use
the new lighter SimulateStdin which does not perform a tee.

Also removes attrs dependency, which had few benefits anyhow,
and complicates matters when building a deep class hierarchy.

Related to bskinn#4
jayvdb added a commit to jayvdb/stdio-mgr that referenced this issue Aug 26, 2019
TeeStdin is only needed when both stdin and stdout are being
programmatically managed.  If only stdin is being mocked, and
stdout should behave normally, the context manager should use
the new lighter SimulateStdin which does not perform a tee.

Also removes attrs dependency, which had few benefits anyhow,
and complicates matters when building a deep class hierarchy.

Related to bskinn#4
jayvdb added a commit to jayvdb/stdio-mgr that referenced this issue Aug 26, 2019
TeeStdin is only needed when both stdin and stdout are being
programmatically managed.  If only stdin is being mocked, and
stdout should behave normally, the context manager should use
the new lighter SimulateStdin which does not perform a tee.

Also removes attrs dependency, which had few benefits anyhow,
and complicates matters when building a deep class hierarchy.

Related to bskinn#4
jayvdb added a commit to jayvdb/stdio-mgr that referenced this issue Aug 26, 2019
TeeStdin is only needed when both stdin and stdout are being
programmatically managed.  If only stdin is being mocked, and
stdout should behave normally, the context manager should use
the new lighter SimulateStdin which does not perform a tee.

Also removes attrs dependency, which had few benefits anyhow,
and complicates matters when building a deep class hierarchy.

Related to bskinn#4
jayvdb added a commit to jayvdb/stdio-mgr that referenced this issue Aug 26, 2019
TeeStdin is only needed when both stdin and stdout are being
programmatically managed.  If only stdin is being mocked, and
stdout should behave normally, the context manager should use
the new lighter SimulateStdin which does not perform a tee.

Also removes attrs dependency, which had few benefits anyhow,
and complicates matters when building a deep class hierarchy.

Related to bskinn#4
jayvdb added a commit to jayvdb/stdio-mgr that referenced this issue Aug 26, 2019
TeeStdin is only needed when both stdin and stdout are being
programmatically managed.  If only stdin is being mocked, and
stdout should behave normally, the context manager should use
the new lighter SimulateStdin which does not perform a tee.

Also removes attrs dependency, which had few benefits anyhow,
and complicates matters when building a deep class hierarchy.

And removes TeeStdin.SEEK_END and TeeStdin.SEEK_SET.

Related to bskinn#4
jayvdb added a commit to jayvdb/stdio-mgr that referenced this issue Aug 26, 2019
TeeStdin is only needed when both stdin and stdout are being
programmatically managed.  If only stdin is being mocked, and
stdout should behave normally, the context manager should use
the new lighter SimulateStdin which does not perform a tee.

Also removes attrs dependency, which had few benefits anyhow,
and complicates matters when building a deep class hierarchy.

And removes TeeStdin.SEEK_END and TeeStdin.SEEK_SET.

Related to bskinn#4
jayvdb added a commit to jayvdb/stdio-mgr that referenced this issue Aug 26, 2019
TeeStdin is only needed when both stdin and stdout are being
programmatically managed.  If only stdin is being mocked, and
stdout should behave normally, the context manager should use
the new lighter SimulateStdin which does not perform a tee.

Also removes attrs dependency, which had few benefits anyhow,
and complicates matters when building a deep class hierarchy.

And removes TeeStdin.SEEK_END and TeeStdin.SEEK_SET.

Related to bskinn#4
jayvdb added a commit to jayvdb/stdio-mgr that referenced this issue Aug 26, 2019
TeeStdin is only needed when both stdin and stdout are being
programmatically managed.  If only stdin is being mocked, and
stdout should behave normally, the context manager should use
the new lighter SimulateStdin which does not perform a tee.

Also removes attrs dependency, which had few benefits anyhow,
and complicates matters when building a deep class hierarchy.

And removes TeeStdin.SEEK_END and TeeStdin.SEEK_SET.

Related to bskinn#4
jayvdb added a commit to jayvdb/stdio-mgr that referenced this issue Sep 4, 2019
TeeStdin is only needed when both stdin and stdout are being
programmatically managed.  If only stdin is being mocked, and
stdout should behave normally, the context manager should use
the new lighter SimulateStdin which does not perform a tee.

Also removes attrs dependency, which had few benefits anyhow,
and complicates matters when building a deep class hierarchy.

And removes TeeStdin.SEEK_END and TeeStdin.SEEK_SET.

Related to bskinn#4
jayvdb added a commit to jayvdb/stdio-mgr that referenced this issue Sep 4, 2019
TeeStdin is only needed when both stdin and stdout are being
programmatically managed.  If only stdin is being mocked, and
stdout should behave normally, the context manager should use
the new lighter SimulateStdin which does not perform a tee.

Also removes attrs dependency, which had few benefits anyhow,
and complicates matters when building a deep class hierarchy.

And removes TeeStdin.SEEK_END and TeeStdin.SEEK_SET.

Related to bskinn#4
@bskinn
Copy link
Owner Author

bskinn commented Sep 4, 2019

For this, I would like to explore either

  1. always conceptualising the three as a discrete object, and using class methods to instantiate different tuples, or

For this, would a user instantiate cm, use instance methods on cm to configure the desired redirection, and then enter the context?

>>> cm = StdioManager()
>>> cm.tee_stdin(cm.stdout)
>>> with cm:
...     ...
  1. borrowing semantics from Popen and how it allows the three streams to be instantiated & managed.

Do you mean syntax like the the Popen(..., stderr=subprocess.STDOUT)? (TBH, I'm still unclear on what subprocess.PIPE actually does.... <goes and reads the docs> Ohh, that connects pipes to the child process so that the output can be loaded into the communicate() return value in the parent.)

Separately, maybe it would make sense to have at least three redirection modes... tee-on-read, tee-on-write, and pipe? ('pipe' would pass anything written to the stream through to the target stream, without retaining an internal copy, as in bash's 2>&1.)

@jayvdb
Copy link
Contributor

jayvdb commented Sep 11, 2019

For this, would a user instantiate cm, use instance methods on cm to configure the desired redirection, and then enter the context?

Yes, like the example you have, but I am envisioning also the following for creation of new streams.

>>> with _current_stdio().tee(stdin="foo") as cm:
...     assert cm.stdout.getvalue() == "foo\n"

>>> with _current_stdio().tee(stdout=False, stderr=True) as cm:
...     print("foo")
...     assert cm.stderr.getvalue() == "foo\n"

Do you mean syntax like the the Popen(..., stderr=subprocess.STDOUT)?

Yes, specifically creating constants for the three streams, so non-default behaviour is written in semi-literate code.

Separately, maybe it would make sense to have at least three redirection modes... tee-on-read, tee-on-write, and pipe?

Sounds good. Thinking out loud ...

>>> with _current_stdio().pipe(in=stdio_mgr.STDIN, out=stdio_mgr.STDERR) as cm:
...     print("foo")
...     assert cm.stderr.getvalue() == "foo\n"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs tests Tests are absent or incomplete for this
Projects
None yet
Development

No branches or pull requests

2 participants