Skip to content

Commit d356c71

Browse files
author
ニヒル デ フーン ( Michiel de Hoon )
committed
add test script
1 parent c3d637b commit d356c71

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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}\nSTDOUT:\n{out}\nSTDERR:\n{err}")
29+
30+
self.assertEqual(stdout.rstrip(), "hello")
31+
32+
33+
if __name__ == "__main__":
34+
unittest.main()

0 commit comments

Comments
 (0)