bskinn / stdio-mgr

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

Add support for bytes in init_text arg of stdio_mgr #36

Open bskinn opened 5 years ago

bskinn commented 5 years ago

jayvdb:

(That also needed binary init_text so it cant adopt stdio-mgr quite yet)

Certain use-cases will benefit from stdio_mgr taking either str or bytes in the init_text argument.

bskinn commented 5 years ago

@jayvdb I figure part of the challenge here is dealing with the encoding... is part of it also having to change the type of the output between str and bytes depending on the type of the content passed to init_text?

I.e., StdioManager.stdout should be made to be of the same type (& encoding, if relevant) as init_text?

jayvdb commented 5 years ago

It isnt hard to change the code. Writing the tests is however quite a bit of work.

The main problem was that the attr checks on init_text would need to be weakened to allow bytes or str, and I have been looking to avoid that, because I find that any time bytes or str are allowed, people make mistakes and they end up reporting weird errors stemming from the mistake.

https://github.com/bskinn/stdio-mgr/pull/64 should get us on the path to using different classes for bytes (e.g. class names can include Raw or Bytes for those versions), or adding class methods, to handle different types with proper type checking.