1import os 2import sys 3import unittest 4from test import test_support 5from Tkinter import Tcl, TclError 6 7test_support.requires('gui') 8 9class 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 42tests_gui = (TkLoadTest, ) 43 44if __name__ == "__main__": 45 test_support.run_unittest(*tests_gui) 46