mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
parent
178418ad67
commit
eca7da0f13
1 changed files with 75 additions and 47 deletions
|
@ -1,31 +1,23 @@
|
||||||
'''Test idlelib.help_about.
|
'''Test idlelib.help_about.
|
||||||
|
|
||||||
Coverage:
|
Coverage: 100%
|
||||||
'''
|
'''
|
||||||
from idlelib import help_about
|
from test.support import requires, findfile
|
||||||
from idlelib import textview
|
from tkinter import Tk, TclError
|
||||||
|
import unittest
|
||||||
from idlelib.idle_test.mock_idle import Func
|
from idlelib.idle_test.mock_idle import Func
|
||||||
from idlelib.idle_test.mock_tk import Mbox_func
|
from idlelib.idle_test.mock_tk import Mbox_func
|
||||||
from test.support import requires, findfile
|
from idlelib.help_about import AboutDialog as About
|
||||||
requires('gui')
|
from idlelib import textview
|
||||||
from tkinter import Tk
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
|
class LiveDialogTest(unittest.TestCase):
|
||||||
|
"""Simulate user clicking buttons other than [Close].
|
||||||
|
|
||||||
About = help_about.AboutDialog
|
Test that invoked textview has text from source.
|
||||||
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):
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
|
requires('gui')
|
||||||
cls.root = Tk()
|
cls.root = Tk()
|
||||||
cls.root.withdraw()
|
cls.root.withdraw()
|
||||||
cls.dialog = About(cls.root, 'About IDLE', _utest=True)
|
cls.dialog = About(cls.root, 'About IDLE', _utest=True)
|
||||||
|
@ -37,43 +29,41 @@ class AboutDialogTest(unittest.TestCase):
|
||||||
cls.root.destroy()
|
cls.root.destroy()
|
||||||
del cls.root
|
del cls.root
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
if self.dialog._current_textview:
|
|
||||||
self.dialog._current_textview.destroy()
|
|
||||||
|
|
||||||
def test_dialog_title(self):
|
def test_dialog_title(self):
|
||||||
"""This will test about dialog title"""
|
"""Test about dialog title"""
|
||||||
self.assertEqual(self.dialog.title(), 'About IDLE')
|
self.assertEqual(self.dialog.title(), 'About IDLE')
|
||||||
|
|
||||||
def test_printer_dialog(self):
|
def test_printer_buttons(self):
|
||||||
"""This will test dialog which using printer"""
|
"""Test buttons whose commands use printer function."""
|
||||||
buttons = [(license, self.dialog.py_license),
|
|
||||||
(copyright, self.dialog.py_copyright),
|
|
||||||
(credits, self.dialog.py_credits)]
|
|
||||||
|
|
||||||
for printer, button in buttons:
|
|
||||||
dialog = self.dialog
|
dialog = self.dialog
|
||||||
|
button_sources = [(self.dialog.py_license, license),
|
||||||
|
(self.dialog.py_copyright, copyright),
|
||||||
|
(self.dialog.py_credits, credits)]
|
||||||
|
|
||||||
|
for button, printer in button_sources:
|
||||||
printer._Printer__setup()
|
printer._Printer__setup()
|
||||||
button.invoke()
|
button.invoke()
|
||||||
self.assertEqual(printer._Printer__lines[0],
|
self.assertEqual(
|
||||||
|
printer._Printer__lines[0],
|
||||||
dialog._current_textview.textView.get('1.0', '1.end'))
|
dialog._current_textview.textView.get('1.0', '1.end'))
|
||||||
self.assertEqual(printer._Printer__lines[1],
|
self.assertEqual(
|
||||||
|
printer._Printer__lines[1],
|
||||||
dialog._current_textview.textView.get('2.0', '2.end'))
|
dialog._current_textview.textView.get('2.0', '2.end'))
|
||||||
|
|
||||||
dialog._current_textview.destroy()
|
dialog._current_textview.destroy()
|
||||||
|
|
||||||
def test_file_dialog(self):
|
def test_file_buttons(self):
|
||||||
"""This will test dialog which using file"""
|
"""Test buttons that display files."""
|
||||||
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
|
dialog = self.dialog
|
||||||
|
button_sources = [(self.dialog.readme, 'README.txt'),
|
||||||
|
(self.dialog.idle_news, 'NEWS.txt'),
|
||||||
|
(self.dialog.idle_credits, 'CREDITS.txt')]
|
||||||
|
|
||||||
|
for button, filename in button_sources:
|
||||||
button.invoke()
|
button.invoke()
|
||||||
fn = findfile(filename, subdir='idlelib')
|
fn = findfile(filename, subdir='idlelib')
|
||||||
with open(fn) as f:
|
with open(fn) as f:
|
||||||
self.assertEqual(f.readline().strip(),
|
self.assertEqual(
|
||||||
|
f.readline().strip(),
|
||||||
dialog._current_textview.textView.get('1.0', '1.end'))
|
dialog._current_textview.textView.get('1.0', '1.end'))
|
||||||
f.readline()
|
f.readline()
|
||||||
self.assertEqual(f.readline().strip(),
|
self.assertEqual(f.readline().strip(),
|
||||||
|
@ -81,7 +71,46 @@ class AboutDialogTest(unittest.TestCase):
|
||||||
dialog._current_textview.destroy()
|
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):
|
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()
|
dialog = Dummy_about_dialog()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -92,14 +121,13 @@ class DisplayFileTest(unittest.TestCase):
|
||||||
cls.view = Func()
|
cls.view = Func()
|
||||||
textview.showerror = cls.error
|
textview.showerror = cls.error
|
||||||
textview.view_text = cls.view
|
textview.view_text = cls.view
|
||||||
cls.About = Dummy_about_dialog()
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
textview.showerror = cls.orig_error
|
textview.showerror = cls.orig_error
|
||||||
textview.view_text = cls.orig_view
|
textview.view_text = cls.orig_view
|
||||||
|
|
||||||
def test_file_isplay(self):
|
def test_file_display(self):
|
||||||
for handler in (self.dialog.idle_credits,
|
for handler in (self.dialog.idle_credits,
|
||||||
self.dialog.idle_readme,
|
self.dialog.idle_readme,
|
||||||
self.dialog.idle_news):
|
self.dialog.idle_news):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue