Home | History | Annotate | Download | only in test
      1 import os
      2 import unittest
      3 from test import test_support
      4 
      5 # Skip this test if _tkinter wasn't built.
      6 test_support.import_module('_tkinter')
      7 
      8 this_dir = os.path.dirname(os.path.abspath(__file__))
      9 lib_tk_test = os.path.abspath(os.path.join(this_dir, os.path.pardir,
     10     'lib-tk', 'test'))
     11 
     12 with test_support.DirsOnSysPath(lib_tk_test):
     13     import runtktests
     14 
     15 # Skip test if tk cannot be initialized.
     16 runtktests.check_tk_availability()
     17 
     18 import ttk
     19 from _tkinter import TclError
     20 
     21 try:
     22     ttk.Button()
     23 except TclError, msg:
     24     # assuming ttk is not available
     25     raise unittest.SkipTest("ttk not available: %s" % msg)
     26 
     27 def test_main(enable_gui=False):
     28     if enable_gui:
     29         if test_support.use_resources is None:
     30             test_support.use_resources = ['gui']
     31         elif 'gui' not in test_support.use_resources:
     32             test_support.use_resources.append('gui')
     33 
     34     with test_support.DirsOnSysPath(lib_tk_test):
     35         from test_ttk.support import get_tk_root
     36         try:
     37             test_support.run_unittest(
     38                 *runtktests.get_tests(text=False, packages=['test_ttk']))
     39         finally:
     40             get_tk_root().destroy()
     41 
     42 if __name__ == '__main__':
     43     test_main(enable_gui=True)
     44