From e9c12d9a35e22b76a53943e7aba75c25c491c531 Mon Sep 17 00:00:00 2001 From: Jonathan Eunice Date: Wed, 7 Jun 2017 15:41:17 -0400 Subject: [PATCH 1/2] added test for textwrap backtracking --- Lib/test/test_textwrap.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Lib/test/test_textwrap.py b/Lib/test/test_textwrap.py index 5a33c151642c62..1ef9dfe29d9f84 100644 --- a/Lib/test/test_textwrap.py +++ b/Lib/test/test_textwrap.py @@ -559,6 +559,20 @@ def test_placeholder(self): placeholder=' [truncated]...') self.check_wrap(self.text, 80, [self.text], placeholder='.' * 1000) + def test_placeholder_backtrack(self): + # Test a relatively rare case which seems to occur + # when max_lines insufficient, but the what would be + # the last wrapped line so long that the placeholder + # cannot be added there without violence. So, textwrap + # backtracks and adds the placeholder to the penultimate + # line. This test exercises several lines that otherwise + # have no test coverage. + text = 'Good grief Python features are advancing quickly!' + self.check_wrap(text, 12, + ['Good grief', 'Python*****'], + max_lines=3, + placeholder='*****') + class LongWordTestCase (BaseTestCase): def setUp(self): From e10b9de91c3c23ac92f3ba37c8315f46ec0b8d2f Mon Sep 17 00:00:00 2001 From: Jonathan Eunice Date: Wed, 7 Jun 2017 16:21:40 -0400 Subject: [PATCH 2/2] tweak comment and indentation --- Lib/test/test_textwrap.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Lib/test/test_textwrap.py b/Lib/test/test_textwrap.py index 1ef9dfe29d9f84..47d97bda86fd1f 100644 --- a/Lib/test/test_textwrap.py +++ b/Lib/test/test_textwrap.py @@ -560,18 +560,15 @@ def test_placeholder(self): self.check_wrap(self.text, 80, [self.text], placeholder='.' * 1000) def test_placeholder_backtrack(self): - # Test a relatively rare case which seems to occur - # when max_lines insufficient, but the what would be - # the last wrapped line so long that the placeholder - # cannot be added there without violence. So, textwrap - # backtracks and adds the placeholder to the penultimate - # line. This test exercises several lines that otherwise - # have no test coverage. + # Test special case when max_lines insufficient, but what + # would be last wrapped line so long the placeholder cannot + # be added there without violence. So, textwrap backtracks, + # adding placeholder to the penultimate line. text = 'Good grief Python features are advancing quickly!' self.check_wrap(text, 12, - ['Good grief', 'Python*****'], - max_lines=3, - placeholder='*****') + ['Good grief', 'Python*****'], + max_lines=3, + placeholder='*****') class LongWordTestCase (BaseTestCase):