[Python-checkins] cpython: Issue #27732: Silence test_idle with dummy bell functions.
terry.reedy
python-checkins at python.org
Wed Aug 10 23:45:09 EDT 2016
https://hg.python.org/cpython/rev/2eb84fe85889
changeset: 102612:2eb84fe85889
parent: 102610:ba8d87a27335
user: Terry Jan Reedy <tjreedy at udel.edu>
date: Wed Aug 10 23:44:54 2016 -0400
summary:
Issue #27732: Silence test_idle with dummy bell functions.
files:
Lib/idlelib/autoexpand.py | 6 +++-
Lib/idlelib/idle_test/test_autoexpand.py | 2 +
Lib/idlelib/idle_test/test_parenmatch.py | 13 ++++++++---
Lib/idlelib/idle_test/test_replace.py | 6 ++--
Lib/idlelib/idle_test/test_search.py | 2 +
Lib/idlelib/idle_test/test_undo.py | 2 +-
Lib/idlelib/parenmatch.py | 9 ++-----
Lib/idlelib/replace.py | 8 +++---
Lib/idlelib/search.py | 4 +-
Lib/idlelib/searchbase.py | 3 +-
10 files changed, 32 insertions(+), 23 deletions(-)
diff --git a/Lib/idlelib/autoexpand.py b/Lib/idlelib/autoexpand.py
--- a/Lib/idlelib/autoexpand.py
+++ b/Lib/idlelib/autoexpand.py
@@ -31,6 +31,7 @@
def __init__(self, editwin):
self.text = editwin.text
+ self.bell = self.text.bell
self.state = None
def expand_word_event(self, event):
@@ -46,14 +47,14 @@
words = self.getwords()
index = 0
if not words:
- self.text.bell()
+ self.bell()
return "break"
word = self.getprevword()
self.text.delete("insert - %d chars" % len(word), "insert")
newword = words[index]
index = (index + 1) % len(words)
if index == 0:
- self.text.bell() # Warn we cycled around
+ self.bell() # Warn we cycled around
self.text.insert("insert", newword)
curinsert = self.text.index("insert")
curline = self.text.get("insert linestart", "insert lineend")
@@ -99,6 +100,7 @@
i = i-1
return line[i:]
+
if __name__ == '__main__':
import unittest
unittest.main('idlelib.idle_test.test_autoexpand', verbosity=2)
diff --git a/Lib/idlelib/idle_test/test_autoexpand.py b/Lib/idlelib/idle_test/test_autoexpand.py
--- a/Lib/idlelib/idle_test/test_autoexpand.py
+++ b/Lib/idlelib/idle_test/test_autoexpand.py
@@ -22,6 +22,7 @@
else:
cls.text = Text()
cls.auto_expand = AutoExpand(Dummy_Editwin(cls.text))
+ cls.auto_expand.bell = lambda: None
@classmethod
def tearDownClass(cls):
@@ -137,5 +138,6 @@
new_state = self.auto_expand.state
self.assertNotEqual(initial_state, new_state)
+
if __name__ == '__main__':
unittest.main(verbosity=2)
diff --git a/Lib/idlelib/idle_test/test_parenmatch.py b/Lib/idlelib/idle_test/test_parenmatch.py
--- a/Lib/idlelib/idle_test/test_parenmatch.py
+++ b/Lib/idlelib/idle_test/test_parenmatch.py
@@ -38,12 +38,17 @@
def tearDown(self):
self.text.delete('1.0', 'end')
+ def get_parenmatch(self):
+ pm = ParenMatch(self.editwin)
+ pm.bell = lambda: None
+ return pm
+
def test_paren_expression(self):
"""
Test ParenMatch with 'expression' style.
"""
text = self.text
- pm = ParenMatch(self.editwin)
+ pm = self.get_parenmatch()
pm.set_style('expression')
text.insert('insert', 'def foobar(a, b')
@@ -66,7 +71,7 @@
Test ParenMatch with 'default' style.
"""
text = self.text
- pm = ParenMatch(self.editwin)
+ pm = self.get_parenmatch()
pm.set_style('default')
text.insert('insert', 'def foobar(a, b')
@@ -86,7 +91,7 @@
These cases force conditional expression and alternate paths.
"""
text = self.text
- pm = ParenMatch(self.editwin)
+ pm = self.get_parenmatch()
text.insert('insert', '# this is a commen)')
self.assertIsNone(pm.paren_closed_event('event'))
@@ -99,7 +104,7 @@
self.assertIsNone(pm.paren_closed_event('event'))
def test_handle_restore_timer(self):
- pm = ParenMatch(self.editwin)
+ pm = self.get_parenmatch()
pm.restore_event = Mock()
pm.handle_restore_timer(0)
self.assertTrue(pm.restore_event.called)
diff --git a/Lib/idlelib/idle_test/test_replace.py b/Lib/idlelib/idle_test/test_replace.py
--- a/Lib/idlelib/idle_test/test_replace.py
+++ b/Lib/idlelib/idle_test/test_replace.py
@@ -7,7 +7,7 @@
from tkinter import Tk, Text
from idlelib.idle_test.mock_tk import Mbox
import idlelib.searchengine as se
-import idlelib.replace as rd
+from idlelib.replace import ReplaceDialog
orig_mbox = se.tkMessageBox
showerror = Mbox.showerror
@@ -21,7 +21,8 @@
cls.root.withdraw()
se.tkMessageBox = Mbox
cls.engine = se.SearchEngine(cls.root)
- cls.dialog = rd.ReplaceDialog(cls.root, cls.engine)
+ cls.dialog = ReplaceDialog(cls.root, cls.engine)
+ cls.dialog.bell = lambda: None
cls.dialog.ok = Mock()
cls.text = Text(cls.root)
cls.text.undo_block_start = Mock()
@@ -70,7 +71,6 @@
# text found and replaced
pv.set('a')
rv.set('asdf')
- self.dialog.open(self.text)
replace()
equal(text.get('1.8', '1.12'), 'asdf')
diff --git a/Lib/idlelib/idle_test/test_search.py b/Lib/idlelib/idle_test/test_search.py
--- a/Lib/idlelib/idle_test/test_search.py
+++ b/Lib/idlelib/idle_test/test_search.py
@@ -29,6 +29,7 @@
def setUp(self):
self.engine = se.SearchEngine(self.root)
self.dialog = sd.SearchDialog(self.root, self.engine)
+ self.dialog.bell = lambda: None
self.text = tk.Text(self.root)
self.text.insert('1.0', 'Hello World!')
@@ -38,6 +39,7 @@
self.engine.setpat('')
self.assertFalse(self.dialog.find_again(text))
+ self.dialog.bell = lambda: None
self.engine.setpat('Hello')
self.assertTrue(self.dialog.find_again(text))
diff --git a/Lib/idlelib/idle_test/test_undo.py b/Lib/idlelib/idle_test/test_undo.py
--- a/Lib/idlelib/idle_test/test_undo.py
+++ b/Lib/idlelib/idle_test/test_undo.py
@@ -29,8 +29,8 @@
def setUp(self):
self.delegator = UndoDelegator()
+ self.delegator.bell = Mock()
self.percolator.insertfilter(self.delegator)
- self.delegator.bell = Mock(wraps=self.delegator.bell)
def tearDown(self):
self.percolator.removefilter(self.delegator)
diff --git a/Lib/idlelib/parenmatch.py b/Lib/idlelib/parenmatch.py
--- a/Lib/idlelib/parenmatch.py
+++ b/Lib/idlelib/parenmatch.py
@@ -64,6 +64,7 @@
# and deactivate_restore (which calls event_delete).
editwin.text.bind(self.RESTORE_VIRTUAL_EVENT_NAME,
self.restore_event)
+ self.bell = self.text.bell if self.BELL else lambda: None
self.counter = 0
self.is_restore_active = 0
self.set_style(self.STYLE)
@@ -93,7 +94,7 @@
indices = (HyperParser(self.editwin, "insert")
.get_surrounding_brackets())
if indices is None:
- self.warn_mismatched()
+ self.bell()
return
self.activate_restore()
self.create_tag(indices)
@@ -109,7 +110,7 @@
return
indices = hp.get_surrounding_brackets(_openers[closer], True)
if indices is None:
- self.warn_mismatched()
+ self.bell()
return
self.activate_restore()
self.create_tag(indices)
@@ -124,10 +125,6 @@
if timer_count == self.counter:
self.restore_event()
- def warn_mismatched(self):
- if self.BELL:
- self.text.bell()
-
# any one of the create_tag_XXX methods can be used depending on
# the style
diff --git a/Lib/idlelib/replace.py b/Lib/idlelib/replace.py
--- a/Lib/idlelib/replace.py
+++ b/Lib/idlelib/replace.py
@@ -95,7 +95,7 @@
text = self.text
res = self.engine.search_text(text, prog)
if not res:
- text.bell()
+ self.bell()
return
text.tag_remove("sel", "1.0", "end")
text.tag_remove("hit", "1.0", "end")
@@ -142,7 +142,7 @@
text = self.text
res = self.engine.search_text(text, None, ok)
if not res:
- text.bell()
+ self.bell()
return False
line, m = res
i, j = m.span()
@@ -204,8 +204,8 @@
def _replace_dialog(parent): # htest #
- from tkinter import Toplevel, Text
- from tkiter.ttk import Button
+ from tkinter import Toplevel, Text, END, SEL
+ from tkinter.ttk import Button
box = Toplevel(parent)
box.title("Test ReplaceDialog")
diff --git a/Lib/idlelib/search.py b/Lib/idlelib/search.py
--- a/Lib/idlelib/search.py
+++ b/Lib/idlelib/search.py
@@ -51,7 +51,7 @@
selfirst = text.index("sel.first")
sellast = text.index("sel.last")
if selfirst == first and sellast == last:
- text.bell()
+ self.bell()
return False
except TclError:
pass
@@ -61,7 +61,7 @@
text.see("insert")
return True
else:
- text.bell()
+ self.bell()
return False
def find_selection(self, text):
diff --git a/Lib/idlelib/searchbase.py b/Lib/idlelib/searchbase.py
--- a/Lib/idlelib/searchbase.py
+++ b/Lib/idlelib/searchbase.py
@@ -79,6 +79,7 @@
top.wm_title(self.title)
top.wm_iconname(self.icon)
self.top = top
+ self.bell = top.bell
self.row = 0
self.top.grid_columnconfigure(0, pad=2, weight=0)
@@ -188,7 +189,7 @@
width,height, x,y = list(map(int, re.split('[x+]', parent.geometry())))
self.top.geometry("+%d+%d" % (x + 40, y + 175))
- def default_command(self): pass
+ def default_command(self, dummy): pass
if __name__ == '__main__':
import unittest
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list