• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import unittest
2import tkinter
3from test.support import requires, swap_attr
4from tkinter.test.support import AbstractDefaultRootTest
5from tkinter.simpledialog import Dialog, askinteger
6
7requires('gui')
8
9
10class DefaultRootTest(AbstractDefaultRootTest, unittest.TestCase):
11
12    def test_askinteger(self):
13        @staticmethod
14        def mock_wait_window(w):
15            nonlocal ismapped
16            ismapped = w.master.winfo_ismapped()
17            w.destroy()
18
19        with swap_attr(Dialog, 'wait_window', mock_wait_window):
20            ismapped = None
21            askinteger("Go To Line", "Line number")
22            self.assertEqual(ismapped, False)
23
24            root = tkinter.Tk()
25            ismapped = None
26            askinteger("Go To Line", "Line number")
27            self.assertEqual(ismapped, True)
28            root.destroy()
29
30            tkinter.NoDefaultRoot()
31            self.assertRaises(RuntimeError, askinteger, "Go To Line", "Line number")
32
33
34if __name__ == "__main__":
35    unittest.main()
36