Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2525992
bpo-35196: optimize Squeezer's write() interception
taleinat Nov 10, 2018
6b60df6
remove dead, old test code from test_squeezer.py
taleinat Nov 10, 2018
0e30a72
bpo-35196: fix test_reload() failing
taleinat Nov 11, 2018
76e8ea2
remove unnecessary additional check which doesn't improve performance
taleinat Dec 24, 2018
65ee056
instantiate Squeezer only on PyShell windows
taleinat Dec 24, 2018
485d954
hard-code tab width to 8 (always true for IDLE's shell)
taleinat Dec 24, 2018
22f1c4f
Merge remote-tracking branch 'origin/master' into pr_10454
terryjreedy Dec 27, 2018
5f0e69f
Add blurb and idlelib news.
terryjreedy Dec 27, 2018
23af040
Condense character width comment and update to 8.6.
terryjreedy Dec 27, 2018
8a4ca02
In test, change deprecated assertEquals to assertEqual.
terryjreedy Dec 27, 2018
1f56ee8
Add coverage information. Details in comment.
terryjreedy Dec 28, 2018
390d089
Add X windows comment.
terryjreedy Dec 28, 2018
8e12a81
Move PyShell only code to pyshell.PyShell.
terryjreedy Dec 28, 2018
ee25bac
Use existing local reference.
terryjreedy Dec 28, 2018
9ac5156
Fix comments (# Cap ... length ... end.) in squeezer.py.
terryjreedy Dec 28, 2018
6e1556d
Fix comments in test_squeezer to PEP standards. Uncomment test
terryjreedy Dec 28, 2018
2f0e0a5
fix bug in setting Squeezer._instance_weakref and improve test coverage
taleinat Jan 3, 2019
37daa8a
add a do-nothing test case for Squeezer.reload(), and fix test cleanup
taleinat Jan 3, 2019
62ca6d3
re-format inline comments
taleinat Jan 3, 2019
3f77905
Update test_squeezer, trigger retest
terryjreedy Jan 11, 2019
17bc8d9
Reverse asssertions to test 2nd
terryjreedy Jan 11, 2019
69eaa4f
Change taked to taken
terryjreedy Jan 12, 2019
3c3fb9d
fix test_reload() check that zero_with_char has increased
taleinat Jan 12, 2019
05543b0
Change 'name' to 'font' in load_font Font().
terryjreedy Jan 12, 2019
66c01e5
Reset font size by resetting font option.
terryjreedy Jan 12, 2019
ae8a483
minor code cleanup in Squeezer's mywrite()
taleinat Jan 13, 2019
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
hard-code tab width to 8 (always true for IDLE's shell)
  • Loading branch information
taleinat committed Dec 24, 2018
commit 485d954a3bb2d2e23fed6dcb9beaf13b464ce131
71 changes: 21 additions & 50 deletions Lib/idlelib/idle_test/test_squeezer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def cleanup_root():

class CountLinesTest(unittest.TestCase):
"""Tests for the count_lines_with_wrapping function."""
def check(self, expected, text, linewidth, tabwidth):
def check(self, expected, text, linewidth):
return self.assertEqual(
expected,
count_lines_with_wrapping(text, linewidth, tabwidth),
count_lines_with_wrapping(text, linewidth),
)

def test_count_empty(self):
Expand All @@ -55,37 +55,14 @@ def test_count_several_lines(self):
"""Test with several lines of text."""
self.assertEqual(count_lines_with_wrapping("1\n2\n3\n"), 3)

def test_tab_width(self):
"""Test with various tab widths and line widths."""
self.check(expected=1, text='\t' * 1, linewidth=8, tabwidth=4)
self.check(expected=1, text='\t' * 2, linewidth=8, tabwidth=4)
self.check(expected=2, text='\t' * 3, linewidth=8, tabwidth=4)
self.check(expected=2, text='\t' * 4, linewidth=8, tabwidth=4)
self.check(expected=3, text='\t' * 5, linewidth=8, tabwidth=4)

# test longer lines and various tab widths
self.check(expected=4, text='\t' * 10, linewidth=12, tabwidth=4)
self.check(expected=10, text='\t' * 10, linewidth=12, tabwidth=8)
self.check(expected=2, text='\t' * 4, linewidth=10, tabwidth=3)

# test tabwidth=1
self.check(expected=2, text='\t' * 9, linewidth=5, tabwidth=1)
self.check(expected=2, text='\t' * 10, linewidth=5, tabwidth=1)
self.check(expected=3, text='\t' * 11, linewidth=5, tabwidth=1)

# test for off-by-one errors
self.check(expected=2, text='\t' * 6, linewidth=12, tabwidth=4)
self.check(expected=3, text='\t' * 6, linewidth=11, tabwidth=4)
self.check(expected=2, text='\t' * 6, linewidth=13, tabwidth=4)

def test_empty_lines(self):
self.check(expected=1, text='\n', linewidth=80, tabwidth=8)
self.check(expected=2, text='\n\n', linewidth=80, tabwidth=8)
self.check(expected=10, text='\n' * 10, linewidth=80, tabwidth=8)
self.check(expected=1, text='\n', linewidth=80)
self.check(expected=2, text='\n\n', linewidth=80)
self.check(expected=10, text='\n' * 10, linewidth=80)

def test_long_line(self):
self.check(expected=3, text='a' * 200, linewidth=80, tabwidth=8)
self.check(expected=3, text='a' * 200 + '\n', linewidth=80, tabwidth=8)
self.check(expected=3, text='a' * 200, linewidth=80)
self.check(expected=3, text='a' * 200 + '\n', linewidth=80)

def test_several_lines_different_lengths(self):
text = dedent("""\
Expand All @@ -94,12 +71,11 @@ def test_several_lines_different_lengths(self):

7 chars
13 characters""")
self.check(expected=5, text=text, linewidth=80, tabwidth=8)
self.check(expected=5, text=text + '\n', linewidth=80, tabwidth=8)
self.check(expected=6, text=text, linewidth=40, tabwidth=8)
self.check(expected=7, text=text, linewidth=20, tabwidth=8)
self.check(expected=11, text=text, linewidth=10, tabwidth=8)

self.check(expected=5, text=text, linewidth=80)
self.check(expected=5, text=text + '\n', linewidth=80)
self.check(expected=6, text=text, linewidth=40)
self.check(expected=7, text=text, linewidth=20)
self.check(expected=11, text=text, linewidth=10)

class SqueezerTest(unittest.TestCase):
"""Tests for the Squeezer class."""
Expand All @@ -117,7 +93,6 @@ def make_squeezer_instance(self, editor_window=None):
editor_window = self.make_mock_editor_window()
squeezer = Squeezer(editor_window)
squeezer.get_line_width = Mock(return_value=80)
squeezer.editwin.get_tk_tabwidth = Mock(return_value=8)
return squeezer

def make_text_widget(self):
Expand All @@ -132,25 +107,21 @@ def test_count_lines(self):
editwin = self.make_mock_editor_window()
squeezer = self.make_squeezer_instance(editwin)

for text_code, tab_width, line_width, expected in [
(r"'\n'", 8, 80, 1),
(r"'\n' * 3", 8, 80, 3),
(r"'a' * 40 + '\n'", 8, 80, 1),
(r"'a' * 80 + '\n'", 8, 80, 1),
for text_code, line_width, expected in [
(r"'\n'", 80, 1),
(r"'\n' * 3", 80, 3),
(r"'a' * 40 + '\n'", 80, 1),
(r"'a' * 80 + '\n'", 80, 1),
# TODO: uncomment the next test case after bpo-35208 is fixed
# (r"'a' * 200 + '\n'", 8, 80, 3),
(r"'aa\t' * 20", 8, 80, 2),
(r"'aa\t' * 21", 8, 80, 3),
(r"'aa\t' * 20", 8, 40, 4),
(r"'aa\t' * 20", 4, 80, 1),
(r"'aa\t' * 21", 4, 80, 2),
# (r"'a' * 200 + '\n'", 80, 3),
(r"'aa\t' * 20", 80, 2),
(r"'aa\t' * 21", 80, 3),
(r"'aa\t' * 20", 40, 4),
]:
with self.subTest(text_code=text_code,
tab_width=tab_width,
line_width=line_width,
expected=expected):
text = eval(text_code)
editwin.get_tk_tabwidth.return_value = tab_width
squeezer.get_line_width.return_value = line_width
self.assertEquals(squeezer.count_lines(text), expected)

Expand Down
7 changes: 3 additions & 4 deletions Lib/idlelib/squeezer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
from idlelib import macosx


def count_lines_with_wrapping(s, linewidth=80, tabwidth=8):
def count_lines_with_wrapping(s, linewidth=80):
"""Count the number of lines in a given string.

Lines are counted as if the string was wrapped so that lines are never over
linewidth characters long.

Tabs are considered tabwidth characters long.
"""
tabwidth = 8 # this is currently always true in IDLE's shell
pos = 0
linecount = 1
current_column = 0
Expand Down Expand Up @@ -299,10 +300,8 @@ def count_lines(self, s):

Tabs are considered tabwidth characters long.
"""
# Tab width is configurable
tabwidth = self.editwin.get_tk_tabwidth()
linewidth = self.get_line_width()
return count_lines_with_wrapping(s, linewidth, tabwidth)
return count_lines_with_wrapping(s, linewidth)

def get_line_width(self):
# The maximum line length in pixels: The width of the text widget,
Expand Down