File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import unittest
2+ import subprocess
3+ import sys
4+ from test import support
5+ from test .support import import_helper
6+
7+ tkinter = import_helper .import_module ("tkinter" )
8+
9+
10+ @unittest .skipUnless (support .has_subprocess_support , "test requires subprocess" )
11+ class TkStdinPipe (unittest .TestCase ):
12+
13+ def test_pipe_stdin (self ):
14+ proc = subprocess .Popen ([sys .executable , "-i" ],
15+ stdin = subprocess .PIPE ,
16+ stdout = subprocess .PIPE ,
17+ stderr = subprocess .PIPE )
18+ proc .stdin .write (b"import tkinter\n " )
19+ proc .stdin .write (b"interpreter = tkinter.Tcl()\n " )
20+ proc .stdin .write (b"print('hello')\n " )
21+ proc .stdin .write (b"quit()\n " )
22+
23+ stdout , stderr = proc .communicate ()
24+ stdout = stdout .decode ()
25+ stderr = stderr .decode ()
26+
27+ if proc .returncode != 0 :
28+ self .fail (f"Child exited with { proc .returncode } \n STDOUT:\n { out } \n STDERR:\n { err } " )
29+
30+ self .assertEqual (stdout .rstrip (), "hello" )
31+
32+
33+ if __name__ == "__main__" :
34+ unittest .main ()
You can’t perform that action at this time.
0 commit comments