How to override stdin for tests simulating user input? #9954
Unanswered
DavesCodeMusings
asked this question in
Using MicroPython
Replies: 1 comment 1 reply
-
@DavesCodeMusings I think you can use |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I've got an interactive program that I'd like to write some tests for. It requires simulating user input, so I'm trying to override stdin to pass pre-defined input. Unfortunately, I've succeeded only in crashing the system so far.
I started with this, based on examples I found on the interwebs:
It works great in CPython, but fails in MicroPython. I think I know why, but I'm unsure how to fix it.
In CPython, sys.stdin is a TextIOWrapper
But in MicroPython it's FileIO
So I tried changing it:
Now I've made things worse and running the code above causes an unhandled exception that reboots the board. I also tried getting more specific with
sys.stdin.read
, but again I'm just crashing the board.Not exactly where to go next. I'm hoping someone has done this kind of thing before and can point me in the right direction. Or is there another way to send simulated user input to a MicroPython program's stdin?
Beta Was this translation helpful? Give feedback.
All reactions