summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/idle_test/test_parenmatch.py
diff options
context:
space:
mode:
authorwohlganger <charles.wohlganger@gmail.com>2017-06-28 02:36:23 (GMT)
committerterryjreedy <tjreedy@udel.edu>2017-06-28 02:36:23 (GMT)
commitfae2c3538ecbcdd37b6eca891c0815d2093c39e3 (patch)
tree020cc2337e161624e52fccaf0765cb17838566c6 /Lib/idlelib/idle_test/test_parenmatch.py
parent84d9d14a1fa395fbd21262ba195490be25a7b3bc (diff)
downloadcpython-fae2c3538ecbcdd37b6eca891c0815d2093c39e3.zip
cpython-fae2c3538ecbcdd37b6eca891c0815d2093c39e3.tar.gz
cpython-fae2c3538ecbcdd37b6eca891c0815d2093c39e3.tar.bz2
bpo-30723: IDLE -- Enhance parenmatch; add style, flash, and help (#2306)
* Add 'parens' style to highlight both opener and closer. * Make 'default' style, which is not default, a synonym for 'opener'. * Make time-delay work the same with all styles. * Add help for config dialog extensions tab, including parenmatch. * Add new tests. Original patch by Charles Wohlganger.
Diffstat (limited to 'Lib/idlelib/idle_test/test_parenmatch.py')
-rw-r--r--Lib/idlelib/idle_test/test_parenmatch.py68
1 files changed, 31 insertions, 37 deletions
diff --git a/Lib/idlelib/idle_test/test_parenmatch.py b/Lib/idlelib/idle_test/test_parenmatch.py
index cbec350..6943a70 100644
--- a/Lib/idlelib/idle_test/test_parenmatch.py
+++ b/Lib/idlelib/idle_test/test_parenmatch.py
@@ -3,13 +3,14 @@
This must currently be a gui test because ParenMatch methods use
several text methods not defined on idlelib.idle_test.mock_tk.Text.
'''
+from idlelib.parenmatch import ParenMatch
from test.support import requires
requires('gui')
import unittest
from unittest.mock import Mock
from tkinter import Tk, Text
-from idlelib.parenmatch import ParenMatch
+
class DummyEditwin:
def __init__(self, text):
@@ -44,46 +45,39 @@ class ParenMatchTest(unittest.TestCase):
pm.bell = lambda: None
return pm
- def test_paren_expression(self):
+ def test_paren_styles(self):
"""
- Test ParenMatch with 'expression' style.
+ Test ParenMatch with each style.
"""
text = self.text
pm = self.get_parenmatch()
- pm.set_style('expression')
-
- text.insert('insert', 'def foobar(a, b')
- pm.flash_paren_event('event')
- self.assertIn('<<parenmatch-check-restore>>', text.event_info())
- self.assertTupleEqual(text.tag_prevrange('paren', 'end'),
- ('1.10', '1.15'))
- text.insert('insert', ')')
- pm.restore_event()
- self.assertNotIn('<<parenmatch-check-restore>>', text.event_info())
- self.assertEqual(text.tag_prevrange('paren', 'end'), ())
-
- # paren_closed_event can only be tested as below
- pm.paren_closed_event('event')
- self.assertTupleEqual(text.tag_prevrange('paren', 'end'),
- ('1.10', '1.16'))
-
- def test_paren_default(self):
- """
- Test ParenMatch with 'default' style.
- """
- text = self.text
- pm = self.get_parenmatch()
- pm.set_style('default')
-
- text.insert('insert', 'def foobar(a, b')
- pm.flash_paren_event('event')
- self.assertIn('<<parenmatch-check-restore>>', text.event_info())
- self.assertTupleEqual(text.tag_prevrange('paren', 'end'),
- ('1.10', '1.11'))
- text.insert('insert', ')')
- pm.restore_event()
- self.assertNotIn('<<parenmatch-check-restore>>', text.event_info())
- self.assertEqual(text.tag_prevrange('paren', 'end'), ())
+ for style, range1, range2 in (
+ ('opener', ('1.10', '1.11'), ('1.10', '1.11')),
+ ('default',('1.10', '1.11'),('1.10', '1.11')),
+ ('parens', ('1.14', '1.15'), ('1.15', '1.16')),
+ ('expression', ('1.10', '1.15'), ('1.10', '1.16'))):
+ with self.subTest(style=style):
+ text.delete('1.0', 'end')
+ pm.set_style(style)
+ text.insert('insert', 'def foobar(a, b')
+
+ pm.flash_paren_event('event')
+ self.assertIn('<<parenmatch-check-restore>>', text.event_info())
+ if style == 'parens':
+ self.assertTupleEqual(text.tag_nextrange('paren', '1.0'),
+ ('1.10', '1.11'))
+ self.assertTupleEqual(
+ text.tag_prevrange('paren', 'end'), range1)
+
+ text.insert('insert', ')')
+ pm.restore_event()
+ self.assertNotIn('<<parenmatch-check-restore>>',
+ text.event_info())
+ self.assertEqual(text.tag_prevrange('paren', 'end'), ())
+
+ pm.paren_closed_event('event')
+ self.assertTupleEqual(
+ text.tag_prevrange('paren', 'end'), range2)
def test_paren_corner(self):
"""