Skip to content

Commit fde0041

Browse files
bpo-39663: IDLE: Add additional tests for pyparse (GH-18536)
Test when find_good_parse_start should return 0. Co-authored-by: Terry Jan Reedy <[email protected]> (cherry picked from commit ffda25f) Co-authored-by: Cheryl Sabella <[email protected]>
1 parent 3c57ca6 commit fde0041

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

Lib/idlelib/NEWS.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Released on 2019-12-16?
33
======================================
44

55

6+
bpo-39663: Add tests for pyparse find_good_parse_start().
7+
68
bpo-39600: Remove duplicate font names from configuration list.
79

810
bpo-38792: Close a shell calltip if a :exc:`KeyboardInterrupt`

Lib/idlelib/idle_test/test_pyparse.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ def test_find_good_parse_start(self):
5858
p = self.parser
5959
setcode = p.set_code
6060
start = p.find_good_parse_start
61+
def char_in_string_false(index): return False
62+
63+
# First line starts with 'def' and ends with ':', then 0 is the pos.
64+
setcode('def spam():\n')
65+
eq(start(char_in_string_false), 0)
66+
67+
# First line begins with a keyword in the list and ends
68+
# with an open brace, then 0 is the pos. This is how
69+
# hyperparser calls this function as the newline is not added
70+
# in the editor, but rather on the call to setcode.
71+
setcode('class spam( ' + ' \n')
72+
eq(start(char_in_string_false), 0)
6173

6274
# Split def across lines.
6375
setcode('"""This is a module docstring"""\n'
@@ -79,7 +91,7 @@ def test_find_good_parse_start(self):
7991

8092
# Make all text look like it's not in a string. This means that it
8193
# found a good start position.
82-
eq(start(is_char_in_string=lambda index: False), 44)
94+
eq(start(char_in_string_false), 44)
8395

8496
# If the beginning of the def line is not in a string, then it
8597
# returns that as the index.
@@ -98,7 +110,7 @@ def test_find_good_parse_start(self):
98110
' def __init__(self, a, b=True):\n'
99111
' pass\n'
100112
)
101-
eq(start(is_char_in_string=lambda index: False), 44)
113+
eq(start(char_in_string_false), 44)
102114
eq(start(is_char_in_string=lambda index: index > 44), 44)
103115
eq(start(is_char_in_string=lambda index: index >= 44), 33)
104116
# When the def line isn't split, this returns which doesn't match the
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add tests for pyparse find_good_parse_start().

0 commit comments

Comments
 (0)