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