Skip to content

Commit d5d4c4e

Browse files
committed
Issue 21284: Idle: make test_formatparagraph pass even when a user changes the
reformat width in the configuration menu.
1 parent 4a63923 commit d5d4c4e

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

Lib/idlelib/FormatParagraph.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self, editwin):
3232
def close(self):
3333
self.editwin = None
3434

35-
def format_paragraph_event(self, event):
35+
def format_paragraph_event(self, event, limit=None):
3636
"""Formats paragraph to a max width specified in idleConf.
3737
3838
If text is selected, format_paragraph_event will start breaking lines
@@ -41,9 +41,12 @@ def format_paragraph_event(self, event):
4141
If no text is selected, format_paragraph_event uses the current
4242
cursor location to determine the paragraph (lines of text surrounded
4343
by blank lines) and formats it.
44+
45+
The length limit parameter is for testing with a known value.
4446
"""
45-
maxformatwidth = idleConf.GetOption(
46-
'main', 'FormatParagraph', 'paragraph', type='int')
47+
if limit == None:
48+
limit = idleConf.GetOption(
49+
'main', 'FormatParagraph', 'paragraph', type='int')
4750
text = self.editwin.text
4851
first, last = self.editwin.get_selection_indices()
4952
if first and last:
@@ -53,9 +56,9 @@ def format_paragraph_event(self, event):
5356
first, last, comment_header, data = \
5457
find_paragraph(text, text.index("insert"))
5558
if comment_header:
56-
newdata = reformat_comment(data, maxformatwidth, comment_header)
59+
newdata = reformat_comment(data, limit, comment_header)
5760
else:
58-
newdata = reformat_paragraph(data, maxformatwidth)
61+
newdata = reformat_paragraph(data, limit)
5962
text.tag_remove("sel", "1.0", "end")
6063

6164
if newdata != data:

Lib/idlelib/idle_test/test_formatparagraph.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def test_long_line(self):
293293
# Set cursor ('insert' mark) to '1.0', within text.
294294
text.insert('1.0', self.test_string)
295295
text.mark_set('insert', '1.0')
296-
self.formatter('ParameterDoesNothing')
296+
self.formatter('ParameterDoesNothing', limit=70)
297297
result = text.get('1.0', 'insert')
298298
# find function includes \n
299299
expected = (
@@ -305,7 +305,7 @@ def test_long_line(self):
305305
# Select from 1.11 to line end.
306306
text.insert('1.0', self.test_string)
307307
text.tag_add('sel', '1.11', '1.end')
308-
self.formatter('ParameterDoesNothing')
308+
self.formatter('ParameterDoesNothing', limit=70)
309309
result = text.get('1.0', 'insert')
310310
# selection excludes \n
311311
expected = (
@@ -319,7 +319,7 @@ def test_multiple_lines(self):
319319
# Select 2 long lines.
320320
text.insert('1.0', self.multiline_test_string)
321321
text.tag_add('sel', '2.0', '4.0')
322-
self.formatter('ParameterDoesNothing')
322+
self.formatter('ParameterDoesNothing', limit=70)
323323
result = text.get('2.0', 'insert')
324324
expected = (
325325
" The second line's length is way over the max width. It goes on and\n"
@@ -334,7 +334,7 @@ def test_comment_block(self):
334334

335335
# Set cursor ('insert') to '1.0', within block.
336336
text.insert('1.0', self.multiline_test_comment)
337-
self.formatter('ParameterDoesNothing')
337+
self.formatter('ParameterDoesNothing', limit=70)
338338
result = text.get('1.0', 'insert')
339339
expected = (
340340
"# The first line is under the max width. The second line's length is\n"
@@ -348,7 +348,7 @@ def test_comment_block(self):
348348
# Select line 2, verify line 1 unaffected.
349349
text.insert('1.0', self.multiline_test_comment)
350350
text.tag_add('sel', '2.0', '3.0')
351-
self.formatter('ParameterDoesNothing')
351+
self.formatter('ParameterDoesNothing', limit=70)
352352
result = text.get('1.0', 'insert')
353353
expected = (
354354
"# The first line is under the max width.\n"

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ Extension Modules
186186
IDLE
187187
----
188188

189+
- Issue 21284: Paragraph reformat test passes after user changes reformat width.
190+
189191
- Issue #17654: Ensure IDLE menus are customized properly on OS X for
190192
non-framework builds and for all variants of Tk.
191193

0 commit comments

Comments
 (0)