Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0a4d13e

Browse files
committed
Issue #21477: Add htests for Search and Replace dialogs.
Patch by Saimadhav Heblikar.
1 parent aa7886d commit 0a4d13e

4 files changed

Lines changed: 73 additions & 15 deletions

File tree

Lib/idlelib/ReplaceDialog.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,34 @@ def show_hit(self, first, last):
188188
def close(self, event=None):
189189
SearchDialogBase.close(self, event)
190190
self.text.tag_remove("hit", "1.0", "end")
191+
192+
def _replace_dialog(parent):
193+
root = Tk()
194+
root.title("Test ReplaceDialog")
195+
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
196+
root.geometry("+%d+%d"%(x, y + 150))
197+
198+
# mock undo delegator methods
199+
def undo_block_start():
200+
pass
201+
202+
def undo_block_stop():
203+
pass
204+
205+
text = Text(root)
206+
text.undo_block_start = undo_block_start
207+
text.undo_block_stop = undo_block_stop
208+
text.pack()
209+
text.insert("insert","This is a sample string.\n"*10)
210+
211+
def show_replace():
212+
text.tag_add(SEL, "1.0", END)
213+
replace(text)
214+
text.tag_remove(SEL, "1.0", END)
215+
216+
button = Button(root, text="Replace", command=show_replace)
217+
button.pack()
218+
219+
if __name__ == '__main__':
220+
from idlelib.idle_test.htest import run
221+
run(_replace_dialog)

Lib/idlelib/SearchDialog.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,25 @@ def find_selection(self, text):
6565
if pat:
6666
self.engine.setcookedpat(pat)
6767
return self.find_again(text)
68+
69+
def _search_dialog(parent):
70+
root = Tk()
71+
root.title("Test SearchDialog")
72+
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
73+
root.geometry("+%d+%d"%(x, y + 150))
74+
text = Text(root)
75+
text.pack()
76+
text.insert("insert","This is a sample string.\n"*10)
77+
78+
def show_find():
79+
text.tag_add(SEL, "1.0", END)
80+
s = _setup(text)
81+
s.open(text)
82+
text.tag_remove(SEL, "1.0", END)
83+
84+
button = Button(root, text="Search", command=show_find)
85+
button.pack()
86+
87+
if __name__ == '__main__':
88+
from idlelib.idle_test.htest import run
89+
run(_search_dialog)

Lib/idlelib/TreeWidget.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -453,20 +453,11 @@ def _tree_widget(parent):
453453
root.title("Test TreeWidget")
454454
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
455455
root.geometry("+%d+%d"%(x, y + 150))
456-
# test with scrollable canvas
457456
sc = ScrolledCanvas(root, bg="white", highlightthickness=0, takefocus=1)
458457
sc.frame.pack(expand=1, fill="both", side=LEFT)
459458
item = FileTreeItem(os.getcwd())
460459
node = TreeNode(sc.canvas, None, item)
461460
node.expand()
462-
463-
# test without scrollable canvas
464-
canvas = Canvas(root, bg="white", highlightthickness=0)
465-
canvas.pack(expand=0, fill="both", side=RIGHT)
466-
item = FileTreeItem(os.getcwd())
467-
node = TreeNode(canvas, None, item)
468-
node.update()
469-
470461
root.mainloop()
471462

472463
if __name__ == '__main__':

Lib/idlelib/idle_test/htest.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
'kwds': {},
5555
'msg': "Inspect names of module, class(with superclass if "
5656
"applicable), methods and functions.\nToggle nested items.\n"
57-
"Double clicking on items prints a traceback print a traceback "
58-
"for an exception that is ignored."
59-
}
57+
"Double clicking on items prints a traceback for an exception "
58+
"that is ignored."
59+
}
6060

6161
_color_delegator_spec = {
6262
'file': 'ColorDelegator',
@@ -181,6 +181,22 @@
181181
"Test for actions like text entry, and removal."
182182
}
183183

184+
_replace_dialog_spec = {
185+
'file': 'ReplaceDialog',
186+
'kwds': {},
187+
'msg': "Click the 'Replace' button.\n"
188+
"Test various replace options in the 'Replace dialog'.\n"
189+
"Click [Close] or [X] to close to the 'Replace Dialog'."
190+
}
191+
192+
_search_dialog_spec = {
193+
'file': 'SearchDialog',
194+
'kwds': {},
195+
'msg': "Click the 'Search' button.\n"
196+
"Test various search options in the 'Search dialog'.\n"
197+
"Click [Close] or [X] to close to the 'Search Dialog'."
198+
}
199+
184200
_scrolled_list_spec = {
185201
'file': 'ScrolledList',
186202
'kwds': {},
@@ -227,9 +243,7 @@
227243
_tree_widget_spec = {
228244
'file': 'TreeWidget',
229245
'kwds': {},
230-
'msg': "You should see two canvases side-by-side.\n"
231-
"The left canvas is scrollable.\n"
232-
"The right canvas is not scrollable.\n"
246+
'msg': "The canvas is scrollable.\n"
233247
"Click on folders upto to the lowest level."
234248
}
235249

0 commit comments

Comments
 (0)