Debian Codegraph @

Lib/test/test_tkinter/test_loadtk.py

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