summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/idle_test/test_codecontext.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-05-24 03:26:54 (GMT)
committerGitHub <noreply@github.com>2018-05-24 03:26:54 (GMT)
commitb2ab5dc72b36d074a86f2b1d91ae804e5a7210f8 (patch)
tree7230f28f99c04b1721eedabb6fce663d4e7e2852 /Lib/idlelib/idle_test/test_codecontext.py
parentdd7a255911f364cf521676082a89d4cac307737e (diff)
downloadcpython-b2ab5dc72b36d074a86f2b1d91ae804e5a7210f8.zip
cpython-b2ab5dc72b36d074a86f2b1d91ae804e5a7210f8.tar.gz
cpython-b2ab5dc72b36d074a86f2b1d91ae804e5a7210f8.tar.bz2
bpo-33628: IDLE: Minor code cleanup of codecontext.py and its tests (GH-7085)
(cherry picked from commit 8506016f904ba6bc27bf5261f27a0bdd5945cd26) Co-authored-by: Cheryl Sabella <cheryl.sabella@gmail.com>
Diffstat (limited to 'Lib/idlelib/idle_test/test_codecontext.py')
-rw-r--r--Lib/idlelib/idle_test/test_codecontext.py39
1 files changed, 20 insertions, 19 deletions
diff --git a/Lib/idlelib/idle_test/test_codecontext.py b/Lib/idlelib/idle_test/test_codecontext.py
index 448094e..ed45828 100644
--- a/Lib/idlelib/idle_test/test_codecontext.py
+++ b/Lib/idlelib/idle_test/test_codecontext.py
@@ -96,8 +96,6 @@ class CodeContextTest(unittest.TestCase):
eq(self.root.tk.call('after', 'info', self.cc.t2)[1], 'timer')
def test_del(self):
- self.root.tk.call('after', 'info', self.cc.t1)
- self.root.tk.call('after', 'info', self.cc.t2)
self.cc.__del__()
with self.assertRaises(TclError) as msg:
self.root.tk.call('after', 'info', self.cc.t1)
@@ -135,21 +133,6 @@ class CodeContextTest(unittest.TestCase):
eq(toggle(), 'break')
self.assertIsNone(cc.label)
- def test_get_line_info(self):
- eq = self.assertEqual
- gli = self.cc.get_line_info
-
- # Line 1 is not a BLOCKOPENER.
- eq(gli(1), (codecontext.INFINITY, '', False))
- # Line 2 is a BLOCKOPENER without an indent.
- eq(gli(2), (0, 'class C1():', 'class'))
- # Line 3 is not a BLOCKOPENER and does not return the indent level.
- eq(gli(3), (codecontext.INFINITY, ' # Class comment.', False))
- # Line 4 is a BLOCKOPENER and is indented.
- eq(gli(4), (4, ' def __init__(self, a, b):', 'def'))
- # Line 8 is a different BLOCKOPENER and is indented.
- eq(gli(8), (8, ' if a > b:', 'if'))
-
def test_get_context(self):
eq = self.assertEqual
gc = self.cc.get_context
@@ -323,8 +306,8 @@ class CodeContextTest(unittest.TestCase):
class HelperFunctionText(unittest.TestCase):
- def test_getspacesfirstword(self):
- get = codecontext.getspacesfirstword
+ def test_get_spaces_firstword(self):
+ get = codecontext.get_spaces_firstword
test_lines = (
(' first word', (' ', 'first')),
('\tfirst word', ('\t', 'first')),
@@ -342,6 +325,24 @@ class HelperFunctionText(unittest.TestCase):
c=re.compile(r'^(\s*)([^\s]*)')),
(' ', '(continuation)'))
+ def test_get_line_info(self):
+ eq = self.assertEqual
+ gli = codecontext.get_line_info
+ lines = code_sample.splitlines()
+
+ # Line 1 is not a BLOCKOPENER.
+ eq(gli(lines[0]), (codecontext.INFINITY, '', False))
+ # Line 2 is a BLOCKOPENER without an indent.
+ eq(gli(lines[1]), (0, 'class C1():', 'class'))
+ # Line 3 is not a BLOCKOPENER and does not return the indent level.
+ eq(gli(lines[2]), (codecontext.INFINITY, ' # Class comment.', False))
+ # Line 4 is a BLOCKOPENER and is indented.
+ eq(gli(lines[3]), (4, ' def __init__(self, a, b):', 'def'))
+ # Line 8 is a different BLOCKOPENER and is indented.
+ eq(gli(lines[7]), (8, ' if a > b:', 'if'))
+ # Test tab.
+ eq(gli('\tif a == b:'), (1, '\tif a == b:', 'if'))
+
if __name__ == '__main__':
unittest.main(verbosity=2)