1
1
'''Test idlelib.help_about.
2
2
3
- Coverage:
3
+ Coverage: 100%
4
4
'''
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
9
5
from test .support import requires , findfile
10
- requires ('gui' )
11
- from tkinter import Tk
6
+ from tkinter import Tk , TclError
12
7
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
13
12
13
+ class LiveDialogTest (unittest .TestCase ):
14
+ """Simulate user clicking buttons other than [Close].
14
15
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
+ """
27
18
@classmethod
28
19
def setUpClass (cls ):
20
+ requires ('gui' )
29
21
cls .root = Tk ()
30
22
cls .root .withdraw ()
31
23
cls .dialog = About (cls .root , 'About IDLE' , _utest = True )
@@ -37,51 +29,88 @@ def tearDownClass(cls):
37
29
cls .root .destroy ()
38
30
del cls .root
39
31
40
- def tearDown (self ):
41
- if self .dialog ._current_textview :
42
- self .dialog ._current_textview .destroy ()
43
-
44
32
def test_dialog_title (self ):
45
- """This will test about dialog title"""
33
+ """Test about dialog title"""
46
34
self .assertEqual (self .dialog .title (), 'About IDLE' )
47
35
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 )]
53
42
54
- for printer , button in buttons :
55
- dialog = self .dialog
43
+ for button , printer in button_sources :
56
44
printer ._Printer__setup ()
57
45
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' ))
63
52
dialog ._current_textview .destroy ()
64
53
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' )]
70
60
71
- for filename , button in buttons :
72
- dialog = self .dialog
61
+ for button , filename in button_sources :
73
62
button .invoke ()
74
63
fn = findfile (filename , subdir = 'idlelib' )
75
64
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' ))
78
68
f .readline ()
79
69
self .assertEqual (f .readline ().strip (),
80
70
dialog ._current_textview .textView .get ('3.0' , '3.end' ))
81
71
dialog ._current_textview .destroy ()
82
72
83
73
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
+
84
108
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
+ """
85
114
dialog = Dummy_about_dialog ()
86
115
87
116
@classmethod
@@ -92,14 +121,13 @@ def setUpClass(cls):
92
121
cls .view = Func ()
93
122
textview .showerror = cls .error
94
123
textview .view_text = cls .view
95
- cls .About = Dummy_about_dialog ()
96
124
97
125
@classmethod
98
126
def tearDownClass (cls ):
99
127
textview .showerror = cls .orig_error
100
128
textview .view_text = cls .orig_view
101
129
102
- def test_file_isplay (self ):
130
+ def test_file_display (self ):
103
131
for handler in (self .dialog .idle_credits ,
104
132
self .dialog .idle_readme ,
105
133
self .dialog .idle_news ):
0 commit comments