From ae7a74e8287d6c0c10f4be5b83b53da4fb22a546 Mon Sep 17 00:00:00 2001 From: Cheryl Sabella Date: Mon, 17 Feb 2020 09:24:09 -0500 Subject: [PATCH 1/3] bpo-39663: IDLE: Add additional tests for pyparse --- Lib/idlelib/idle_test/test_pyparse.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Lib/idlelib/idle_test/test_pyparse.py b/Lib/idlelib/idle_test/test_pyparse.py index a2b13c38d80d5f..997a859e7e04c8 100644 --- a/Lib/idlelib/idle_test/test_pyparse.py +++ b/Lib/idlelib/idle_test/test_pyparse.py @@ -59,6 +59,17 @@ def test_find_good_parse_start(self): setcode = p.set_code start = p.find_good_parse_start + # First line starts with 'def' and ends with ':', then 0 is the pos. + setcode('def spam():\n') + eq(start(is_char_in_string=lambda index: False), 0) + + # First line begins with a keyword in the list and ends + # with an open brace, then 0 is the pos. This is how + # hyperparser calls this function as the newline is not added + # in the editor, but rather on the call to setcode. + setcode('class spam( ' + ' \n') + eq(start(is_char_in_string=lambda index: False), 0) + # Split def across lines. setcode('"""This is a module docstring"""\n' 'class C():\n' From cc94acff4a99f06709ad8aaf452c7bb68c267c10 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Mon, 17 Feb 2020 21:11:51 -0500 Subject: [PATCH 2/3] Add news item. --- Lib/idlelib/NEWS.txt | 2 ++ Misc/NEWS.d/next/IDLE/2020-02-17-21-09-03.bpo-39663.wexcsH.rst | 1 + 2 files changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/IDLE/2020-02-17-21-09-03.bpo-39663.wexcsH.rst diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt index 838120964b2d89..021e1f7710e0f8 100644 --- a/Lib/idlelib/NEWS.txt +++ b/Lib/idlelib/NEWS.txt @@ -3,6 +3,8 @@ Released on 2020-10-05? ====================================== +bpo-39663: Add tests for pyparse find_good_parse_start(). + bpo-39600: Remove duplicate font names from configuration list. bpo-38792: Close a shell calltip if a :exc:`KeyboardInterrupt` diff --git a/Misc/NEWS.d/next/IDLE/2020-02-17-21-09-03.bpo-39663.wexcsH.rst b/Misc/NEWS.d/next/IDLE/2020-02-17-21-09-03.bpo-39663.wexcsH.rst new file mode 100644 index 00000000000000..19e16329ce0a01 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2020-02-17-21-09-03.bpo-39663.wexcsH.rst @@ -0,0 +1 @@ +Add tests for pyparse find_good_parse_start(). From 17c170e227cb71db007ef6fdb9208164e9dd8bca Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Mon, 17 Feb 2020 21:12:09 -0500 Subject: [PATCH 3/3] Factor out function. --- Lib/idlelib/idle_test/test_pyparse.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Lib/idlelib/idle_test/test_pyparse.py b/Lib/idlelib/idle_test/test_pyparse.py index 997a859e7e04c8..f21baf7534420a 100644 --- a/Lib/idlelib/idle_test/test_pyparse.py +++ b/Lib/idlelib/idle_test/test_pyparse.py @@ -58,17 +58,18 @@ def test_find_good_parse_start(self): p = self.parser setcode = p.set_code start = p.find_good_parse_start + def char_in_string_false(index): return False # First line starts with 'def' and ends with ':', then 0 is the pos. setcode('def spam():\n') - eq(start(is_char_in_string=lambda index: False), 0) + eq(start(char_in_string_false), 0) # First line begins with a keyword in the list and ends # with an open brace, then 0 is the pos. This is how # hyperparser calls this function as the newline is not added # in the editor, but rather on the call to setcode. setcode('class spam( ' + ' \n') - eq(start(is_char_in_string=lambda index: False), 0) + eq(start(char_in_string_false), 0) # Split def across lines. setcode('"""This is a module docstring"""\n' @@ -90,7 +91,7 @@ def test_find_good_parse_start(self): # Make all text look like it's not in a string. This means that it # found a good start position. - eq(start(is_char_in_string=lambda index: False), 44) + eq(start(char_in_string_false), 44) # If the beginning of the def line is not in a string, then it # returns that as the index. @@ -109,7 +110,7 @@ def test_find_good_parse_start(self): ' def __init__(self, a, b=True):\n' ' pass\n' ) - eq(start(is_char_in_string=lambda index: False), 44) + eq(start(char_in_string_false), 44) eq(start(is_char_in_string=lambda index: index > 44), 44) eq(start(is_char_in_string=lambda index: index >= 44), 33) # When the def line isn't split, this returns which doesn't match the