| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,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(timeout=support.SHORT_TIMEOUT) | ||
| 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(timeout=support.SHORT_TIMEOUT) | ||
| stdout = stdout.decode() | ||
| self.assertEqual(stdout.strip(), 'goodbye') | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Prevent :mod:`tkinter` from hanging on Windows if stdin is redirected to a pipe in an | ||
| interactive session. This is helpful for testing interactive usage of | ||
| tkinter from a script, for example as part of the cpython test suite. |
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.