mirror of
https://github.com/python/cpython.git
synced 2025-11-10 02:21:40 +00:00
Issue #18910: Add unittest for textView. Patch by Phil Webster.
This commit is contained in:
parent
0d3e4b4e1a
commit
537e2c8632
4 changed files with 115 additions and 4 deletions
|
|
@ -12,7 +12,11 @@ class TextViewer(Toplevel):
|
|||
def __init__(self, parent, title, text, modal=True, _htest=False):
|
||||
"""Show the given text in a scrollable window with a 'close' button
|
||||
|
||||
_htest - bool, change box location when running htest
|
||||
If modal option set to False, user can interact with other windows,
|
||||
otherwise they will be unable to interact with other windows until
|
||||
the textview window is closed.
|
||||
|
||||
_htest - bool; change box location when running htest.
|
||||
"""
|
||||
Toplevel.__init__(self, parent)
|
||||
self.configure(borderwidth=5)
|
||||
|
|
@ -68,8 +72,7 @@ def view_file(parent, title, filename, encoding=None, modal=True):
|
|||
try:
|
||||
with open(filename, 'r', encoding=encoding) as file:
|
||||
contents = file.read()
|
||||
except OSError:
|
||||
import tkinter.messagebox as tkMessageBox
|
||||
except IOError:
|
||||
tkMessageBox.showerror(title='File Load Error',
|
||||
message='Unable to load file %r .' % filename,
|
||||
parent=parent)
|
||||
|
|
@ -77,5 +80,7 @@ def view_file(parent, title, filename, encoding=None, modal=True):
|
|||
return view_text(parent, title, contents, modal)
|
||||
|
||||
if __name__ == '__main__':
|
||||
import unittest
|
||||
unittest.main('idlelib.idle_test.test_textview', verbosity=2, exit=False)
|
||||
from idlelib.idle_test.htest import run
|
||||
run(TextViewer)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue