Mock for tkinter.messagebox with an Mbox_func for each function. Example usage in test_module.py for testing functions in module.py: --- from idlelib.idle_test.mock_tk import Mbox import module orig_mbox = module.messagebox showerror = Mbox.showerror # example, for attribute access in tes
| 57 | |
| 58 | |
| 59 | class Mbox: |
| 60 | """Mock for tkinter.messagebox with an Mbox_func for each function. |
| 61 | |
| 62 | Example usage in test_module.py for testing functions in module.py: |
| 63 | --- |
| 64 | from idlelib.idle_test.mock_tk import Mbox |
| 65 | import module |
| 66 | |
| 67 | orig_mbox = module.messagebox |
| 68 | showerror = Mbox.showerror # example, for attribute access in test methods |
| 69 | |
| 70 | class Test(unittest.TestCase): |
| 71 | |
| 72 | @classmethod |
| 73 | def setUpClass(cls): |
| 74 | module.messagebox = Mbox |
| 75 | |
| 76 | @classmethod |
| 77 | def tearDownClass(cls): |
| 78 | module.messagebox = orig_mbox |
| 79 | --- |
| 80 | For 'ask' functions, set func.result return value before calling the method |
| 81 | that uses the message function. When messagebox functions are the |
| 82 | only GUI calls in a method, this replacement makes the method GUI-free, |
| 83 | """ |
| 84 | askokcancel = Mbox_func() # True or False |
| 85 | askquestion = Mbox_func() # 'yes' or 'no' |
| 86 | askretrycancel = Mbox_func() # True or False |
| 87 | askyesno = Mbox_func() # True or False |
| 88 | askyesnocancel = Mbox_func() # True, False, or None |
| 89 | showerror = Mbox_func() # None |
| 90 | showinfo = Mbox_func() # None |
| 91 | showwarning = Mbox_func() # None |
| 92 | |
| 93 | |
| 94 | class Text: |
nothing calls this directly
no test coverage detected
searching dependent graphs…