bskinn / stdio-mgr

Context manager for mocking/wrapping stdin/stdout/stderr
MIT License
14 stars 4 forks source link

Cannibalize coala-utils ContextManagers #59

Open jayvdb opened 5 years ago

jayvdb commented 5 years ago

There are some useful bits of coala-utils ContextManagers which may be desirable features here, especially simulate_console_inputs which is extensively used in https://github.com/coala/coala/ testsuite.

Most of the concepts in coala-utils ContextManagers are likely already pending issues here, or can be achieved using the existing functionality. I envisage this issue here is mostly to map coala-utils to stdio-mgr, discuss and track progress.

Created https://gitlab.com/coala/coala-utils/issues/88 for the other side, once most of the necessary enhancements are done here. There is no need to replicate exactly the same functionality, or do it all in one release. coala would contain to use its own wrapper, but it would become a thin layer to stdio-mgr , and possibly (lightly) deprecating some bits where the coala-utils tool has no benefits over the stdio-mgr replacement.

bskinn commented 5 years ago

Mm, simulate_console_inputs definitely has a much more attractive API than stdio-mgr's current init_text. Seems like that could be mimicked in stdio-mgr by just a '\n'.join() on any initialization argument that's a non-str iterable.

For clarity, maybe better to create a new kwarg for it, though?

jayvdb commented 5 years ago

https://github.com/bskinn/stdio-mgr/pull/62 is the first step for a stdin-only-capture.

I did a POC of revised coala-utils & coala, based on top of #64, code at https://gitlab.com/jayvdb/coala-utils/blob/a8212112f5a6dd214422077cdbe1d0447b1291db/coala_utils/ContextManagers.py#L151 which shows the extra features in stdio-mgr needed to have a comparable feature set.

The two usages of last_input (ignoring ContextManagersTest which is a copy of the same in coala-utils, I hope) are worth considering adding here.

https://github.com/coala/coala/blob/6a24dac547e5a6936ccd43068f2fff5753744d7b/tests/settings/SectionFillingTest.py#L52 is asserting that the read buffer was not used, which is easy to achieve a different way.

https://github.com/coala/coala/blob/3eaae8875055d5340b707adaa53c289dd6b96725/tests/output/ConsoleInteractionTest.py#L219 is asserting that the buffer is fully used, again easy to implement a different way.

I had to disable pytest capturing all the way, so something is amiss somewhere, probably in #64 , and even with that the coala test log is full of errors so more is needed.

jayvdb commented 5 years ago

I had to disable pytest capturing all the way, so something is amiss somewhere, probably in #64 , and even with that the coala test log is full of errors so more is needed.

This has been fixed with a tweak to #64 and a fix in coala's test logic to workaround https://github.com/bskinn/stdio-mgr/issues/73

The next bit is https://github.com/bskinn/stdio-mgr/issues/74 , and/or the more advanced version https://github.com/bskinn/stdio-mgr/issues/75

jayvdb commented 5 years ago

Offtopic, another set of similar functions at https://github.com/Erotemic/ubelt/blob/master/ubelt/util_stream.py .

We might want to document prior art in the README, or in the docs.

bskinn commented 5 years ago

We might want to document prior art in the README, or in the docs.

New issue to curate?