From b6c169ee77ad5863af49a88abc504edb2e114b26 Mon Sep 17 00:00:00 2001 From: mlouielu Date: Mon, 22 May 2017 06:19:35 +0800 Subject: [PATCH 1/3] bpo-30290: IDLE: Add more tests for help_about dialog (#1697) Increases coverage to 99% (cherry picked from commit 054e09147aaa6f61aca6cd40c7bf7ce6dc54a04b) --- Lib/idlelib/help_about.py | 64 +++++++++++++----------- Lib/idlelib/idle_test/test_help_about.py | 63 +++++++++++++++++++++++ 2 files changed, 99 insertions(+), 28 deletions(-) diff --git a/Lib/idlelib/help_about.py b/Lib/idlelib/help_about.py index 071bd3ec0f219c..4ad05f3994e6a3 100644 --- a/Lib/idlelib/help_about.py +++ b/Lib/idlelib/help_about.py @@ -13,9 +13,10 @@ class AboutDialog(Toplevel): """Modal about dialog for idle """ - def __init__(self, parent, title, _htest=False): + def __init__(self, parent, title, _htest=False, _utest=False): """ _htest - bool, change box location when running htest + _utest - bool, don't wait_window when running unittest """ Toplevel.__init__(self, parent) self.configure(borderwidth=5) @@ -35,7 +36,12 @@ def __init__(self, parent, title, _htest=False): self.buttonOk.focus_set() self.bind('',self.Ok) #dismiss dialog self.bind('',self.Ok) #dismiss dialog - self.wait_window() + self._current_textview = None + self._utest = _utest + + if not _utest: + self.deiconify() + self.wait_window() def CreateWidgets(self): release = version[:version.index(' ')] @@ -80,18 +86,18 @@ def CreateWidgets(self): labelTkVer.grid(row=9, column=1, sticky=W, padx=2, pady=0) py_button_f = Frame(frameBg, bg=self.bg) py_button_f.grid(row=10, column=0, columnspan=2, sticky=NSEW) - buttonLicense = Button(py_button_f, text='License', width=8, - highlightbackground=self.bg, - command=self.ShowLicense) - buttonLicense.pack(side=LEFT, padx=10, pady=10) - buttonCopyright = Button(py_button_f, text='Copyright', width=8, - highlightbackground=self.bg, - command=self.ShowCopyright) - buttonCopyright.pack(side=LEFT, padx=10, pady=10) - buttonCredits = Button(py_button_f, text='Credits', width=8, - highlightbackground=self.bg, - command=self.ShowPythonCredits) - buttonCredits.pack(side=LEFT, padx=10, pady=10) + self.buttonLicense = Button(py_button_f, text='License', width=8, + highlightbackground=self.bg, + command=self.ShowLicense) + self.buttonLicense.pack(side=LEFT, padx=10, pady=10) + self.buttonCopyright = Button(py_button_f, text='Copyright', width=8, + highlightbackground=self.bg, + command=self.ShowCopyright) + self.buttonCopyright.pack(side=LEFT, padx=10, pady=10) + self.buttonCredits = Button(py_button_f, text='Credits', width=8, + highlightbackground=self.bg, + command=self.ShowPythonCredits) + self.buttonCredits.pack(side=LEFT, padx=10, pady=10) Frame(frameBg, borderwidth=1, relief=SUNKEN, height=2, bg=self.bg).grid(row=11, column=0, sticky=EW, columnspan=3, padx=5, pady=5) @@ -100,18 +106,18 @@ def CreateWidgets(self): idle_v.grid(row=12, column=0, sticky=W, padx=10, pady=0) idle_button_f = Frame(frameBg, bg=self.bg) idle_button_f.grid(row=13, column=0, columnspan=3, sticky=NSEW) - idle_about_b = Button(idle_button_f, text='README', width=8, - highlightbackground=self.bg, - command=self.ShowIDLEAbout) - idle_about_b.pack(side=LEFT, padx=10, pady=10) - idle_news_b = Button(idle_button_f, text='NEWS', width=8, - highlightbackground=self.bg, - command=self.ShowIDLENEWS) - idle_news_b.pack(side=LEFT, padx=10, pady=10) - idle_credits_b = Button(idle_button_f, text='Credits', width=8, - highlightbackground=self.bg, - command=self.ShowIDLECredits) - idle_credits_b.pack(side=LEFT, padx=10, pady=10) + self.idle_about_b = Button(idle_button_f, text='README', width=8, + highlightbackground=self.bg, + command=self.ShowIDLEAbout) + self.idle_about_b.pack(side=LEFT, padx=10, pady=10) + self.idle_news_b = Button(idle_button_f, text='NEWS', width=8, + highlightbackground=self.bg, + command=self.ShowIDLENEWS) + self.idle_news_b.pack(side=LEFT, padx=10, pady=10) + self.idle_credits_b = Button(idle_button_f, text='Credits', width=8, + highlightbackground=self.bg, + command=self.ShowIDLECredits) + self.idle_credits_b.pack(side=LEFT, padx=10, pady=10) # License, et all, are of type _sitebuiltins._Printer def ShowLicense(self): @@ -137,11 +143,13 @@ def ShowIDLENEWS(self): def display_printer_text(self, title, printer): printer._Printer__setup() text = '\n'.join(printer._Printer__lines) - textview.view_text(self, title, text) + self._current_textview = textview.view_text( + self, title, text, _utest=self._utest) def display_file_text(self, title, filename, encoding=None): fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename) - textview.view_file(self, title, fn, encoding) + self._current_textview = textview.view_file( + self, title, fn, encoding, _utest=self._utest) def Ok(self, event=None): self.destroy() diff --git a/Lib/idlelib/idle_test/test_help_about.py b/Lib/idlelib/idle_test/test_help_about.py index 843efb9ad2458c..031c7ffc5d4a42 100644 --- a/Lib/idlelib/idle_test/test_help_about.py +++ b/Lib/idlelib/idle_test/test_help_about.py @@ -6,8 +6,12 @@ from idlelib import textview from idlelib.idle_test.mock_idle import Func from idlelib.idle_test.mock_tk import Mbox_func +from test.support import requires, findfile +requires('gui') +from tkinter import Tk import unittest + About = help_about.AboutDialog class Dummy_about_dialog(): # Dummy class for testing file display functions. @@ -16,6 +20,65 @@ class Dummy_about_dialog(): idle_news = About.ShowIDLENEWS # Called by the above display_file_text = About.display_file_text + _utest = True + + +class AboutDialogTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.root = Tk() + cls.root.withdraw() + cls.dialog = About(cls.root, 'About IDLE', _utest=True) + + @classmethod + def tearDownClass(cls): + del cls.dialog + cls.root.update_idletasks() + cls.root.destroy() + del cls.root + + def tearDown(self): + if self.dialog._current_textview: + self.dialog._current_textview.destroy() + + def test_dialog_title(self): + """This will test about dialog title""" + self.assertEqual(self.dialog.title(), 'About IDLE') + + def test_printer_dialog(self): + """This will test dialog which using printer""" + buttons = [(license, self.dialog.buttonLicense), + (copyright, self.dialog.buttonCopyright), + (credits, self.dialog.buttonCredits)] + + for printer, button in buttons: + dialog = self.dialog + printer._Printer__setup() + button.invoke() + self.assertEqual(printer._Printer__lines[0], + dialog._current_textview.textView.get('1.0', '1.end')) + self.assertEqual(printer._Printer__lines[1], + dialog._current_textview.textView.get('2.0', '2.end')) + + dialog._current_textview.destroy() + + def test_file_dialog(self): + """This will test dialog which using file""" + buttons = [('README.txt', self.dialog.idle_about_b), + ('NEWS.txt', self.dialog.idle_news_b), + ('CREDITS.txt', self.dialog.idle_credits_b)] + + for filename, button in buttons: + dialog = self.dialog + button.invoke() + fn = findfile(filename, subdir='idlelib') + with open(fn) as f: + self.assertEqual(f.readline().strip(), + dialog._current_textview.textView.get('1.0', '1.end')) + f.readline() + self.assertEqual(f.readline().strip(), + dialog._current_textview.textView.get('3.0', '3.end')) + dialog._current_textview.destroy() class DisplayFileTest(unittest.TestCase): From cbf5775d459a432b098819ed0ffc3155c25a1c98 Mon Sep 17 00:00:00 2001 From: csabella Date: Sat, 27 May 2017 15:49:26 -0400 Subject: [PATCH 2/3] bpo-30290: IDLE: Refactor help_about to PEP8 names (#1714) Patch by Cheryl Sabella. (cherry picked from commit 5a346d5dbc1f0f70eca706a8ba19f7645bf17837) --- Lib/idlelib/help_about.py | 196 +++++++++++++---------- Lib/idlelib/idle_test/test_help_about.py | 18 +-- 2 files changed, 119 insertions(+), 95 deletions(-) diff --git a/Lib/idlelib/help_about.py b/Lib/idlelib/help_about.py index 4ad05f3994e6a3..f0a40e927c3634 100644 --- a/Lib/idlelib/help_about.py +++ b/Lib/idlelib/help_about.py @@ -4,7 +4,8 @@ import os from sys import version -from tkinter import * +from tkinter import Toplevel, Frame, Label, Button +from tkinter import SUNKEN, TOP, BOTTOM, LEFT, X, BOTH, W, EW, NSEW from idlelib import textview @@ -14,7 +15,10 @@ class AboutDialog(Toplevel): """ def __init__(self, parent, title, _htest=False, _utest=False): - """ + """Create popup, do not return until tk widget destroyed. + + parent - parent of this dialog + title - string which is title of popup dialog _htest - bool, change box location when running htest _utest - bool, don't wait_window when running unittest """ @@ -26,16 +30,16 @@ def __init__(self, parent, title, _htest=False, _utest=False): parent.winfo_rooty()+(30 if not _htest else 100))) self.bg = "#707070" self.fg = "#ffffff" - self.CreateWidgets() - self.resizable(height=FALSE, width=FALSE) + self.create_widgets() + self.resizable(height=False, width=False) self.title(title) self.transient(parent) self.grab_set() - self.protocol("WM_DELETE_WINDOW", self.Ok) + self.protocol("WM_DELETE_WINDOW", self.ok) self.parent = parent - self.buttonOk.focus_set() - self.bind('',self.Ok) #dismiss dialog - self.bind('',self.Ok) #dismiss dialog + self.button_ok.focus_set() + self.bind('', self.ok) # dismiss dialog + self.bind('', self.ok) # dismiss dialog self._current_textview = None self._utest = _utest @@ -43,115 +47,135 @@ def __init__(self, parent, title, _htest=False, _utest=False): self.deiconify() self.wait_window() - def CreateWidgets(self): + def create_widgets(self): release = version[:version.index(' ')] - frameMain = Frame(self, borderwidth=2, relief=SUNKEN) - frameButtons = Frame(self) - frameButtons.pack(side=BOTTOM, fill=X) - frameMain.pack(side=TOP, expand=TRUE, fill=BOTH) - self.buttonOk = Button(frameButtons, text='Close', - command=self.Ok) - self.buttonOk.pack(padx=5, pady=5) - #self.picture = Image('photo', data=self.pictureData) - frameBg = Frame(frameMain, bg=self.bg) - frameBg.pack(expand=TRUE, fill=BOTH) - labelTitle = Label(frameBg, text='IDLE', fg=self.fg, bg=self.bg, - font=('courier', 24, 'bold')) - labelTitle.grid(row=0, column=0, sticky=W, padx=10, pady=10) - #labelPicture = Label(frameBg, text='[picture]') - #image=self.picture, bg=self.bg) - #labelPicture.grid(row=1, column=1, sticky=W, rowspan=2, - # padx=0, pady=3) - byline = "Python's Integrated DeveLopment Environment" + 5*'\n' - labelDesc = Label(frameBg, text=byline, justify=LEFT, - fg=self.fg, bg=self.bg) - labelDesc.grid(row=2, column=0, sticky=W, columnspan=3, padx=10, pady=5) - labelEmail = Label(frameBg, text='email: idle-dev@python.org', - justify=LEFT, fg=self.fg, bg=self.bg) - labelEmail.grid(row=6, column=0, columnspan=2, - sticky=W, padx=10, pady=0) - labelWWW = Label(frameBg, text='https://docs.python.org/' + - version[:3] + '/library/idle.html', - justify=LEFT, fg=self.fg, bg=self.bg) - labelWWW.grid(row=7, column=0, columnspan=2, sticky=W, padx=10, pady=0) - Frame(frameBg, borderwidth=1, relief=SUNKEN, + frame = Frame(self, borderwidth=2, relief=SUNKEN) + frame_buttons = Frame(self) + frame_buttons.pack(side=BOTTOM, fill=X) + frame.pack(side=TOP, expand=True, fill=BOTH) + self.button_ok = Button(frame_buttons, text='Close', + command=self.ok) + self.button_ok.pack(padx=5, pady=5) + + frame_background = Frame(frame, bg=self.bg) + frame_background.pack(expand=True, fill=BOTH) + + header = Label(frame_background, text='IDLE', fg=self.fg, + bg=self.bg, font=('courier', 24, 'bold')) + header.grid(row=0, column=0, sticky=W, padx=10, pady=10) + byline_text = "Python's Integrated DeveLopment Environment" + 5*'\n' + byline = Label(frame_background, text=byline_text, justify=LEFT, + fg=self.fg, bg=self.bg) + byline.grid(row=2, column=0, sticky=W, columnspan=3, padx=10, pady=5) + email = Label(frame_background, text='email: idle-dev@python.org', + justify=LEFT, fg=self.fg, bg=self.bg) + email.grid(row=6, column=0, columnspan=2, sticky=W, padx=10, pady=0) + docs = Label(frame_background, text='https://docs.python.org/' + + version[:3] + '/library/idle.html', + justify=LEFT, fg=self.fg, bg=self.bg) + docs.grid(row=7, column=0, columnspan=2, sticky=W, padx=10, pady=0) + + Frame(frame_background, borderwidth=1, relief=SUNKEN, height=2, bg=self.bg).grid(row=8, column=0, sticky=EW, columnspan=3, padx=5, pady=5) - labelPythonVer = Label(frameBg, text='Python version: ' + - release, fg=self.fg, bg=self.bg) - labelPythonVer.grid(row=9, column=0, sticky=W, padx=10, pady=0) - tkVer = self.tk.call('info', 'patchlevel') - labelTkVer = Label(frameBg, text='Tk version: '+ - tkVer, fg=self.fg, bg=self.bg) - labelTkVer.grid(row=9, column=1, sticky=W, padx=2, pady=0) - py_button_f = Frame(frameBg, bg=self.bg) - py_button_f.grid(row=10, column=0, columnspan=2, sticky=NSEW) - self.buttonLicense = Button(py_button_f, text='License', width=8, - highlightbackground=self.bg, - command=self.ShowLicense) - self.buttonLicense.pack(side=LEFT, padx=10, pady=10) - self.buttonCopyright = Button(py_button_f, text='Copyright', width=8, - highlightbackground=self.bg, - command=self.ShowCopyright) - self.buttonCopyright.pack(side=LEFT, padx=10, pady=10) - self.buttonCredits = Button(py_button_f, text='Credits', width=8, - highlightbackground=self.bg, - command=self.ShowPythonCredits) - self.buttonCredits.pack(side=LEFT, padx=10, pady=10) - Frame(frameBg, borderwidth=1, relief=SUNKEN, + + pyver = Label(frame_background, text='Python version: ' + release, + fg=self.fg, bg=self.bg) + pyver.grid(row=9, column=0, sticky=W, padx=10, pady=0) + tk_patchlevel = self.tk.call('info', 'patchlevel') + tkver = Label(frame_background, text='Tk version: ' + tk_patchlevel, + fg=self.fg, bg=self.bg) + tkver.grid(row=9, column=1, sticky=W, padx=2, pady=0) + py_buttons = Frame(frame_background, bg=self.bg) + py_buttons.grid(row=10, column=0, columnspan=2, sticky=NSEW) + self.py_license = Button(py_buttons, text='License', width=8, + highlightbackground=self.bg, + command=self.show_py_license) + self.py_license.pack(side=LEFT, padx=10, pady=10) + self.py_copyright = Button(py_buttons, text='Copyright', width=8, + highlightbackground=self.bg, + command=self.show_py_copyright) + self.py_copyright.pack(side=LEFT, padx=10, pady=10) + self.py_credits = Button(py_buttons, text='Credits', width=8, + highlightbackground=self.bg, + command=self.show_py_credits) + self.py_credits.pack(side=LEFT, padx=10, pady=10) + + Frame(frame_background, borderwidth=1, relief=SUNKEN, height=2, bg=self.bg).grid(row=11, column=0, sticky=EW, columnspan=3, padx=5, pady=5) - idle_v = Label(frameBg, text='IDLE version: ' + release, - fg=self.fg, bg=self.bg) - idle_v.grid(row=12, column=0, sticky=W, padx=10, pady=0) - idle_button_f = Frame(frameBg, bg=self.bg) - idle_button_f.grid(row=13, column=0, columnspan=3, sticky=NSEW) - self.idle_about_b = Button(idle_button_f, text='README', width=8, + + idlever = Label(frame_background, text='IDLE version: ' + release, + fg=self.fg, bg=self.bg) + idlever.grid(row=12, column=0, sticky=W, padx=10, pady=0) + idle_buttons = Frame(frame_background, bg=self.bg) + idle_buttons.grid(row=13, column=0, columnspan=3, sticky=NSEW) + self.readme = Button(idle_buttons, text='README', width=8, + highlightbackground=self.bg, + command=self.show_readme) + self.readme.pack(side=LEFT, padx=10, pady=10) + self.idle_news = Button(idle_buttons, text='NEWS', width=8, + highlightbackground=self.bg, + command=self.show_idle_news) + self.idle_news.pack(side=LEFT, padx=10, pady=10) + self.idle_credits = Button(idle_buttons, text='Credits', width=8, highlightbackground=self.bg, - command=self.ShowIDLEAbout) - self.idle_about_b.pack(side=LEFT, padx=10, pady=10) - self.idle_news_b = Button(idle_button_f, text='NEWS', width=8, - highlightbackground=self.bg, - command=self.ShowIDLENEWS) - self.idle_news_b.pack(side=LEFT, padx=10, pady=10) - self.idle_credits_b = Button(idle_button_f, text='Credits', width=8, - highlightbackground=self.bg, - command=self.ShowIDLECredits) - self.idle_credits_b.pack(side=LEFT, padx=10, pady=10) - - # License, et all, are of type _sitebuiltins._Printer - def ShowLicense(self): + command=self.show_idle_credits) + self.idle_credits.pack(side=LEFT, padx=10, pady=10) + + # License, copyright, and credits are of type _sitebuiltins._Printer + def show_py_license(self): + "Handle License button event." self.display_printer_text('About - License', license) - def ShowCopyright(self): + def show_py_copyright(self): + "Handle Copyright button event." self.display_printer_text('About - Copyright', copyright) - def ShowPythonCredits(self): + def show_py_credits(self): + "Handle Python Credits button event." self.display_printer_text('About - Python Credits', credits) # Encode CREDITS.txt to utf-8 for proper version of Loewis. # Specify others as ascii until need utf-8, so catch errors. - def ShowIDLECredits(self): + def show_idle_credits(self): + "Handle Idle Credits button event." self.display_file_text('About - Credits', 'CREDITS.txt', 'utf-8') - def ShowIDLEAbout(self): + def show_readme(self): + "Handle Readme button event." self.display_file_text('About - Readme', 'README.txt', 'ascii') - def ShowIDLENEWS(self): + def show_idle_news(self): + "Handle News button event." self.display_file_text('About - NEWS', 'NEWS.txt', 'utf-8') def display_printer_text(self, title, printer): + """Create textview for built-in constants. + + Built-in constants have type _sitebuiltins._Printer. The + text is extracted from the built-in and then sent to a text + viewer with self as the parent and title as the title of + the popup. + """ printer._Printer__setup() text = '\n'.join(printer._Printer__lines) self._current_textview = textview.view_text( self, title, text, _utest=self._utest) def display_file_text(self, title, filename, encoding=None): + """Create textview for filename. + + The filename needs to be in the current directory. The path + is sent to a text viewer with self as the parent, title as + the title of the popup, and the file encoding. + """ fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename) self._current_textview = textview.view_file( self, title, fn, encoding, _utest=self._utest) - def Ok(self, event=None): + def ok(self, event=None): + "Dismiss help_about dialog." self.destroy() diff --git a/Lib/idlelib/idle_test/test_help_about.py b/Lib/idlelib/idle_test/test_help_about.py index 031c7ffc5d4a42..484f39ffbd692a 100644 --- a/Lib/idlelib/idle_test/test_help_about.py +++ b/Lib/idlelib/idle_test/test_help_about.py @@ -15,9 +15,9 @@ About = help_about.AboutDialog class Dummy_about_dialog(): # Dummy class for testing file display functions. - idle_credits = About.ShowIDLECredits - idle_readme = About.ShowIDLEAbout - idle_news = About.ShowIDLENEWS + idle_credits = About.show_idle_credits + idle_readme = About.show_readme + idle_news = About.show_idle_news # Called by the above display_file_text = About.display_file_text _utest = True @@ -47,9 +47,9 @@ def test_dialog_title(self): def test_printer_dialog(self): """This will test dialog which using printer""" - buttons = [(license, self.dialog.buttonLicense), - (copyright, self.dialog.buttonCopyright), - (credits, self.dialog.buttonCredits)] + buttons = [(license, self.dialog.py_license), + (copyright, self.dialog.py_copyright), + (credits, self.dialog.py_credits)] for printer, button in buttons: dialog = self.dialog @@ -64,9 +64,9 @@ def test_printer_dialog(self): def test_file_dialog(self): """This will test dialog which using file""" - buttons = [('README.txt', self.dialog.idle_about_b), - ('NEWS.txt', self.dialog.idle_news_b), - ('CREDITS.txt', self.dialog.idle_credits_b)] + buttons = [('README.txt', self.dialog.readme), + ('NEWS.txt', self.dialog.idle_news), + ('CREDITS.txt', self.dialog.idle_credits)] for filename, button in buttons: dialog = self.dialog From d2225e07a2149a82b91f5d80fd551fe14aa6936c Mon Sep 17 00:00:00 2001 From: terryjreedy Date: Sun, 28 May 2017 01:10:51 -0400 Subject: [PATCH 3/3] IDLE test_help_about: edit and add test. (#1838) Coverage is now 100% (cherry picked from commit eca7da0f13c78013b924fe7306f3e2e59c0af40b) --- Lib/idlelib/idle_test/test_help_about.py | 122 ++++++++++++++--------- 1 file changed, 75 insertions(+), 47 deletions(-) diff --git a/Lib/idlelib/idle_test/test_help_about.py b/Lib/idlelib/idle_test/test_help_about.py index 484f39ffbd692a..b98405df52a0c7 100644 --- a/Lib/idlelib/idle_test/test_help_about.py +++ b/Lib/idlelib/idle_test/test_help_about.py @@ -1,31 +1,23 @@ '''Test idlelib.help_about. -Coverage: +Coverage: 100% ''' -from idlelib import help_about -from idlelib import textview -from idlelib.idle_test.mock_idle import Func -from idlelib.idle_test.mock_tk import Mbox_func from test.support import requires, findfile -requires('gui') -from tkinter import Tk +from tkinter import Tk, TclError import unittest +from idlelib.idle_test.mock_idle import Func +from idlelib.idle_test.mock_tk import Mbox_func +from idlelib.help_about import AboutDialog as About +from idlelib import textview +class LiveDialogTest(unittest.TestCase): + """Simulate user clicking buttons other than [Close]. -About = help_about.AboutDialog -class Dummy_about_dialog(): - # Dummy class for testing file display functions. - idle_credits = About.show_idle_credits - idle_readme = About.show_readme - idle_news = About.show_idle_news - # Called by the above - display_file_text = About.display_file_text - _utest = True - - -class AboutDialogTest(unittest.TestCase): + Test that invoked textview has text from source. + """ @classmethod def setUpClass(cls): + requires('gui') cls.root = Tk() cls.root.withdraw() cls.dialog = About(cls.root, 'About IDLE', _utest=True) @@ -37,51 +29,88 @@ def tearDownClass(cls): cls.root.destroy() del cls.root - def tearDown(self): - if self.dialog._current_textview: - self.dialog._current_textview.destroy() - def test_dialog_title(self): - """This will test about dialog title""" + """Test about dialog title""" self.assertEqual(self.dialog.title(), 'About IDLE') - def test_printer_dialog(self): - """This will test dialog which using printer""" - buttons = [(license, self.dialog.py_license), - (copyright, self.dialog.py_copyright), - (credits, self.dialog.py_credits)] + def test_printer_buttons(self): + """Test buttons whose commands use printer function.""" + dialog = self.dialog + button_sources = [(self.dialog.py_license, license), + (self.dialog.py_copyright, copyright), + (self.dialog.py_credits, credits)] - for printer, button in buttons: - dialog = self.dialog + for button, printer in button_sources: printer._Printer__setup() button.invoke() - self.assertEqual(printer._Printer__lines[0], - dialog._current_textview.textView.get('1.0', '1.end')) - self.assertEqual(printer._Printer__lines[1], - dialog._current_textview.textView.get('2.0', '2.end')) - + self.assertEqual( + printer._Printer__lines[0], + dialog._current_textview.textView.get('1.0', '1.end')) + self.assertEqual( + printer._Printer__lines[1], + dialog._current_textview.textView.get('2.0', '2.end')) dialog._current_textview.destroy() - def test_file_dialog(self): - """This will test dialog which using file""" - buttons = [('README.txt', self.dialog.readme), - ('NEWS.txt', self.dialog.idle_news), - ('CREDITS.txt', self.dialog.idle_credits)] + def test_file_buttons(self): + """Test buttons that display files.""" + dialog = self.dialog + button_sources = [(self.dialog.readme, 'README.txt'), + (self.dialog.idle_news, 'NEWS.txt'), + (self.dialog.idle_credits, 'CREDITS.txt')] - for filename, button in buttons: - dialog = self.dialog + for button, filename in button_sources: button.invoke() fn = findfile(filename, subdir='idlelib') with open(fn) as f: - self.assertEqual(f.readline().strip(), - dialog._current_textview.textView.get('1.0', '1.end')) + self.assertEqual( + f.readline().strip(), + dialog._current_textview.textView.get('1.0', '1.end')) f.readline() self.assertEqual(f.readline().strip(), dialog._current_textview.textView.get('3.0', '3.end')) dialog._current_textview.destroy() +class CloseTest(unittest.TestCase): + """Simulate user clicking [Close] button""" + + @classmethod + def setUpClass(cls): + requires('gui') + cls.root = Tk() + cls.root.withdraw() + cls.dialog = About(cls.root, 'About IDLE', _utest=True) + + @classmethod + def tearDownClass(cls): + del cls.dialog + cls.root.update_idletasks() + cls.root.destroy() + del cls.root + + def test_close(self): + self.assertEqual(self.dialog.winfo_class(), 'Toplevel') + self.dialog.button_ok.invoke() + with self.assertRaises(TclError): + self.dialog.winfo_class() + + +class Dummy_about_dialog(): + # Dummy class for testing file display functions. + idle_credits = About.show_idle_credits + idle_readme = About.show_readme + idle_news = About.show_idle_news + # Called by the above + display_file_text = About.display_file_text + _utest = True + + class DisplayFileTest(unittest.TestCase): + """Test functions that display files. + + While somewhat redundant with gui-based test_file_dialog, + these unit tests run on all buildbots, not just a few. + """ dialog = Dummy_about_dialog() @classmethod @@ -92,14 +121,13 @@ def setUpClass(cls): cls.view = Func() textview.showerror = cls.error textview.view_text = cls.view - cls.About = Dummy_about_dialog() @classmethod def tearDownClass(cls): textview.showerror = cls.orig_error textview.view_text = cls.orig_view - def test_file_isplay(self): + def test_file_display(self): for handler in (self.dialog.idle_credits, self.dialog.idle_readme, self.dialog.idle_news):