Debian Codegraph @

cpython27/Lib/lib-tk/test/test_tkinter/test_loadtk.py

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