1 | n/a | import os |
---|
2 | n/a | import sys |
---|
3 | n/a | import unittest |
---|
4 | n/a | import test.support as test_support |
---|
5 | n/a | from tkinter import Tcl, TclError |
---|
6 | n/a | |
---|
7 | n/a | test_support.requires('gui') |
---|
8 | n/a | |
---|
9 | n/a | class TkLoadTest(unittest.TestCase): |
---|
10 | n/a | |
---|
11 | n/a | @unittest.skipIf('DISPLAY' not in os.environ, 'No $DISPLAY set.') |
---|
12 | n/a | def testLoadTk(self): |
---|
13 | n/a | tcl = Tcl() |
---|
14 | n/a | self.assertRaises(TclError,tcl.winfo_geometry) |
---|
15 | n/a | tcl.loadtk() |
---|
16 | n/a | self.assertEqual('1x1+0+0', tcl.winfo_geometry()) |
---|
17 | n/a | tcl.destroy() |
---|
18 | n/a | |
---|
19 | n/a | def testLoadTkFailure(self): |
---|
20 | n/a | old_display = None |
---|
21 | n/a | if sys.platform.startswith(('win', 'darwin', 'cygwin')): |
---|
22 | n/a | # no failure possible on windows? |
---|
23 | n/a | |
---|
24 | n/a | # XXX Maybe on tk older than 8.4.13 it would be possible, |
---|
25 | n/a | # see tkinter.h. |
---|
26 | n/a | return |
---|
27 | n/a | with test_support.EnvironmentVarGuard() as env: |
---|
28 | n/a | if 'DISPLAY' in os.environ: |
---|
29 | n/a | del env['DISPLAY'] |
---|
30 | n/a | # on some platforms, deleting environment variables |
---|
31 | n/a | # doesn't actually carry through to the process level |
---|
32 | n/a | # because they don't support unsetenv |
---|
33 | n/a | # If that's the case, abort. |
---|
34 | n/a | with os.popen('echo $DISPLAY') as pipe: |
---|
35 | n/a | display = pipe.read().strip() |
---|
36 | n/a | if display: |
---|
37 | n/a | return |
---|
38 | n/a | |
---|
39 | n/a | tcl = Tcl() |
---|
40 | n/a | self.assertRaises(TclError, tcl.winfo_geometry) |
---|
41 | n/a | self.assertRaises(TclError, tcl.loadtk) |
---|
42 | n/a | |
---|
43 | n/a | tests_gui = (TkLoadTest, ) |
---|
44 | n/a | |
---|
45 | n/a | if __name__ == "__main__": |
---|
46 | n/a | test_support.run_unittest(*tests_gui) |
---|