8000 gh-136061: IDLE - update code in editor.Editor.load_extension by johnzhou721 · Pull Request #134874 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-136061: IDLE - update code in editor.Editor.load_extension #134874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e5f4260
fix a dos
johnzhou721 May 29, 2025
aa5b5a8
📜🤖 Added by blurb_it.
blurb-it[bot] May 29, 2025
edfa904
Update Misc/NEWS.d/next/Security/2025-05-29-03-24-18.gh-issue-134873.…
johnzhou721 May 30, 2025
2090baf
another dos and also simplify
johnzhou721 May 30, 2025
d2838a5
grumble
johnzhou721 May 30, 2025
83bafff
have condition
johnzhou721 May 30, 2025 8000
660fbd3
significant refactor
johnzhou721 May 30, 2025
15f821a
Update Lib/idlelib/editor.py
johnzhou721 Jun 1, 2025
6a59e50
rem blank line
johnzhou721 Jun 1, 2025
546f19b
write some tests
johnzhou721 Jun 1, 2025
605373b
static
johnzhou721 Jun 1, 2025
9625fcc
linter
johnzhou721 Jun 1, 2025
d0017b6
get this right
johnzhou721 Jun 1, 2025
88c318c
write more tests
johnzhou721 Jun 1, 2025
6323ab8
unconditionally remove last character, tests
johnzhou721 Jun 1, 2025
01921fc
more organized testing also speedup test
johnzhou721 Jun 1, 2025
5f9bb55
grumble
johnzhou721 Jun 1, 2025
a087395
fix some tests and add some new ones
johnzhou721 Jun 1, 2025
6604a73
fix everythign
johnzhou721 Jun 1, 2025
3f0abfb
precommit
johnzhou721 Jun 1, 2025
1e9bdfd
Merge branch 'main' into idledos
johnzhou721 Jun 12, 2025
0b3c5b6
Merge branch 'main' into idledos
johnzhou721 Jun 14, 2025
338e2fc
Merge branch 'main' into idledos
johnzhou721 Jun 15, 2025
7c92d9a
Apply suggestions from code review
terryjreedy Jun 28, 2025
e1fb6b9
Apply suggestions from code review
terryjreedy Jun 28, 2025
7b67419
Update Lib/idlelib/idle_test/test_editor.py
terryjreedy Jun 28, 2025
1037bea
Delete Misc/NEWS.d/next/Security/2025-05-29-03-24-18.gh-issue-134873.…
terryjreedy Jun 28, 2025
e505938
📜🤖 Added by blurb_it.
blurb-it[bot] Jun 28, 2025
283a27a
Apply suggestions from code review
johnzhou721 Jun 29, 2025
d58bd18
update news
johnzhou721 Jun 29, 2025
560e06b
Update News3.txt
johnzhou721 Jun 29, 2025
a09c458
Delete Misc/NEWS.d/next/IDLE/2025-06-28-13-29-52.gh-issue-136061.EQYu…
johnzhou721 Jun 30, 2025
a082fbf
Update Lib/idlelib/News3.txt
johnzhou721 Jun 30, 2025
4c1268f
Update Lib/idlelib/editor.py
johnzhou721 Jun 30, 2025
ab8ef90
Merge branch 'main' into idledos
johnzhou721 Jul 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more organized testing also speedup test
  • Loading branch information
johnzhou721 committed Jun 1, 2025
commit 01921fc070b43af2959f3168c1329783989450f0
86 changes: 54 additions & 32 deletions Lib/idlelib/idle_test/test_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from collections import namedtuple
from test.support import requires
from tkinter import Tk, Text
import time

Editor = editor.EditorWindow

Expand Down Expand Up @@ -239,41 +240,62 @@ def test_rclick(self):

class DeleteWantTest(unittest.TestCase):

data = [
("abcde" + 10000 * "\t" + 10000 * " ", [
(30000, 4, "abcde" + 7499 * "\t"),
(41005, 4, "abcde" + 10000 * "\t" + 1001 * " "),
(3, 4, "abcde"),
(6, 4, "abcde"),
(30002, 4, "abcde" + 7499 * "\t"),
]),
("abcde\tabd\t\t", [
(7, 4, "abcde\tabd"),
(12, 4, "abcde\tabd\t"),
(13, 4, "abcde\tabd\t"),
(16, 4, "abcde\tabd\t"),
]),
("abcde\tabd\t \ta", [
(7, 4, "abcde\tabd"),
(12, 4, "abcde\tabd\t"),
(13, 4, "abcde\tabd\t "),
(16, 4, "abcde\tabd\t \t"),
]),
]

def mock_delete_trail_char_and_space(self, want, chars, tabwidth):
ncharsdeleted = 0
while True:
chars = chars[:-1]
ncharsdeleted = ncharsdeleted + 1
have = len(chars.expandtabs(tabwidth))
if have <= want or chars[-1] not in " \t":
break
return ncharsdeleted, chars

def test_delete_trail_char_and_space(self):
with unittest.mock.patch.object(Editor, '__init__', return_value=None) as mock_init:
initial_time_new = time.time()
ew = Editor()

test_str = "abcde" + 10000 * "\t" + 10000 * " "
res_str = ew.delete_trail_char_and_space(30000, test_str, 4)[1]
self.assertEqual(res_str, "abcde" + 7499 * "\t")
res_str = ew.delete_trail_char_and_space(41005, test_str, 4)[1]
self.assertEqual(res_str, "abcde" + 10000 * "\t" + 1001 * " ")
res_str = ew.delete_trail_char_and_space(3, test_str, 4)[1]
self.assertEqual(res_str, "abcde")
res_str = ew.delete_trail_char_and_space(6, test_str, 4)[1]
self.assertEqual(res_str, "abcde")
res_str = ew.delete_trail_char_and_space(30002, test_str, 4)[1]
self.assertEqual(res_str, "abcde" + 7499 * "\t")

test_str = "abcde\tabd\t\t"
res_str = ew.delete_trail_char_and_space(7, test_str, 4)[1]
self.assertEqual(res_str, "abcde\tabd")
res_str = ew.delete_trail_char_and_space(12, test_str, 4)[1]
self.assertEqual(res_str, "abcde\tabd\t")
res_str = ew.delete_trail_char_and_space(13, test_str, 4)[1]
self.assertEqual(res_str, "abcde\tabd\t")
res_str = ew.delete_trail_char_and_space(16, test_str, 4)[1]
self.assertEqual(res_str, "abcde\tabd\t")

test_str = "abcde\tabd\t \ta"
res_str = ew.delete_trail_char_and_space(7, test_str, 4)[1]
self.assertEqual(res_str, "abcde\tabd")
res_str = ew.delete_trail_char_and_space(12, test_str, 4)[1]
self.assertEqual(res_str, "abcde\tabd\t")
res_str = ew.delete_trail_char_and_space(13, test_str, 4)[1]
self.assertEqual(res_str, "abcde\tabd\t ")
res_str = ew.delete_trail_char_and_space(16, test_str, 4)[1]
self.assertEqual(res_str, "abcde\tabd\t \t")
for dat in self.data:
test_str = dat[0]
for da in dat[1]:
with self.subTest(want=da[0], tabwidth=da[1], input=repr(test_str)):
res_str = ew.delete_trail_char_and_space(da[0], test_str, da[1])[1]
self.assertEqual(res_str, da[2])
time_new = time.time() - initial_time_new

initial_time_old = time.time()
with unittest.mock.patch.object(Editor, 'delete_trail_char_and_space', self.mock_delete_trail_char_and_space):
ew = Editor()
for dat in self.data:
test_str = dat[0]
for da in dat[1]:
with self.subTest(want=da[0], tabwidth=da[1], input=repr(test_str)):
res_str = ew.delete_trail_char_and_space(da[0], test_str, da[1])[1]
self.assertEqual(res_str, da[2])
time_old = time.time() - initial_time_old

self.assertGreaterEqual(time_old / time_new, 10)

if __name__ == '__main__':
unittest.main(verbosity=2)
Loading
0