Commits

Terry Jan Reedy  committed 681979c

Issue #21982: Add minimal unittest for configDialog with 46% coverage.
Fix regression that this test would have caught.

  • Participants
  • Parent commits e461e35
  • Branches 3.4

Comments (0)

Files changed (2)

File Lib/idlelib/configDialog.py

 
 class ConfigDialog(Toplevel):
 
-    def __init__(self,parent,title,_htest=False):
+    def __init__(self, parent, title, _htest=False, _utest=False):
         """
         _htest - bool, change box location when running htest
+        _utest - bool, don't wait_window when running unittest
         """
         Toplevel.__init__(self, parent)
         self.wm_withdraw()
         self.LoadConfigs()
         self.AttachVarCallbacks() #avoid callbacks during LoadConfigs
 
-        self.wm_deiconify()
-        self.wait_window()
+        if not _utest:
+            self.wm_deiconify()
+            self.wait_window()
 
     def CreateWidgets(self):
         self.tabPages = TabbedPageSet(self,
         if self.listBindings.curselection():
             reselect=1
             listIndex=self.listBindings.index(ANCHOR)
-        # keySet=idleConf.GetKeySet(keySetName) # unused, delete?
+        keySet=idleConf.GetKeySet(keySetName)
         bindNames = list(keySet.keys())
         bindNames.sort()
         self.listBindings.delete(0,END)
         pass
 
 if __name__ == '__main__':
+    import unittest
+    unittest.main('idlelib.idle_test.test_configdialog',
+                  verbosity=2, exit=False)
+
     from idlelib.idle_test.htest import run
     run(ConfigDialog)

File Lib/idlelib/idle_test/test_configdialog.py

+'''Unittests for idlelib/configHandler.py
+
+Coverage: 46% just by creating dialog. The other half is change code.
+
+'''
+import unittest
+from test.support import requires
+from tkinter import Tk
+from idlelib.configDialog import ConfigDialog
+from idlelib.macosxSupport import _initializeTkVariantTests
+
+
+class ConfigDialogTest(unittest.TestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        requires('gui')
+        cls.root = Tk()
+        _initializeTkVariantTests(cls.root)
+
+    @classmethod
+    def tearDownClass(cls):
+        cls.root.destroy()
+        del cls.root
+
+    def test_dialog(self):
+        d=ConfigDialog(self.root, 'Test', _utest=True)
+        d.destroy()
+
+
+if __name__ == '__main__':
+    unittest.main(verbosity=2)