Kaydet (Commit) 096c6aae authored tarafından Terry Jan Reedy's avatar Terry Jan Reedy

Issue #27365: partial merge

'''Test idlelib.help_about.
Coverage:
'''
from idlelib import aboutDialog as help_about
from idlelib import textView as textview
from idlelib.idle_test.mock_idle import Func
from idlelib.idle_test.mock_tk import Mbox
import unittest
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
# Called by the above
display_file_text = About.display_file_text
class DisplayFileTest(unittest.TestCase):
"Test that .txt files are found and properly decoded."
dialog = Dummy_about_dialog()
@classmethod
def setUpClass(cls):
cls.orig_mbox = textview.tkMessageBox
cls.orig_view = textview.view_text
cls.mbox = Mbox()
cls.view = Func()
textview.tkMessageBox = cls.mbox
textview.view_text = cls.view
cls.About = Dummy_about_dialog()
@classmethod
def tearDownClass(cls):
textview.tkMessageBox = cls.orig_mbox
textview.view_text = cls.orig_view
def test_file_isplay(self):
for handler in (self.dialog.idle_credits,
self.dialog.idle_readme,
self.dialog.idle_news):
self.mbox.showerror.message = ''
self.view.called = False
handler()
self.assertEqual(self.mbox.showerror.message, '')
self.assertEqual(self.view.called, True)
if __name__ == '__main__':
unittest.main(verbosity=2)
......@@ -5,7 +5,7 @@ is a widget containing multiple widgets, all tests must be gui tests.
Using mock Text would not change this. Other mocks are used to retrieve
information about calls.
The coverage is essentially 100%.
Coverage: 94%.
'''
from idlelib import textview as tv
from test.support import requires
......@@ -15,7 +15,7 @@ import unittest
import os
from tkinter import Tk
from idlelib.idle_test.mock_idle import Func
from idlelib.idle_test.mock_tk import Mbox
from idlelib.idle_test.mock_tk import Mbox_func
def setUpModule():
global root
......@@ -64,17 +64,17 @@ class TextViewTest(unittest.TestCase):
view.destroy
class textviewTest(unittest.TestCase):
class ViewFunctionTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.orig_mbox = tv.tkMessageBox
tv.tkMessageBox = Mbox
cls.orig_error = tv.showerror
tv.showerror = Mbox_func()
@classmethod
def tearDownClass(cls):
tv.tkMessageBox = cls.orig_mbox
del cls.orig_mbox
tv.showerror = cls.orig_error
del cls.orig_error
def test_view_text(self):
# If modal True, tkinter will error with 'can't invoke "event" command'
......@@ -89,7 +89,7 @@ class textviewTest(unittest.TestCase):
self.assertIn('Test', view.textView.get('1.0', '1.end'))
view.Ok()
# Mock messagebox will be used and view_file will not return anything
# Mock showerror will be used and view_file will return None
testfile = os.path.join(test_dir, '../notthere.py')
view = tv.view_file(root, 'Title', testfile, modal=False)
self.assertIsNone(view)
......
......@@ -77,6 +77,10 @@ def view_file(parent, title, filename, encoding=None, modal=True):
tkMessageBox.showerror(title='File Load Error',
message='Unable to load file %r .' % filename,
parent=parent)
except UnicodeDecodeError as err:
tkMessageBox.showerror(title='Unicode Decode Error',
message=str(err),
parent=parent)
else:
return view_text(parent, title, contents, modal)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment