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 import ttk 9 from _tkinter import TclError 10 11 try: 12 ttk.Button() 13 except TclError, msg: 14 # assuming ttk is not available 15 raise unittest.SkipTest("ttk not available: %s" % msg) 16 17 this_dir = os.path.dirname(os.path.abspath(__file__)) 18 lib_tk_test = os.path.abspath(os.path.join(this_dir, os.path.pardir, 19 'lib-tk', 'test')) 20 21 with test_support.DirsOnSysPath(lib_tk_test): 22 import runtktests 23 24 def test_main(enable_gui=False): 25 if enable_gui: 26 if test_support.use_resources is None: 27 test_support.use_resources = ['gui'] 28 elif 'gui' not in test_support.use_resources: 29 test_support.use_resources.append('gui') 30 31 with test_support.DirsOnSysPath(lib_tk_test): 32 from test_ttk.support import get_tk_root 33 try: 34 test_support.run_unittest( 35 *runtktests.get_tests(text=False, packages=['test_ttk'])) 36 finally: 37 get_tk_root().destroy() 38 39 if __name__ == '__main__': 40 test_main(enable_gui=True) 41