ยปCore Development>Code coverage>Lib/tkinter/test/test_tkinter/test_loadtk.py

Python code coverage for Lib/tkinter/test/test_tkinter/test_loadtk.py

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