-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
Expand file tree
/
Copy pathtest_tkinter_pipe.py
More file actions
55 lines (46 loc) · 1.91 KB
/
test_tkinter_pipe.py
File metadata and controls
55 lines (46 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# test_tkinter_pipe.py
import unittest
import subprocess
import sys
from test import support
@unittest.skipUnless(support.has_subprocess_support, "test requires subprocess")
class TkinterPipeTest(unittest.TestCase):
def test_tkinter_pipe_buffered(self):
args = [sys.executable, "-i"]
proc = subprocess.Popen(args,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
proc.stdin.write(b"import tkinter\n")
proc.stdin.write(b"interpreter = tkinter.Tcl()\n")
proc.stdin.write(b"print('hello')\n")
proc.stdin.write(b"print('goodbye')\n")
proc.stdin.write(b"quit()\n")
stdout, stderr = proc.communicate()
stdout = stdout.decode()
self.assertEqual(stdout.split(), ['hello', 'goodbye'])
def test_tkinter_pipe_unbuffered(self):
args = [sys.executable, "-i", "-u"]
proc = subprocess.Popen(args,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
proc.stdin.write(b"import tkinter\n")
proc.stdin.write(b"interpreter = tkinter.Tcl()\n")
proc.stdin.write(b"print('hello')\n")
proc.stdin.flush()
stdout = proc.stdout.readline()
stdout = stdout.decode()
self.assertEqual(stdout.strip(), 'hello')
proc.stdin.write(b"print('hello again')\n")
proc.stdin.flush()
stdout = proc.stdout.readline()
stdout = stdout.decode()
self.assertEqual(stdout.strip(), 'hello again')
proc.stdin.write(b"print('goodbye')\n")
proc.stdin.write(b"quit()\n")
stdout, stderr = proc.communicate()
stdout = stdout.decode()
self.assertEqual(stdout.strip(), 'goodbye')
if __name__ == "__main__":
unittest.main()