8000 bpo-30290: IDLE: Add test for help_about dialog by mlouielu · Pull Request #1697 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-30290: IDLE: Add test for help_about dialog #1697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 36 additions & 28 deletions Lib/idlelib/help_about.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -35,7 +36,12 @@ def __init__(self, parent, title, _htest=False):
self.buttonOk.focus_set()
self.bind('<Return>',self.Ok) #dismiss dialog
self.bind('<Escape>',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(' ')]
Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand All @@ -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()
Expand Down
63 changes: 63 additions & 0 deletions Lib/idlelib/idle_test/test_help_about.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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):
Expand Down
0