Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
ba365da9
Kaydet (Commit)
ba365da9
authored
May 17, 2017
tarafından
Louie Lu
Kaydeden (comit)
terryjreedy
May 17, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-30303: IDLE: Add _utest argument to textview (#1499)
üst
ab4413a7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
11 deletions
+57
-11
test_textview.py
Lib/idlelib/idle_test/test_textview.py
+41
-1
textview.py
Lib/idlelib/textview.py
+16
-10
No files found.
Lib/idlelib/idle_test/test_textview.py
Dosyayı görüntüle @
ba365da9
...
...
@@ -13,7 +13,7 @@ requires('gui')
import
unittest
import
os
from
tkinter
import
Tk
from
tkinter
import
Tk
,
Button
from
idlelib.idle_test.mock_idle
import
Func
from
idlelib.idle_test.mock_tk
import
Mbox_func
...
...
@@ -96,5 +96,45 @@ class ViewFunctionTest(unittest.TestCase):
self
.
assertIsNone
(
view
)
class
ButtonClickTextViewTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
view
=
None
self
.
called
=
False
def
tearDown
(
self
):
if
self
.
view
:
self
.
view
.
destroy
()
def
test_view_text_bind_with_button
(
self
):
def
_command
():
self
.
called
=
True
self
.
view
=
tv
.
view_text
(
root
,
'TITLE_TEXT'
,
'COMMAND'
,
_utest
=
True
)
button
=
Button
(
root
,
text
=
'BUTTON'
,
command
=
_command
)
button
.
invoke
()
self
.
addCleanup
(
button
.
destroy
)
self
.
assertEqual
(
self
.
called
,
True
)
self
.
assertEqual
(
self
.
view
.
title
(),
'TITLE_TEXT'
)
self
.
assertEqual
(
self
.
view
.
textView
.
get
(
'1.0'
,
'1.end'
),
'COMMAND'
)
def
test_view_file_bind_with_button
(
self
):
def
_command
():
self
.
called
=
True
self
.
view
=
tv
.
view_file
(
root
,
'TITLE_FILE'
,
__file__
,
_utest
=
True
)
button
=
Button
(
root
,
text
=
'BUTTON'
,
command
=
_command
)
button
.
invoke
()
self
.
addCleanup
(
button
.
destroy
)
self
.
assertEqual
(
self
.
called
,
True
)
self
.
assertEqual
(
self
.
view
.
title
(),
'TITLE_FILE'
)
with
open
(
__file__
)
as
f
:
self
.
assertEqual
(
self
.
view
.
textView
.
get
(
'1.0'
,
'1.end'
),
f
.
readline
()
.
strip
())
f
.
readline
()
self
.
assertEqual
(
self
.
view
.
textView
.
get
(
'3.0'
,
'3.end'
),
f
.
readline
()
.
strip
())
if
__name__
==
'__main__'
:
unittest
.
main
(
verbosity
=
2
)
Lib/idlelib/textview.py
Dosyayı görüntüle @
ba365da9
...
...
@@ -9,14 +9,15 @@ from tkinter.messagebox import showerror
class
TextViewer
(
Toplevel
):
"A simple text viewer dialog for IDLE."
def
__init__
(
self
,
parent
,
title
,
text
,
modal
=
True
,
_htest
=
False
):
"""Show the given text in a scrollable window with a 'close' button
def
__init__
(
self
,
parent
,
title
,
text
,
modal
=
True
,
_htest
=
False
,
_utest
=
False
):
"""Show the given text in a scrollable window with a 'close' button.
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.
If modal is left True, users cannot interact with other windows
until the textview window is closed.
_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
)
...
...
@@ -42,9 +43,11 @@ class TextViewer(Toplevel):
if
modal
:
self
.
transient
(
parent
)
self
.
grab_set
()
self
.
wait_window
()
if
not
_utest
:
self
.
wait_window
()
def
CreateWidgets
(
self
):
"Create Frame with Text (with vertical Scrollbar) and Button."
frameText
=
Frame
(
self
,
relief
=
SUNKEN
,
height
=
700
)
frameButtons
=
Frame
(
self
)
self
.
buttonOk
=
Button
(
frameButtons
,
text
=
'Close'
,
...
...
@@ -65,10 +68,12 @@ class TextViewer(Toplevel):
self
.
destroy
()
def
view_text
(
parent
,
title
,
text
,
modal
=
True
):
return
TextViewer
(
parent
,
title
,
text
,
modal
)
def
view_text
(
parent
,
title
,
text
,
modal
=
True
,
_utest
=
False
):
"Display text in a TextViewer."
return
TextViewer
(
parent
,
title
,
text
,
modal
,
_utest
=
_utest
)
def
view_file
(
parent
,
title
,
filename
,
encoding
=
None
,
modal
=
True
):
def
view_file
(
parent
,
title
,
filename
,
encoding
=
None
,
modal
=
True
,
_utest
=
False
):
"Display file in a TextViever or show error message."
try
:
with
open
(
filename
,
'r'
,
encoding
=
encoding
)
as
file
:
contents
=
file
.
read
()
...
...
@@ -81,7 +86,8 @@ def view_file(parent, title, filename, encoding=None, modal=True):
message
=
str
(
err
),
parent
=
parent
)
else
:
return
view_text
(
parent
,
title
,
contents
,
modal
)
return
view_text
(
parent
,
title
,
contents
,
modal
,
_utest
=
_utest
)
if
__name__
==
'__main__'
:
import
unittest
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment