rework test for #1782, add simple mocking and a stdin_encoding context_manager
I was unhappy with the way I left the test in #1782. 
This is cleaner, and the test actually works, which is always nice.

The mocking helper is primitive, but at least no new dependency is added.
