8000 IDLE test_help_about: edit and add test. (#1838) · python/cpython@eca7da0 · GitHub
[go: up one dir, main page]

Skip to content

Commit eca7da0

Browse files
authored
IDLE test_help_about: edit and add test. (#1838)
Coverage is now 100%
1 parent 178418a commit eca7da0

File tree

1 file changed

+75
-47
lines changed

1 file changed

+75
-47
lines changed

Lib/idlelib/idle_test/test_help_about.py

Lines changed: 75 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
11
'''Test idlelib.help_about.
22
3-
Coverage:
3+
Coverage: 100%
44
'''
5-
from idlelib import help_about
6-
from idlelib import textview
7-
from idlelib.idle_test.mock_idle import Func
8-
from idlelib.idle_test.mock_tk import Mbox_func
95
from test.support import requires, findfile
10-
requires('gui')
11-
from tkinter import Tk
6+
from tkinter import Tk, TclError
127
import unittest
8+
from idlelib.idle_test.mock_idle import Func
9+
from idlelib.idle_test.mock_tk import Mbox_func
10+
from idlelib.help_about import AboutDialog as About
11+
from idlelib import textview
1312

13+
class LiveDialogTest(unittest.TestCase):
14+
"""Simulate user clicking buttons other than [Close].
1415
15-
About = help_about.AboutDialog
16-
class Dummy_about_dialog():
17-
# Dummy class for testing file display functions.
18-
idle_credits = About.show_idle_credits
19-
idle_readme = About.show_readme
20-
idle_news = About.show_idle_news
21-
# Called by the above
22-
display_file_text = About.display_file_text
23-
_utest = True
24-
25-
26-
class AboutDialogTest(unittest.TestCase):
16+
Test that invoked textview has text from source.
17+
"""
2718
@classmethod
2819
def setUpClass(cls):
20+
requires('gui')
2921
cls.root = Tk()
3022
cls.root.withdraw()
3123
cls.dialog = About(cls.root, 'About IDLE', _utest=True)
@@ -37,51 +29,88 @@ def tearDownClass(cls):
3729
cls.root.destroy()
3830
del cls.root
3931

40-
def tearDown(self):
41-
if self.dialog._current_textview:
42-
self.dialog._current_textview.destroy()
43-
4432
def test_dialog_title(self):
45-
"""This will test about dialog title"""
33+
"""Test about dialog title"""
4634
self.assertEqual(self.dialog.title(), 'About IDLE')
4735

48-
def test_printer_dialog(self):
49-
"""This will test dialog which using printer"""
50-
buttons = [(license, self.dialog.py_license),
51-
(copyright, self.dialog.py_copyright),
52-
(credits, self.dialog.py_credits)]
36+
def test_printer_buttons(self):
37+
"""Test buttons whose commands use printer function."""
38+
dialog = self.dialog
39+
button_sources = [(self.dialog.py_license, license),
40+
(self.dialog.py_copyright, copyright),
41+
(self.dialog.py_credits, credits)]
5342

54-
for printer, button in buttons:
55-
dialog = self.dialog
43+
for button, printer in button_sources:
5644
printer._Printer__setup()
5745
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-
46+
self.assertEqual(
47+
printer._Printer__lines[0],
48+
dialog._current_textview.textView.get('1.0', '1.end'))
49+
self.assertEqual(
50+
printer._Printer__lines[1],
51+
dialog._current_textview.textView.get('2.0', '2.end'))
6352
dialog._current_textview.destroy()
6453

65-
def test_file_dialog(self):
66-
"""This will test dialog which using file"""
67-
buttons = [('README.txt', self.dialog.readme),
68-
('NEWS.txt', self.dialog.idle_news),
69-
('CREDITS.txt', self.dialog.idle_credits)]
54+
def test_file_buttons(self):
55+
"""Test buttons that display files."""
56+
dialog = self.dialog
57+
button_sources = [(self.dialog.readme, 'README.txt'),
58+
(self.dialog.idle_news, 'NEWS.txt'),
59+
(self.dialog.idle_credits, 'CREDITS.txt')]
7060

71-
for filename, button in buttons:
72-
dialog = self.dialog
61+
for button, filename in button_sources:
7362
button.invoke()
7463
fn = findfile(filename, subdir='idlelib')
7564
with open(fn) as f:
76-
self.assertEqual(f.readline().strip(),
77-
dialog._current_textview.textView.get('1.0', '1.end'))
65+
self.assertEqual(
66+
f.readline().strip(),
67+
dialog._current_textview.textView.get('1.0', '1.end'))
7868
f.readline()
7969
self.assertEqual(f.readline().strip(),
8070
dialog._current_textview.textView.get('3.0', '3.end'))
8171
dialog._current_textview.destroy()
8272

8373

74+
class CloseTest(unittest.TestCase):
75+
"""Simulate user clicking [Close] button"""
76+
77+
@classmethod
78+
def setUpClass(cls):
79+
requires('gui')
80+
cls.root = Tk()
81+
cls.root.withdraw()
82+
cls.dialog = About(cls.root, 'About IDLE', _utest=True)
83+
84+
@classmethod
85+
def tearDownClass(cls):
86+
del cls.dialog
87+
cls.root.update_idletasks()
88+
cls.root.destroy()
89+
del cls.root
90+
91+
def test_close(self):
92+
self.assertEqual(self.dialog.winfo_class(), 'Toplevel')
93+
self.dialog.button_ok.invoke()
94+
with self.assertRaises(TclError):
95+
self.dialog.winfo_class()
96+
97+
98+
class Dummy_about_dialog():
99+
# Dummy class for testing file display functions.
100+
idle_credits = About.show_idle_credits
101+
idle_readme = About.show_readme
102+
idle_news = About.show_idle_news
103+
# Called by the above
104+
display_file_text = About.display_file_text
105+
_utest = True
106+
107+
84108
class DisplayFileTest(unittest.TestCase):
109+
"""Test functions that display files.
110+
111+
While somewhat redundant with gui-based test_file_dialog,
112+
these unit tests run on all buildbots, not just a few.
113+
"""
85114
dialog = Dummy_about_dialog()
86115

87116
@classmethod
@@ -92,14 +121,13 @@ def setUpClass(cls):
92121
cls.view = Func()
93122
textview.showerror = cls.error
94123
textview.view_text = cls.view
95-
cls.About = Dummy_about_dialog()
96124

97125
@classmethod
98126
def tearDownClass(cls):
99127
textview.showerror = cls.orig_error
100128
textview.view_text = cls.orig_view
101129

102-
def test_file_isplay(self):
130+
def test_file_display(self):
103131
for handler in (self.dialog.idle_credits,
104132
self.dialog.idle_readme,
105133
self.dialog.idle_news):

0 commit comments

Comments
 (0)
0