@@ -87,28 +87,32 @@ def run_micropython(pyb, args, test_file, is_special=False):
8787 def get (required = False ):
8888 rv = b''
8989 while True :
90- ready = select .select ([master ], [], [], 0.02 )
91- if ready [0 ] == [master ]:
92- rv += os .read (master , 1024 )
90+ ready = select .select ([emulator ], [], [], 0.02 )
91+ if ready [0 ] == [emulator ]:
92+ rv += os .read (emulator , 1024 )
9393 else :
9494 if not required or rv :
9595 return rv
9696
9797 def send_get (what ):
98- os .write (master , what )
98+ os .write (emulator , what )
9999 return get ()
100100
101101 with open (test_file , 'rb' ) as f :
102102 # instead of: output_mupy = subprocess.check_output(args, stdin=f)
103- master , slave = pty .openpty ()
104- p = subprocess .Popen (args , stdin = slave , stdout = slave ,
103+ # openpty returns two read/write file descriptors. The first one is
104+ # used by the program which provides the virtual
105+ # terminal service, and the second one is used by the
106+ # subprogram which requires a tty to work.
107+ emulator , subterminal = pty .openpty ()
108+ p = subprocess .Popen (args , stdin = subterminal , stdout = subterminal ,
105109 stderr = subprocess .STDOUT , bufsize = 0 )
106110 banner = get (True )
107111 output_mupy = banner + b'' .join (send_get (line ) for line in f )
108112 send_get (b'\x04 ' ) # exit the REPL, so coverage info is saved
109113 p .kill ()
110- os .close (master )
111- os .close (slave )
114+ os .close (emulator )
115+ os .close (subterminal )
112116 else :
113117 output_mupy = subprocess .check_output (args + [test_file ], stderr = subprocess .STDOUT )
114118 except subprocess .CalledProcessError :
0 commit comments