8000 bpo-30290: IDLE: Add more tests for help_about dialog (#1697) · python/cpython@054e091 · GitHub
[go: up one dir, main page]

Skip to content

Commit 054e091

Browse files
mlouieluterryjreedy
authored andcommitted
bpo-30290: IDLE: Add more tests for help_about dialog (#1697)
Increases coverage to 99%
1 parent 8175547 commit 054e091

File tree

2 files changed

+99
-28
lines changed

2 files changed

+99
-28
lines changed

Lib/idlelib/help_about.py

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ class AboutDialog(Toplevel):
1313
"""Modal about dialog for idle
1414
1515
"""
16-
def __init__(self, parent, title, _htest=False):
16+
def __init__(self, parent, title, _htest=False, _utest=False):
1717
"""
1818
_htest - bool, change box location when running htest
19+
_utest - bool, don't wait_window when running unittest
1920
"""
2021
Toplevel.__init__(self, parent)
2122
self.configure(borderwidth=5)
@@ -35,7 +36,12 @@ def __init__(self, parent, title, _htest=False):
3536
self.buttonOk.focus_set()
3637
self.bind('<Return>',self.Ok) #dismiss dialog
3738
self.bind('<Escape>',self.Ok) #dismiss dialog
38-
self.wait_window()
39+
self._current_textview = None
40+
self._utest = _utest
41+
42+
if not _utest:
43+
self.deiconify()
44+
self.wait_window()
3945

4046
def CreateWidgets(self):
4147
release = version[:version.index(' ')]
@@ -80,18 +86,18 @@ def CreateWidgets(self):
8086
labelTkVer.grid(row=9, column=1, sticky=W, padx=2, pady=0)
8187
py_button_f = Frame(frameBg, bg=self.bg)
8288
py_button_f.grid(row=10, column=0, columnspan=2, sticky=NSEW)
83-
buttonLicense = Button(py_button_f, text='License', width=8,
84-
highlightbackground=self.bg,
85-
command=self.ShowLicense)
86-
buttonLicense.pack(side=LEFT, padx=10, < 8000 span class="pl-s1">pady=10)
87-
buttonCopyright = Button(py_button_f, text='Copyright', width=8,
88-
highlightbackground=self.bg,
89-
command=self.ShowCopyright)
90-
buttonCopyright.pack(side=LEFT, padx=10, pady=10)
91-
buttonCredits = Button(py_button_f, text='Credits', width=8,
92-
highlightbackground=self.bg,
93-
command=self.ShowPythonCredits)
94-
buttonCredits.pack(side=LEFT, padx=10, pady=10)
89+
self.buttonLicense = Button(py_button_f, text='License', width=8,
90+
highlightbackground=self.bg,
91+
command=self.ShowLicense)
92+
self.buttonLicense.pack(side=LEFT, padx=10, pady=10)
93+
self.buttonCopyright = Button(py_button_f, text='Copyright', width=8,
94+
highlightbackground=self.bg,
95+
command=self.ShowCopyright)
96+
self.buttonCopyright.pack(side=LEFT, padx=10, pady=10)
97+
self.buttonCredits = Button(py_button_f, text='Credits', width=8,
98+
highlightbackground=self.bg,
99+
command=self.ShowPythonCredits)
100+
self.buttonCredits.pack(side=LEFT, padx=10, pady=10)
95101
Frame(frameBg, borderwidth=1, relief=SUNKEN,
96102
height=2, bg=self.bg).grid(row=11, column=0, sticky=EW,
97103
columnspan=3, padx=5, pady=5)
@@ -100,18 +106,18 @@ def CreateWidgets(self):
100106
idle_v.grid(row=12, column=0, sticky=W, padx=10, pady=0)
101107
idle_button_f = Frame(frameBg, bg=self.bg)
102108
idle_button_f.grid(row=13, column=0, columnspan=3, sticky=NSEW)
103-
idle_about_b = Button(idle_button_f, text='README', width=8,
104-
highlightbackground=self.bg,
105-
command=self.ShowIDLEAbout)
106-
idle_about_b.pack(side=LEFT, padx=10, pady=10)
107-
idle_news_b = Button(idle_button_f, text='NEWS', width=8,
108-
highlightbackground=self.bg,
109-
command=self.ShowIDLENEWS)
110-
idle_news_b.pack(side=LEFT, padx=10, pady=10)
111-
idle_credits_b = Button(idle_button_f, text='Credits', width=8,
112-
highlightbackground=self.bg,
113-
command=self.ShowIDLECredits)
114-
idle_credits_b.pack(side=LEFT, padx=10, pady=10)
109+
self.idle_about_b = Button(idle_button_f, text='README', width=8,
110+
highlightbackground=self.bg,
111+
command=self.ShowIDLEAbout)
112+
self.idle_about_b.pack(side=LEFT, padx=10, pady=10)
113+
self.idle_news_b = Button(idle_button_f, text='NEWS', width=8,
114+
highlightbackground=self.bg,
115+
command=self.ShowIDLENEWS)
116+
self.idle_news_b.pack(side=LEFT, padx=10, pady=10)
117+
self.idle_credits_b = Button(idle_button_f, text='Credits', width=8,
118+
highlightbackground=self.bg,
119+
command=self.ShowIDLECredits)
120+
self.idle_credits_b.pack(side=LEFT, padx=10, pady=10)
115121

116122
# License, et all, are of type _sitebuiltins._Printer
117123
def ShowLicense(self):
@@ -137,11 +143,13 @@ def ShowIDLENEWS(self):
137143
def display_printer_text(self, title, printer):
138144
printer._Printer__setup()
139145
text = '\n'.join(printer._Printer__lines)
140-
textview.view_text(self, title, text)
146+
self._current_textview = textview.view_text(
147+
self, title, text, _utest=self._utest)
141148

142149
def display_file_text(self, title, filename, encoding=None):
143150
fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename)
144-
textview.view_file(self, title, fn, encoding)
151+
self._current_textview = textview.view_file(
152+
self, title, fn, encoding, _utest=self._utest)
145153

146154
def Ok(self, event=None):
147155
self.destroy()

Lib/idlelib/idle_test/test_help_about.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
from idlelib import textview
77
from idlelib.idle_test.mock_idle import Func
88
from idlelib.idle_test.mock_tk import Mbox_func
9+
from test.support import requires, findfile
10+
requires('gui')
11+
from tkinter import Tk
912
import unittest
1013

14+
1115
About = help_about.AboutDialog
1216
class Dummy_about_dialog():
1317
# Dummy class for testing file display functions.
@@ -16,6 +20,65 @@ class Dummy_about_dialog():
1620
idle_news = About.ShowIDLENEWS
1721
# Called by the above
1822
display_file_text = About.display_file_text
23+
_utest = True
24+
25+
26+
class AboutDialogTest(unittest.TestCase):
27+
@classmethod
28+
def setUpClass(cls):
29+
cls.root = Tk()
30+
cls.root.withdraw()
31+
cls.dialog = About(cls.root, 'About IDLE', _utest=True)
32+
33+
@classmethod
34+
def tearDownClass(cls):
35+
del cls.dialog
36+
cls.root.update_idletasks()
37+
cls.root.destroy()
38+
del cls.root
39+
40+
def tearDown(self):
41+
if self.dialog._current_textview:
42+
self.dialog._current_textview.destroy()
43+
44+
def test_dialog_title(self):
45+
"""This will test about dialog title"""
46+
self.assertEqual(self.dialog.title(), 'About IDLE')
47+
48+
def test_printer_dialog(self):
49+
"""This will test dialog which using printer"""
50+
buttons = [(license, self.dialog.buttonLicense),
51+
(copyright, self.dialog.buttonCopyright),
52+
(credits, self.dialog.buttonCredits)]
53+
54+
for printer, button in buttons:
55+
dialog = self.dialog
56+
printer._Printer__setup()
57+
button.invoke()
58+
self.assertEqual(printer._Printer__lines[0],
59+
dialog._current_textview.textView.get('1.0', '1.end'))
60+
self.assertEqual(printer._Printer__lines[1],
61+
dialog._current_textview.textView.get('2.0', '2.end'))
62+
63+
dialog._current_textview.destroy()
64+
65+
def test_file_dialog(self):
66+
"""This will test dialog which using file"""
67+
buttons = [('README.txt', self.dialog.idle_about_b),
68+
('NEWS.txt', self.dialog.idle_news_b),
69+
('CREDITS.txt', self.dialog.idle_credits_b)]
70+
71+
for filename, button in buttons:
72+
dialog = self.dialog
73+
button.invoke()
74+
fn = findfile(filename, subdir='idlelib')
75+
with open(fn) as f:
76+
self.assertEqual(f.readline().strip(),
77+
dialog._current_textview.textView.get('1.0', '1.end'))
78+
f.readline()
79+
self.assertEqual(f.readline().strip(),
80+
dialog._current_textview.textView.get('3.0', '3.end'))
81+
dialog._current_textview.destroy()
1982

2083

2184
class DisplayFileTest(unittest.TestCase):

0 commit comments

Comments
 (0)
0