annotate Lib/test/test_textwrap.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents fca48971ac35
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24947
544a326baf7f Add comment header block.
Greg Ward <gward@python.net>
parents: 24946
diff changeset
1 #
32210
eb41a489cc2f SF #965425: fix so hyphenated words surrounded by punctuation are
Greg Ward <gward@python.net>
parents: 32088
diff changeset
2 # Test suite for the textwrap module.
24947
544a326baf7f Add comment header block.
Greg Ward <gward@python.net>
parents: 24946
diff changeset
3 #
544a326baf7f Add comment header block.
Greg Ward <gward@python.net>
parents: 24946
diff changeset
4 # Original tests written by Greg Ward <gward@python.net>.
544a326baf7f Add comment header block.
Greg Ward <gward@python.net>
parents: 24946
diff changeset
5 # Converted to PyUnit by Peter Hansen <peter@engcorp.com>.
544a326baf7f Add comment header block.
Greg Ward <gward@python.net>
parents: 24946
diff changeset
6 # Currently maintained by Greg Ward.
544a326baf7f Add comment header block.
Greg Ward <gward@python.net>
parents: 24946
diff changeset
7 #
544a326baf7f Add comment header block.
Greg Ward <gward@python.net>
parents: 24946
diff changeset
8 # $Id$
544a326baf7f Add comment header block.
Greg Ward <gward@python.net>
parents: 24946
diff changeset
9 #
544a326baf7f Add comment header block.
Greg Ward <gward@python.net>
parents: 24946
diff changeset
10
24946
0c201548d3d4 Conform to standards documented in README:
Greg Ward <gward@python.net>
parents: 24945
diff changeset
11 import unittest
0c201548d3d4 Conform to standards documented in README:
Greg Ward <gward@python.net>
parents: 24945
diff changeset
12 from test import test_support
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
13
29023
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
14 from textwrap import TextWrapper, wrap, fill, dedent
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
15
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
16
24950
13388cafc16e Rename base test case class to (yawn) BaseTestCase.
Greg Ward <gward@python.net>
parents: 24949
diff changeset
17 class BaseTestCase(unittest.TestCase):
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
18 '''Parent class with utility methods for textwrap tests.'''
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
19
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
20 def show(self, textin):
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
21 if isinstance(textin, list):
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
22 result = []
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
23 for i in range(len(textin)):
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
24 result.append(" %d: %r" % (i, textin[i]))
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
25 result = '\n'.join(result)
30448
7cb6745be525 SF patch #806246: use basestring where possible
Raymond Hettinger <python@rcn.com>
parents: 30244
diff changeset
26 elif isinstance(textin, basestring):
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
27 result = " %s\n" % repr(textin)
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
28 return result
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
29
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
30
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
31 def check(self, result, expect):
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58472
diff changeset
32 self.assertEqual(result, expect,
24958
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
33 'expected:\n%s\nbut got:\n%s' % (
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
34 self.show(expect), self.show(result)))
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
35
25534
08148e916d38 Fix an endcase bug: initial_indent was ignored when the text was short
Guido van Rossum <guido@python.org>
parents: 24969
diff changeset
36 def check_wrap(self, text, width, expect, **kwargs):
08148e916d38 Fix an endcase bug: initial_indent was ignored when the text was short
Guido van Rossum <guido@python.org>
parents: 24969
diff changeset
37 result = wrap(text, width, **kwargs)
24949
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
38 self.check(result, expect)
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
39
25977
1d02b405e31f Ad test_funky_hyphens() to test some screwy edge cases reported in SF
Greg Ward <gward@python.net>
parents: 25534
diff changeset
40 def check_split(self, text, expect):
1d02b405e31f Ad test_funky_hyphens() to test some screwy edge cases reported in SF
Greg Ward <gward@python.net>
parents: 25534
diff changeset
41 result = self.wrapper._split(text)
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58472
diff changeset
42 self.assertEqual(result, expect,
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58472
diff changeset
43 "\nexpected %r\n"
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58472
diff changeset
44 "but got %r" % (expect, result))
24968
95186591cbcf Factored out BaseTestCase.check_split() method -- use it wherever
Greg Ward <gward@python.net>
parents: 24967
diff changeset
45
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
46
24950
13388cafc16e Rename base test case class to (yawn) BaseTestCase.
Greg Ward <gward@python.net>
parents: 24949
diff changeset
47 class WrapTestCase(BaseTestCase):
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
48
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
49 def setUp(self):
32088
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
50 self.wrapper = TextWrapper(width=45)
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
51
24946
0c201548d3d4 Conform to standards documented in README:
Greg Ward <gward@python.net>
parents: 24945
diff changeset
52 def test_simple(self):
24962
c1f682beebea Standardize behavior: no docstrings in test functions. Also strip
Guido van Rossum <guido@python.org>
parents: 24958
diff changeset
53 # Simple case: just words, spaces, and a bit of punctuation
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
54
24949
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
55 text = "Hello there, how are you this fine day? I'm glad to hear it!"
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
56
24949
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
57 self.check_wrap(text, 12,
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
58 ["Hello there,",
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
59 "how are you",
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
60 "this fine",
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
61 "day? I'm",
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
62 "glad to hear",
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
63 "it!"])
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
64 self.check_wrap(text, 42,
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
65 ["Hello there, how are you this fine day?",
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
66 "I'm glad to hear it!"])
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
67 self.check_wrap(text, 80, [text])
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
68
78886
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
69 def test_empty_string(self):
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
70 # Check that wrapping the empty string returns an empty list.
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
71 self.check_wrap("", 6, [])
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
72 self.check_wrap("", 6, [], drop_whitespace=False)
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
73
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
74 def test_empty_string_with_initial_indent(self):
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
75 # Check that the empty string is not indented.
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
76 self.check_wrap("", 6, [], initial_indent="++")
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
77 self.check_wrap("", 6, [], initial_indent="++", drop_whitespace=False)
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
78
24946
0c201548d3d4 Conform to standards documented in README:
Greg Ward <gward@python.net>
parents: 24945
diff changeset
79 def test_whitespace(self):
24962
c1f682beebea Standardize behavior: no docstrings in test functions. Also strip
Guido van Rossum <guido@python.org>
parents: 24958
diff changeset
80 # Whitespace munging and end-of-sentence detection
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
81
24949
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
82 text = """\
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
83 This is a paragraph that already has
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
84 line breaks. But some of its lines are much longer than the others,
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
85 so it needs to be wrapped.
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
86 Some lines are \ttabbed too.
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
87 What a mess!
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
88 """
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
89
24949
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
90 expect = ["This is a paragraph that already has line",
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
91 "breaks. But some of its lines are much",
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
92 "longer than the others, so it needs to be",
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
93 "wrapped. Some lines are tabbed too. What a",
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
94 "mess!"]
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
95
32088
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
96 wrapper = TextWrapper(45, fix_sentence_endings=True)
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
97 result = wrapper.wrap(text)
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
98 self.check(result, expect)
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
99
32088
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
100 result = wrapper.fill(text)
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
101 self.check(result, '\n'.join(expect))
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
102
32088
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
103 def test_fix_sentence_endings(self):
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
104 wrapper = TextWrapper(60, fix_sentence_endings=True)
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
105
32088
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
106 # SF #847346: ensure that fix_sentence_endings=True does the
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
107 # right thing even on input short enough that it doesn't need to
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
108 # be wrapped.
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
109 text = "A short line. Note the single space."
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
110 expect = ["A short line. Note the single space."]
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
111 self.check(wrapper.wrap(text), expect)
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
112
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
113 # Test some of the hairy end cases that _fix_sentence_endings()
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
114 # is supposed to handle (the easy stuff is tested in
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
115 # test_whitespace() above).
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
116 text = "Well, Doctor? What do you think?"
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
117 expect = ["Well, Doctor? What do you think?"]
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
118 self.check(wrapper.wrap(text), expect)
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
119
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
120 text = "Well, Doctor?\nWhat do you think?"
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
121 self.check(wrapper.wrap(text), expect)
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
122
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
123 text = 'I say, chaps! Anyone for "tennis?"\nHmmph!'
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
124 expect = ['I say, chaps! Anyone for "tennis?" Hmmph!']
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
125 self.check(wrapper.wrap(text), expect)
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
126
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
127 wrapper.width = 20
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
128 expect = ['I say, chaps!', 'Anyone for "tennis?"', 'Hmmph!']
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
129 self.check(wrapper.wrap(text), expect)
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
130
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
131 text = 'And she said, "Go to hell!"\nCan you believe that?'
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
132 expect = ['And she said, "Go to',
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
133 'hell!" Can you',
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
134 'believe that?']
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
135 self.check(wrapper.wrap(text), expect)
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
136
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
137 wrapper.width = 60
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
138 expect = ['And she said, "Go to hell!" Can you believe that?']
52fe93b656cf SF #847346: merge from release23-maint branch: remove misguided
Greg Ward <gward@python.net>
parents: 30448
diff changeset
139 self.check(wrapper.wrap(text), expect)
32538
4fab4a5cce2f Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 32210
diff changeset
140
46561
9e05f15f921b Issue 2635: fix bug in the fix_sentence_endings option to textwrap.fill.
Mark Dickinson <dickinsm@gmail.com>
parents: 44781
diff changeset
141 text = 'File stdio.h is nice.'
9e05f15f921b Issue 2635: fix bug in the fix_sentence_endings option to textwrap.fill.
Mark Dickinson <dickinsm@gmail.com>
parents: 44781
diff changeset
142 expect = ['File stdio.h is nice.']
9e05f15f921b Issue 2635: fix bug in the fix_sentence_endings option to textwrap.fill.
Mark Dickinson <dickinsm@gmail.com>
parents: 44781
diff changeset
143 self.check(wrapper.wrap(text), expect)
9e05f15f921b Issue 2635: fix bug in the fix_sentence_endings option to textwrap.fill.
Mark Dickinson <dickinsm@gmail.com>
parents: 44781
diff changeset
144
24946
0c201548d3d4 Conform to standards documented in README:
Greg Ward <gward@python.net>
parents: 24945
diff changeset
145 def test_wrap_short(self):
24962
c1f682beebea Standardize behavior: no docstrings in test functions. Also strip
Guido van Rossum <guido@python.org>
parents: 24958
diff changeset
146 # Wrapping to make short lines longer
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
147
24949
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
148 text = "This is a\nshort paragraph."
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
149
24949
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
150 self.check_wrap(text, 20, ["This is a short",
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
151 "paragraph."])
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
152 self.check_wrap(text, 40, ["This is a short paragraph."])
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
153
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
154
25534
08148e916d38 Fix an endcase bug: initial_indent was ignored when the text was short
Guido van Rossum <guido@python.org>
parents: 24969
diff changeset
155 def test_wrap_short_1line(self):
08148e916d38 Fix an endcase bug: initial_indent was ignored when the text was short
Guido van Rossum <guido@python.org>
parents: 24969
diff changeset
156 # Test endcases
08148e916d38 Fix an endcase bug: initial_indent was ignored when the text was short
Guido van Rossum <guido@python.org>
parents: 24969
diff changeset
157
08148e916d38 Fix an endcase bug: initial_indent was ignored when the text was short
Guido van Rossum <guido@python.org>
parents: 24969
diff changeset
158 text = "This is a short line."
08148e916d38 Fix an endcase bug: initial_indent was ignored when the text was short
Guido van Rossum <guido@python.org>
parents: 24969
diff changeset
159
08148e916d38 Fix an endcase bug: initial_indent was ignored when the text was short
Guido van Rossum <guido@python.org>
parents: 24969
diff changeset
160 self.check_wrap(text, 30, ["This is a short line."])
08148e916d38 Fix an endcase bug: initial_indent was ignored when the text was short
Guido van Rossum <guido@python.org>
parents: 24969
diff changeset
161 self.check_wrap(text, 30, ["(1) This is a short line."],
08148e916d38 Fix an endcase bug: initial_indent was ignored when the text was short
Guido van Rossum <guido@python.org>
parents: 24969
diff changeset
162 initial_indent="(1) ")
08148e916d38 Fix an endcase bug: initial_indent was ignored when the text was short
Guido van Rossum <guido@python.org>
parents: 24969
diff changeset
163
08148e916d38 Fix an endcase bug: initial_indent was ignored when the text was short
Guido van Rossum <guido@python.org>
parents: 24969
diff changeset
164
24946
0c201548d3d4 Conform to standards documented in README:
Greg Ward <gward@python.net>
parents: 24945
diff changeset
165 def test_hyphenated(self):
24962
c1f682beebea Standardize behavior: no docstrings in test functions. Also strip
Guido van Rossum <guido@python.org>
parents: 24958
diff changeset
166 # Test breaking hyphenated words
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
167
24949
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
168 text = ("this-is-a-useful-feature-for-"
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
169 "reformatting-posts-from-tim-peters'ly")
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
170
24949
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
171 self.check_wrap(text, 40,
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
172 ["this-is-a-useful-feature-for-",
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
173 "reformatting-posts-from-tim-peters'ly"])
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
174 self.check_wrap(text, 41,
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
175 ["this-is-a-useful-feature-for-",
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
176 "reformatting-posts-from-tim-peters'ly"])
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
177 self.check_wrap(text, 42,
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
178 ["this-is-a-useful-feature-for-reformatting-",
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
179 "posts-from-tim-peters'ly"])
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
180
34691
0725f0d5a5c7 SF #1149508: ensure textwrap handles hyphenated numbers correctly,
Greg Ward <gward@python.net>
parents: 32538
diff changeset
181 def test_hyphenated_numbers(self):
0725f0d5a5c7 SF #1149508: ensure textwrap handles hyphenated numbers correctly,
Greg Ward <gward@python.net>
parents: 32538
diff changeset
182 # Test that hyphenated numbers (eg. dates) are not broken like words.
0725f0d5a5c7 SF #1149508: ensure textwrap handles hyphenated numbers correctly,
Greg Ward <gward@python.net>
parents: 32538
diff changeset
183 text = ("Python 1.0.0 was released on 1994-01-26. Python 1.0.1 was\n"
0725f0d5a5c7 SF #1149508: ensure textwrap handles hyphenated numbers correctly,
Greg Ward <gward@python.net>
parents: 32538
diff changeset
184 "released on 1994-02-15.")
0725f0d5a5c7 SF #1149508: ensure textwrap handles hyphenated numbers correctly,
Greg Ward <gward@python.net>
parents: 32538
diff changeset
185
50257
e4675113d10e Merged revisions 67654,67676-67677,67681,67692,67725,67746,67748,67761,67784-67785,67787-67788,67802,67832,67848-67849,67859,67862-67864,67880,67882,67885,67889-67892,67895 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 46874
diff changeset
186 self.check_wrap(text, 35, ['Python 1.0.0 was released on',
34691
0725f0d5a5c7 SF #1149508: ensure textwrap handles hyphenated numbers correctly,
Greg Ward <gward@python.net>
parents: 32538
diff changeset
187 '1994-01-26. Python 1.0.1 was',
0725f0d5a5c7 SF #1149508: ensure textwrap handles hyphenated numbers correctly,
Greg Ward <gward@python.net>
parents: 32538
diff changeset
188 'released on 1994-02-15.'])
0725f0d5a5c7 SF #1149508: ensure textwrap handles hyphenated numbers correctly,
Greg Ward <gward@python.net>
parents: 32538
diff changeset
189 self.check_wrap(text, 40, ['Python 1.0.0 was released on 1994-01-26.',
0725f0d5a5c7 SF #1149508: ensure textwrap handles hyphenated numbers correctly,
Greg Ward <gward@python.net>
parents: 32538
diff changeset
190 'Python 1.0.1 was released on 1994-02-15.'])
0725f0d5a5c7 SF #1149508: ensure textwrap handles hyphenated numbers correctly,
Greg Ward <gward@python.net>
parents: 32538
diff changeset
191
0725f0d5a5c7 SF #1149508: ensure textwrap handles hyphenated numbers correctly,
Greg Ward <gward@python.net>
parents: 32538
diff changeset
192 text = "I do all my shopping at 7-11."
0725f0d5a5c7 SF #1149508: ensure textwrap handles hyphenated numbers correctly,
Greg Ward <gward@python.net>
parents: 32538
diff changeset
193 self.check_wrap(text, 25, ["I do all my shopping at",
0725f0d5a5c7 SF #1149508: ensure textwrap handles hyphenated numbers correctly,
Greg Ward <gward@python.net>
parents: 32538
diff changeset
194 "7-11."])
0725f0d5a5c7 SF #1149508: ensure textwrap handles hyphenated numbers correctly,
Greg Ward <gward@python.net>
parents: 32538
diff changeset
195 self.check_wrap(text, 27, ["I do all my shopping at",
0725f0d5a5c7 SF #1149508: ensure textwrap handles hyphenated numbers correctly,
Greg Ward <gward@python.net>
parents: 32538
diff changeset
196 "7-11."])
0725f0d5a5c7 SF #1149508: ensure textwrap handles hyphenated numbers correctly,
Greg Ward <gward@python.net>
parents: 32538
diff changeset
197 self.check_wrap(text, 29, ["I do all my shopping at 7-11."])
0725f0d5a5c7 SF #1149508: ensure textwrap handles hyphenated numbers correctly,
Greg Ward <gward@python.net>
parents: 32538
diff changeset
198
24958
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
199 def test_em_dash(self):
24962
c1f682beebea Standardize behavior: no docstrings in test functions. Also strip
Guido van Rossum <guido@python.org>
parents: 24958
diff changeset
200 # Test text with em-dashes
24958
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
201 text = "Em-dashes should be written -- thus."
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
202 self.check_wrap(text, 25,
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
203 ["Em-dashes should be",
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
204 "written -- thus."])
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
205
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
206 # Probe the boundaries of the properly written em-dash,
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
207 # ie. " -- ".
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
208 self.check_wrap(text, 29,
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
209 ["Em-dashes should be written",
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
210 "-- thus."])
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
211 expect = ["Em-dashes should be written --",
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
212 "thus."]
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
213 self.check_wrap(text, 30, expect)
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
214 self.check_wrap(text, 35, expect)
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
215 self.check_wrap(text, 36,
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
216 ["Em-dashes should be written -- thus."])
24962
c1f682beebea Standardize behavior: no docstrings in test functions. Also strip
Guido van Rossum <guido@python.org>
parents: 24958
diff changeset
217
24958
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
218 # The improperly written em-dash is handled too, because
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
219 # it's adjacent to non-whitespace on both sides.
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
220 text = "You can also do--this or even---this."
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
221 expect = ["You can also do",
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
222 "--this or even",
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
223 "---this."]
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
224 self.check_wrap(text, 15, expect)
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
225 self.check_wrap(text, 16, expect)
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
226 expect = ["You can also do--",
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
227 "this or even---",
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
228 "this."]
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
229 self.check_wrap(text, 17, expect)
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
230 self.check_wrap(text, 19, expect)
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
231 expect = ["You can also do--this or even",
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
232 "---this."]
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
233 self.check_wrap(text, 29, expect)
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
234 self.check_wrap(text, 31, expect)
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
235 expect = ["You can also do--this or even---",
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
236 "this."]
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
237 self.check_wrap(text, 32, expect)
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
238 self.check_wrap(text, 35, expect)
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
239
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
240 # All of the above behaviour could be deduced by probing the
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
241 # _split() method.
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
242 text = "Here's an -- em-dash and--here's another---and another!"
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
243 expect = ["Here's", " ", "an", " ", "--", " ", "em-", "dash", " ",
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
244 "and", "--", "here's", " ", "another", "---",
6e78a54bac3c Add test_em_dash() to WrapTestCase to make sure that TextWrapper handles
Greg Ward <gward@python.net>
parents: 24952
diff changeset
245 "and", " ", "another!"]
25977
1d02b405e31f Ad test_funky_hyphens() to test some screwy edge cases reported in SF
Greg Ward <gward@python.net>
parents: 25534
diff changeset
246 self.check_split(text, expect)
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
247
24969
81679ebec07d Test an em-dash with adjacent punctuation.
Greg Ward <gward@python.net>
parents: 24968
diff changeset
248 text = "and then--bam!--he was gone"
81679ebec07d Test an em-dash with adjacent punctuation.
Greg Ward <gward@python.net>
parents: 24968
diff changeset
249 expect = ["and", " ", "then", "--", "bam!", "--",
81679ebec07d Test an em-dash with adjacent punctuation.
Greg Ward <gward@python.net>
parents: 24968
diff changeset
250 "he", " ", "was", " ", "gone"]
25977
1d02b405e31f Ad test_funky_hyphens() to test some screwy edge cases reported in SF
Greg Ward <gward@python.net>
parents: 25534
diff changeset
251 self.check_split(text, expect)
24969
81679ebec07d Test an em-dash with adjacent punctuation.
Greg Ward <gward@python.net>
parents: 24968
diff changeset
252
81679ebec07d Test an em-dash with adjacent punctuation.
Greg Ward <gward@python.net>
parents: 24968
diff changeset
253
24966
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
254 def test_unix_options (self):
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
255 # Test that Unix-style command-line options are wrapped correctly.
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
256 # Both Optik (OptionParser) and Docutils rely on this behaviour!
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
257
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
258 text = "You should use the -n option, or --dry-run in its long form."
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
259 self.check_wrap(text, 20,
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
260 ["You should use the",
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
261 "-n option, or --dry-",
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
262 "run in its long",
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
263 "form."])
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
264 self.check_wrap(text, 21,
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
265 ["You should use the -n",
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
266 "option, or --dry-run",
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
267 "in its long form."])
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
268 expect = ["You should use the -n option, or",
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
269 "--dry-run in its long form."]
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
270 self.check_wrap(text, 32, expect)
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
271 self.check_wrap(text, 34, expect)
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
272 self.check_wrap(text, 35, expect)
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
273 self.check_wrap(text, 38, expect)
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
274 expect = ["You should use the -n option, or --dry-",
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
275 "run in its long form."]
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
276 self.check_wrap(text, 39, expect)
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
277 self.check_wrap(text, 41, expect)
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
278 expect = ["You should use the -n option, or --dry-run",
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
279 "in its long form."]
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
280 self.check_wrap(text, 42, expect)
c45b28658805 Add test_unix_options() to WrapTestCase to test for SF bug #596434.
Greg Ward <gward@python.net>
parents: 24962
diff changeset
281
24967
80f65c63e860 Test _split() method in test_unix_options().
Greg Ward <gward@python.net>
parents: 24966
diff changeset
282 # Again, all of the above can be deduced from _split().
80f65c63e860 Test _split() method in test_unix_options().
Greg Ward <gward@python.net>
parents: 24966
diff changeset
283 text = "the -n option, or --dry-run or --dryrun"
80f65c63e860 Test _split() method in test_unix_options().
Greg Ward <gward@python.net>
parents: 24966
diff changeset
284 expect = ["the", " ", "-n", " ", "option,", " ", "or", " ",
80f65c63e860 Test _split() method in test_unix_options().
Greg Ward <gward@python.net>
parents: 24966
diff changeset
285 "--dry-", "run", " ", "or", " ", "--dryrun"]
25977
1d02b405e31f Ad test_funky_hyphens() to test some screwy edge cases reported in SF
Greg Ward <gward@python.net>
parents: 25534
diff changeset
286 self.check_split(text, expect)
1d02b405e31f Ad test_funky_hyphens() to test some screwy edge cases reported in SF
Greg Ward <gward@python.net>
parents: 25534
diff changeset
287
1d02b405e31f Ad test_funky_hyphens() to test some screwy edge cases reported in SF
Greg Ward <gward@python.net>
parents: 25534
diff changeset
288 def test_funky_hyphens (self):
1d02b405e31f Ad test_funky_hyphens() to test some screwy edge cases reported in SF
Greg Ward <gward@python.net>
parents: 25534
diff changeset
289 # Screwy edge cases cooked up by David Goodger. All reported
1d02b405e31f Ad test_funky_hyphens() to test some screwy edge cases reported in SF
Greg Ward <gward@python.net>
parents: 25534
diff changeset
290 # in SF bug #596434.
1d02b405e31f Ad test_funky_hyphens() to test some screwy edge cases reported in SF
Greg Ward <gward@python.net>
parents: 25534
diff changeset
291 self.check_split("what the--hey!", ["what", " ", "the", "--", "hey!"])
1d02b405e31f Ad test_funky_hyphens() to test some screwy edge cases reported in SF
Greg Ward <gward@python.net>
parents: 25534
diff changeset
292 self.check_split("what the--", ["what", " ", "the--"])
1d02b405e31f Ad test_funky_hyphens() to test some screwy edge cases reported in SF
Greg Ward <gward@python.net>
parents: 25534
diff changeset
293 self.check_split("what the--.", ["what", " ", "the--."])
1d02b405e31f Ad test_funky_hyphens() to test some screwy edge cases reported in SF
Greg Ward <gward@python.net>
parents: 25534
diff changeset
294 self.check_split("--text--.", ["--text--."])
1d02b405e31f Ad test_funky_hyphens() to test some screwy edge cases reported in SF
Greg Ward <gward@python.net>
parents: 25534
diff changeset
295
29006
f9e6f9fb8df0 SF #596434: add test_funky_parens() to probe some more of the tricky
Greg Ward <gward@python.net>
parents: 29004
diff changeset
296 # When I first read bug #596434, this is what I thought David
f9e6f9fb8df0 SF #596434: add test_funky_parens() to probe some more of the tricky
Greg Ward <gward@python.net>
parents: 29004
diff changeset
297 # was talking about. I was wrong; these have always worked
f9e6f9fb8df0 SF #596434: add test_funky_parens() to probe some more of the tricky
Greg Ward <gward@python.net>
parents: 29004
diff changeset
298 # fine. The real problem is tested in test_funky_parens()
f9e6f9fb8df0 SF #596434: add test_funky_parens() to probe some more of the tricky
Greg Ward <gward@python.net>
parents: 29004
diff changeset
299 # below...
25977
1d02b405e31f Ad test_funky_hyphens() to test some screwy edge cases reported in SF
Greg Ward <gward@python.net>
parents: 25534
diff changeset
300 self.check_split("--option", ["--option"])
1d02b405e31f Ad test_funky_hyphens() to test some screwy edge cases reported in SF
Greg Ward <gward@python.net>
parents: 25534
diff changeset
301 self.check_split("--option-opt", ["--option-", "opt"])
29006
f9e6f9fb8df0 SF #596434: add test_funky_parens() to probe some more of the tricky
Greg Ward <gward@python.net>
parents: 29004
diff changeset
302 self.check_split("foo --option-opt bar",
f9e6f9fb8df0 SF #596434: add test_funky_parens() to probe some more of the tricky
Greg Ward <gward@python.net>
parents: 29004
diff changeset
303 ["foo", " ", "--option-", "opt", " ", "bar"])
f9e6f9fb8df0 SF #596434: add test_funky_parens() to probe some more of the tricky
Greg Ward <gward@python.net>
parents: 29004
diff changeset
304
32210
eb41a489cc2f SF #965425: fix so hyphenated words surrounded by punctuation are
Greg Ward <gward@python.net>
parents: 32088
diff changeset
305 def test_punct_hyphens(self):
eb41a489cc2f SF #965425: fix so hyphenated words surrounded by punctuation are
Greg Ward <gward@python.net>
parents: 32088
diff changeset
306 # Oh bother, SF #965425 found another problem with hyphens --
eb41a489cc2f SF #965425: fix so hyphenated words surrounded by punctuation are
Greg Ward <gward@python.net>
parents: 32088
diff changeset
307 # hyphenated words in single quotes weren't handled correctly.
eb41a489cc2f SF #965425: fix so hyphenated words surrounded by punctuation are
Greg Ward <gward@python.net>
parents: 32088
diff changeset
308 # In fact, the bug is that *any* punctuation around a hyphenated
eb41a489cc2f SF #965425: fix so hyphenated words surrounded by punctuation are
Greg Ward <gward@python.net>
parents: 32088
diff changeset
309 # word was handled incorrectly, except for a leading "--", which
eb41a489cc2f SF #965425: fix so hyphenated words surrounded by punctuation are
Greg Ward <gward@python.net>
parents: 32088
diff changeset
310 # was special-cased for Optik and Docutils. So test a variety
eb41a489cc2f SF #965425: fix so hyphenated words surrounded by punctuation are
Greg Ward <gward@python.net>
parents: 32088
diff changeset
311 # of styles of punctuation around a hyphenated word.
eb41a489cc2f SF #965425: fix so hyphenated words surrounded by punctuation are
Greg Ward <gward@python.net>
parents: 32088
diff changeset
312 # (Actually this is based on an Optik bug report, #813077).
eb41a489cc2f SF #965425: fix so hyphenated words surrounded by punctuation are
Greg Ward <gward@python.net>
parents: 32088
diff changeset
313 self.check_split("the 'wibble-wobble' widget",
eb41a489cc2f SF #965425: fix so hyphenated words surrounded by punctuation are
Greg Ward <gward@python.net>
parents: 32088
diff changeset
314 ['the', ' ', "'wibble-", "wobble'", ' ', 'widget'])
eb41a489cc2f SF #965425: fix so hyphenated words surrounded by punctuation are
Greg Ward <gward@python.net>
parents: 32088
diff changeset
315 self.check_split('the "wibble-wobble" widget',
eb41a489cc2f SF #965425: fix so hyphenated words surrounded by punctuation are
Greg Ward <gward@python.net>
parents: 32088
diff changeset
316 ['the', ' ', '"wibble-', 'wobble"', ' ', 'widget'])
eb41a489cc2f SF #965425: fix so hyphenated words surrounded by punctuation are
Greg Ward <gward@python.net>
parents: 32088
diff changeset
317 self.check_split("the (wibble-wobble) widget",
eb41a489cc2f SF #965425: fix so hyphenated words surrounded by punctuation are
Greg Ward <gward@python.net>
parents: 32088
diff changeset
318 ['the', ' ', "(wibble-", "wobble)", ' ', 'widget'])
eb41a489cc2f SF #965425: fix so hyphenated words surrounded by punctuation are
Greg Ward <gward@python.net>
parents: 32088
diff changeset
319 self.check_split("the ['wibble-wobble'] widget",
eb41a489cc2f SF #965425: fix so hyphenated words surrounded by punctuation are
Greg Ward <gward@python.net>
parents: 32088
diff changeset
320 ['the', ' ', "['wibble-", "wobble']", ' ', 'widget'])
eb41a489cc2f SF #965425: fix so hyphenated words surrounded by punctuation are
Greg Ward <gward@python.net>
parents: 32088
diff changeset
321
29006
f9e6f9fb8df0 SF #596434: add test_funky_parens() to probe some more of the tricky
Greg Ward <gward@python.net>
parents: 29004
diff changeset
322 def test_funky_parens (self):
f9e6f9fb8df0 SF #596434: add test_funky_parens() to probe some more of the tricky
Greg Ward <gward@python.net>
parents: 29004
diff changeset
323 # Second part of SF bug #596434: long option strings inside
f9e6f9fb8df0 SF #596434: add test_funky_parens() to probe some more of the tricky
Greg Ward <gward@python.net>
parents: 29004
diff changeset
324 # parentheses.
f9e6f9fb8df0 SF #596434: add test_funky_parens() to probe some more of the tricky
Greg Ward <gward@python.net>
parents: 29004
diff changeset
325 self.check_split("foo (--option) bar",
f9e6f9fb8df0 SF #596434: add test_funky_parens() to probe some more of the tricky
Greg Ward <gward@python.net>
parents: 29004
diff changeset
326 ["foo", " ", "(--option)", " ", "bar"])
f9e6f9fb8df0 SF #596434: add test_funky_parens() to probe some more of the tricky
Greg Ward <gward@python.net>
parents: 29004
diff changeset
327
f9e6f9fb8df0 SF #596434: add test_funky_parens() to probe some more of the tricky
Greg Ward <gward@python.net>
parents: 29004
diff changeset
328 # Related stuff -- make sure parens work in simpler contexts.
f9e6f9fb8df0 SF #596434: add test_funky_parens() to probe some more of the tricky
Greg Ward <gward@python.net>
parents: 29004
diff changeset
329 self.check_split("foo (bar) baz",
f9e6f9fb8df0 SF #596434: add test_funky_parens() to probe some more of the tricky
Greg Ward <gward@python.net>
parents: 29004
diff changeset
330 ["foo", " ", "(bar)", " ", "baz"])
f9e6f9fb8df0 SF #596434: add test_funky_parens() to probe some more of the tricky
Greg Ward <gward@python.net>
parents: 29004
diff changeset
331 self.check_split("blah (ding dong), wubba",
f9e6f9fb8df0 SF #596434: add test_funky_parens() to probe some more of the tricky
Greg Ward <gward@python.net>
parents: 29004
diff changeset
332 ["blah", " ", "(ding", " ", "dong),",
f9e6f9fb8df0 SF #596434: add test_funky_parens() to probe some more of the tricky
Greg Ward <gward@python.net>
parents: 29004
diff changeset
333 " ", "wubba"])
24967
80f65c63e860 Test _split() method in test_unix_options().
Greg Ward <gward@python.net>
parents: 24966
diff changeset
334
78886
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
335 def test_drop_whitespace_false(self):
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
336 # Check that drop_whitespace=False preserves whitespace.
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
337 # SF patch #1581073
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
338 text = " This is a sentence with much whitespace."
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
339 self.check_wrap(text, 10,
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
340 [" This is a", " ", "sentence ",
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
341 "with ", "much white", "space."],
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
342 drop_whitespace=False)
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
343
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
344 def test_drop_whitespace_false_whitespace_only(self):
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
345 # Check that drop_whitespace=False preserves a whitespace-only string.
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
346 self.check_wrap(" ", 6, [" "], drop_whitespace=False)
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
347
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
348 def test_drop_whitespace_false_whitespace_only_with_indent(self):
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
349 # Check that a whitespace-only string gets indented (when
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
350 # drop_whitespace is False).
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
351 self.check_wrap(" ", 6, [" "], drop_whitespace=False,
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
352 initial_indent=" ")
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
353
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
354 def test_drop_whitespace_whitespace_only(self):
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
355 # Check drop_whitespace on a whitespace-only string.
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
356 self.check_wrap(" ", 6, [])
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
357
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
358 def test_drop_whitespace_leading_whitespace(self):
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
359 # Check that drop_whitespace does not drop leading whitespace (if
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
360 # followed by non-whitespace).
26581
9206b004f152 Added test_initial_whitespace() to ensure that SF bug #622849 is fixed.
Greg Ward <gward@python.net>
parents: 25977
diff changeset
361 # SF bug #622849 reported inconsistent handling of leading
9206b004f152 Added test_initial_whitespace() to ensure that SF bug #622849 is fixed.
Greg Ward <gward@python.net>
parents: 25977
diff changeset
362 # whitespace; let's test that a bit, shall we?
9206b004f152 Added test_initial_whitespace() to ensure that SF bug #622849 is fixed.
Greg Ward <gward@python.net>
parents: 25977
diff changeset
363 text = " This is a sentence with leading whitespace."
9206b004f152 Added test_initial_whitespace() to ensure that SF bug #622849 is fixed.
Greg Ward <gward@python.net>
parents: 25977
diff changeset
364 self.check_wrap(text, 50,
9206b004f152 Added test_initial_whitespace() to ensure that SF bug #622849 is fixed.
Greg Ward <gward@python.net>
parents: 25977
diff changeset
365 [" This is a sentence with leading whitespace."])
9206b004f152 Added test_initial_whitespace() to ensure that SF bug #622849 is fixed.
Greg Ward <gward@python.net>
parents: 25977
diff changeset
366 self.check_wrap(text, 30,
9206b004f152 Added test_initial_whitespace() to ensure that SF bug #622849 is fixed.
Greg Ward <gward@python.net>
parents: 25977
diff changeset
367 [" This is a sentence with", "leading whitespace."])
9206b004f152 Added test_initial_whitespace() to ensure that SF bug #622849 is fixed.
Greg Ward <gward@python.net>
parents: 25977
diff changeset
368
78886
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
369 def test_drop_whitespace_whitespace_line(self):
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
370 # Check that drop_whitespace skips the whole line if a non-leading
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
371 # line consists only of whitespace.
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
372 text = "abcd efgh"
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
373 # Include the result for drop_whitespace=False for comparison.
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
374 self.check_wrap(text, 6, ["abcd", " ", "efgh"],
41158
1d80d84c7792 Patch #1581073: add a flag to textwrap that prevents the dropping of
Georg Brandl <georg@python.org>
parents: 38748
diff changeset
375 drop_whitespace=False)
78886
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
376 self.check_wrap(text, 6, ["abcd", "efgh"])
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
377
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
378 def test_drop_whitespace_whitespace_only_with_indent(self):
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
379 # Check that initial_indent is not applied to a whitespace-only
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
380 # string. This checks a special case of the fact that dropping
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
381 # whitespace occurs before indenting.
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
382 self.check_wrap(" ", 6, [], initial_indent="++")
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
383
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
384 def test_drop_whitespace_whitespace_indent(self):
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
385 # Check that drop_whitespace does not drop whitespace indents.
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
386 # This checks a special case of the fact that dropping whitespace
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
387 # occurs before indenting.
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
388 self.check_wrap("abcd efgh", 6, [" abcd", " efgh"],
fca48971ac35 #15510: clarify textwrap's handling of whitespace, and add confirming tests.
R David Murray <rdmurray@bitdance.com>
parents: 66348
diff changeset
389 initial_indent=" ", subsequent_indent=" ")
41158
1d80d84c7792 Patch #1581073: add a flag to textwrap that prevents the dropping of
Georg Brandl <georg@python.org>
parents: 38748
diff changeset
390
35309
5fe9ceeca111 Disable a few other tests, that can't work if Python is compiled without
Walter Dörwald <walter@livinglogic.de>
parents: 34691
diff changeset
391 if test_support.have_unicode:
5fe9ceeca111 Disable a few other tests, that can't work if Python is compiled without
Walter Dörwald <walter@livinglogic.de>
parents: 34691
diff changeset
392 def test_unicode(self):
5fe9ceeca111 Disable a few other tests, that can't work if Python is compiled without
Walter Dörwald <walter@livinglogic.de>
parents: 34691
diff changeset
393 # *Very* simple test of wrapping Unicode strings. I'm sure
5fe9ceeca111 Disable a few other tests, that can't work if Python is compiled without
Walter Dörwald <walter@livinglogic.de>
parents: 34691
diff changeset
394 # there's more to it than this, but let's at least make
5fe9ceeca111 Disable a few other tests, that can't work if Python is compiled without
Walter Dörwald <walter@livinglogic.de>
parents: 34691
diff changeset
395 # sure textwrap doesn't crash on Unicode input!
5fe9ceeca111 Disable a few other tests, that can't work if Python is compiled without
Walter Dörwald <walter@livinglogic.de>
parents: 34691
diff changeset
396 text = u"Hello there, how are you today?"
5fe9ceeca111 Disable a few other tests, that can't work if Python is compiled without
Walter Dörwald <walter@livinglogic.de>
parents: 34691
diff changeset
397 self.check_wrap(text, 50, [u"Hello there, how are you today?"])
5fe9ceeca111 Disable a few other tests, that can't work if Python is compiled without
Walter Dörwald <walter@livinglogic.de>
parents: 34691
diff changeset
398 self.check_wrap(text, 20, [u"Hello there, how are", "you today?"])
5fe9ceeca111 Disable a few other tests, that can't work if Python is compiled without
Walter Dörwald <walter@livinglogic.de>
parents: 34691
diff changeset
399 olines = self.wrapper.wrap(text)
58472
6ffcdafa0118 use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 50257
diff changeset
400 self.assertIsInstance(olines, list)
6ffcdafa0118 use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 50257
diff changeset
401 self.assertIsInstance(olines[0], unicode)
35309
5fe9ceeca111 Disable a few other tests, that can't work if Python is compiled without
Walter Dörwald <walter@livinglogic.de>
parents: 34691
diff changeset
402 otext = self.wrapper.fill(text)
58472
6ffcdafa0118 use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 50257
diff changeset
403 self.assertIsInstance(otext, unicode)
26582
952687ea9cb1 Add test_unicode() to ensure that 1) textwrap doesn't crash on unicode
Greg Ward <gward@python.net>
parents: 26581
diff changeset
404
50257
e4675113d10e Merged revisions 67654,67676-67677,67681,67692,67725,67746,67748,67761,67784-67785,67787-67788,67802,67832,67848-67849,67859,67862-67864,67880,67882,67885,67889-67892,67895 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 46874
diff changeset
405 def test_no_split_at_umlaut(self):
e4675113d10e Merged revisions 67654,67676-67677,67681,67692,67725,67746,67748,67761,67784-67785,67787-67788,67802,67832,67848-67849,67859,67862-67864,67880,67882,67885,67889-67892,67895 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 46874
diff changeset
406 text = u"Die Empf\xe4nger-Auswahl"
e4675113d10e Merged revisions 67654,67676-67677,67681,67692,67725,67746,67748,67761,67784-67785,67787-67788,67802,67832,67848-67849,67859,67862-67864,67880,67882,67885,67889-67892,67895 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 46874
diff changeset
407 self.check_wrap(text, 13, [u"Die", u"Empf\xe4nger-", u"Auswahl"])
e4675113d10e Merged revisions 67654,67676-67677,67681,67692,67725,67746,67748,67761,67784-67785,67787-67788,67802,67832,67848-67849,67859,67862-67864,67880,67882,67885,67889-67892,67895 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 46874
diff changeset
408
e4675113d10e Merged revisions 67654,67676-67677,67681,67692,67725,67746,67748,67761,67784-67785,67787-67788,67802,67832,67848-67849,67859,67862-67864,67880,67882,67885,67889-67892,67895 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 46874
diff changeset
409 def test_umlaut_followed_by_dash(self):
e4675113d10e Merged revisions 67654,67676-67677,67681,67692,67725,67746,67748,67761,67784-67785,67787-67788,67802,67832,67848-67849,67859,67862-67864,67880,67882,67885,67889-67892,67895 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 46874
diff changeset
410 text = u"aa \xe4\xe4-\xe4\xe4"
e4675113d10e Merged revisions 67654,67676-67677,67681,67692,67725,67746,67748,67761,67784-67785,67787-67788,67802,67832,67848-67849,67859,67862-67864,67880,67882,67885,67889-67892,67895 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 46874
diff changeset
411 self.check_wrap(text, 7, [u"aa \xe4\xe4-", u"\xe4\xe4"])
e4675113d10e Merged revisions 67654,67676-67677,67681,67692,67725,67746,67748,67761,67784-67785,67787-67788,67802,67832,67848-67849,67859,67862-67864,67880,67882,67885,67889-67892,67895 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 46874
diff changeset
412
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
413 def test_split(self):
24962
c1f682beebea Standardize behavior: no docstrings in test functions. Also strip
Guido van Rossum <guido@python.org>
parents: 24958
diff changeset
414 # Ensure that the standard _split() method works as advertised
c1f682beebea Standardize behavior: no docstrings in test functions. Also strip
Guido van Rossum <guido@python.org>
parents: 24958
diff changeset
415 # in the comments
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
416
24949
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
417 text = "Hello there -- you goof-ball, use the -b option!"
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
418
24949
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
419 result = self.wrapper._split(text)
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
420 self.check(result,
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
421 ["Hello", " ", "there", " ", "--", " ", "you", " ", "goof-",
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
422 "ball,", " ", "use", " ", "the", " ", "-b", " ", "option!"])
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
423
46874
c7d1a170c94c #2659: add ``break_on_hyphens`` to TextWrapper.
Georg Brandl <georg@python.org>
parents: 46561
diff changeset
424 def test_break_on_hyphens(self):
c7d1a170c94c #2659: add ``break_on_hyphens`` to TextWrapper.
Georg Brandl <georg@python.org>
parents: 46561
diff changeset
425 # Ensure that the break_on_hyphens attributes work
c7d1a170c94c #2659: add ``break_on_hyphens`` to TextWrapper.
Georg Brandl <georg@python.org>
parents: 46561
diff changeset
426 text = "yaba daba-doo"
c7d1a170c94c #2659: add ``break_on_hyphens`` to TextWrapper.
Georg Brandl <georg@python.org>
parents: 46561
diff changeset
427 self.check_wrap(text, 10, ["yaba daba-", "doo"],
c7d1a170c94c #2659: add ``break_on_hyphens`` to TextWrapper.
Georg Brandl <georg@python.org>
parents: 46561
diff changeset
428 break_on_hyphens=True)
c7d1a170c94c #2659: add ``break_on_hyphens`` to TextWrapper.
Georg Brandl <georg@python.org>
parents: 46561
diff changeset
429 self.check_wrap(text, 10, ["yaba", "daba-doo"],
c7d1a170c94c #2659: add ``break_on_hyphens`` to TextWrapper.
Georg Brandl <georg@python.org>
parents: 46561
diff changeset
430 break_on_hyphens=False)
c7d1a170c94c #2659: add ``break_on_hyphens`` to TextWrapper.
Georg Brandl <georg@python.org>
parents: 46561
diff changeset
431
29004
a07def0dc785 SF #726446: ensure wrap() raises ValueError when width <= 0.
Greg Ward <gward@python.net>
parents: 28917
diff changeset
432 def test_bad_width(self):
a07def0dc785 SF #726446: ensure wrap() raises ValueError when width <= 0.
Greg Ward <gward@python.net>
parents: 28917
diff changeset
433 # Ensure that width <= 0 is caught.
a07def0dc785 SF #726446: ensure wrap() raises ValueError when width <= 0.
Greg Ward <gward@python.net>
parents: 28917
diff changeset
434 text = "Whatever, it doesn't matter."
a07def0dc785 SF #726446: ensure wrap() raises ValueError when width <= 0.
Greg Ward <gward@python.net>
parents: 28917
diff changeset
435 self.assertRaises(ValueError, wrap, text, 0)
a07def0dc785 SF #726446: ensure wrap() raises ValueError when width <= 0.
Greg Ward <gward@python.net>
parents: 28917
diff changeset
436 self.assertRaises(ValueError, wrap, text, -1)
a07def0dc785 SF #726446: ensure wrap() raises ValueError when width <= 0.
Greg Ward <gward@python.net>
parents: 28917
diff changeset
437
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
438
24951
1bcafbc69c96 Factor LongWordTestCase out of WrapTestCase, and rename its methods
Greg Ward <gward@python.net>
parents: 24950
diff changeset
439 class LongWordTestCase (BaseTestCase):
1bcafbc69c96 Factor LongWordTestCase out of WrapTestCase, and rename its methods
Greg Ward <gward@python.net>
parents: 24950
diff changeset
440 def setUp(self):
1bcafbc69c96 Factor LongWordTestCase out of WrapTestCase, and rename its methods
Greg Ward <gward@python.net>
parents: 24950
diff changeset
441 self.wrapper = TextWrapper()
26581
9206b004f152 Added test_initial_whitespace() to ensure that SF bug #622849 is fixed.
Greg Ward <gward@python.net>
parents: 25977
diff changeset
442 self.text = '''\
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
443 Did you say "supercalifragilisticexpialidocious?"
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
444 How *do* you spell that odd word, anyways?
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
445 '''
24951
1bcafbc69c96 Factor LongWordTestCase out of WrapTestCase, and rename its methods
Greg Ward <gward@python.net>
parents: 24950
diff changeset
446
1bcafbc69c96 Factor LongWordTestCase out of WrapTestCase, and rename its methods
Greg Ward <gward@python.net>
parents: 24950
diff changeset
447 def test_break_long(self):
24962
c1f682beebea Standardize behavior: no docstrings in test functions. Also strip
Guido van Rossum <guido@python.org>
parents: 24958
diff changeset
448 # Wrap text with long words and lots of punctuation
24951
1bcafbc69c96 Factor LongWordTestCase out of WrapTestCase, and rename its methods
Greg Ward <gward@python.net>
parents: 24950
diff changeset
449
1bcafbc69c96 Factor LongWordTestCase out of WrapTestCase, and rename its methods
Greg Ward <gward@python.net>
parents: 24950
diff changeset
450 self.check_wrap(self.text, 30,
24949
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
451 ['Did you say "supercalifragilis',
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
452 'ticexpialidocious?" How *do*',
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
453 'you spell that odd word,',
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
454 'anyways?'])
24951
1bcafbc69c96 Factor LongWordTestCase out of WrapTestCase, and rename its methods
Greg Ward <gward@python.net>
parents: 24950
diff changeset
455 self.check_wrap(self.text, 50,
24949
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
456 ['Did you say "supercalifragilisticexpialidocious?"',
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
457 'How *do* you spell that odd word, anyways?'])
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
458
30244
9e3d51bec53a SF bug 797650: Infinite loop in textwrap.py
Raymond Hettinger <python@rcn.com>
parents: 29023
diff changeset
459 # SF bug 797650. Prevent an infinite loop by making sure that at
9e3d51bec53a SF bug 797650: Infinite loop in textwrap.py
Raymond Hettinger <python@rcn.com>
parents: 29023
diff changeset
460 # least one character gets split off on every pass.
9e3d51bec53a SF bug 797650: Infinite loop in textwrap.py
Raymond Hettinger <python@rcn.com>
parents: 29023
diff changeset
461 self.check_wrap('-'*10+'hello', 10,
9e3d51bec53a SF bug 797650: Infinite loop in textwrap.py
Raymond Hettinger <python@rcn.com>
parents: 29023
diff changeset
462 ['----------',
9e3d51bec53a SF bug 797650: Infinite loop in textwrap.py
Raymond Hettinger <python@rcn.com>
parents: 29023
diff changeset
463 ' h',
9e3d51bec53a SF bug 797650: Infinite loop in textwrap.py
Raymond Hettinger <python@rcn.com>
parents: 29023
diff changeset
464 ' e',
9e3d51bec53a SF bug 797650: Infinite loop in textwrap.py
Raymond Hettinger <python@rcn.com>
parents: 29023
diff changeset
465 ' l',
9e3d51bec53a SF bug 797650: Infinite loop in textwrap.py
Raymond Hettinger <python@rcn.com>
parents: 29023
diff changeset
466 ' l',
9e3d51bec53a SF bug 797650: Infinite loop in textwrap.py
Raymond Hettinger <python@rcn.com>
parents: 29023
diff changeset
467 ' o'],
9e3d51bec53a SF bug 797650: Infinite loop in textwrap.py
Raymond Hettinger <python@rcn.com>
parents: 29023
diff changeset
468 subsequent_indent = ' '*15)
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
469
44781
17009d6211b8 Fix #1146: TextWrap vs words 1-character shorter than the width.
Georg Brandl <georg@python.org>
parents: 41158
diff changeset
470 # bug 1146. Prevent a long word to be wrongly wrapped when the
17009d6211b8 Fix #1146: TextWrap vs words 1-character shorter than the width.
Georg Brandl <georg@python.org>
parents: 41158
diff changeset
471 # preceding word is exactly one character shorter than the width
17009d6211b8 Fix #1146: TextWrap vs words 1-character shorter than the width.
Georg Brandl <georg@python.org>
parents: 41158
diff changeset
472 self.check_wrap(self.text, 12,
17009d6211b8 Fix #1146: TextWrap vs words 1-character shorter than the width.
Georg Brandl <georg@python.org>
parents: 41158
diff changeset
473 ['Did you say ',
17009d6211b8 Fix #1146: TextWrap vs words 1-character shorter than the width.
Georg Brandl <georg@python.org>
parents: 41158
diff changeset
474 '"supercalifr',
17009d6211b8 Fix #1146: TextWrap vs words 1-character shorter than the width.
Georg Brandl <georg@python.org>
parents: 41158
diff changeset
475 'agilisticexp',
17009d6211b8 Fix #1146: TextWrap vs words 1-character shorter than the width.
Georg Brandl <georg@python.org>
parents: 41158
diff changeset
476 'ialidocious?',
17009d6211b8 Fix #1146: TextWrap vs words 1-character shorter than the width.
Georg Brandl <georg@python.org>
parents: 41158
diff changeset
477 '" How *do*',
17009d6211b8 Fix #1146: TextWrap vs words 1-character shorter than the width.
Georg Brandl <georg@python.org>
parents: 41158
diff changeset
478 'you spell',
17009d6211b8 Fix #1146: TextWrap vs words 1-character shorter than the width.
Georg Brandl <georg@python.org>
parents: 41158
diff changeset
479 'that odd',
17009d6211b8 Fix #1146: TextWrap vs words 1-character shorter than the width.
Georg Brandl <georg@python.org>
parents: 41158
diff changeset
480 'word,',
17009d6211b8 Fix #1146: TextWrap vs words 1-character shorter than the width.
Georg Brandl <georg@python.org>
parents: 41158
diff changeset
481 'anyways?'])
17009d6211b8 Fix #1146: TextWrap vs words 1-character shorter than the width.
Georg Brandl <georg@python.org>
parents: 41158
diff changeset
482
24962
c1f682beebea Standardize behavior: no docstrings in test functions. Also strip
Guido van Rossum <guido@python.org>
parents: 24958
diff changeset
483 def test_nobreak_long(self):
c1f682beebea Standardize behavior: no docstrings in test functions. Also strip
Guido van Rossum <guido@python.org>
parents: 24958
diff changeset
484 # Test with break_long_words disabled
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
485 self.wrapper.break_long_words = 0
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
486 self.wrapper.width = 30
24949
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
487 expect = ['Did you say',
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
488 '"supercalifragilisticexpialidocious?"',
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
489 'How *do* you spell that odd',
9f26e0c0c692 Ditch the whole loop-over-subcases way of working. Add check_wrap() to
Greg Ward <gward@python.net>
parents: 24948
diff changeset
490 'word, anyways?'
24962
c1f682beebea Standardize behavior: no docstrings in test functions. Also strip
Guido van Rossum <guido@python.org>
parents: 24958
diff changeset
491 ]
24951
1bcafbc69c96 Factor LongWordTestCase out of WrapTestCase, and rename its methods
Greg Ward <gward@python.net>
parents: 24950
diff changeset
492 result = self.wrapper.wrap(self.text)
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
493 self.check(result, expect)
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
494
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
495 # Same thing with kwargs passed to standalone wrap() function.
24951
1bcafbc69c96 Factor LongWordTestCase out of WrapTestCase, and rename its methods
Greg Ward <gward@python.net>
parents: 24950
diff changeset
496 result = wrap(self.text, width=30, break_long_words=0)
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
497 self.check(result, expect)
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
498
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
499
24950
13388cafc16e Rename base test case class to (yawn) BaseTestCase.
Greg Ward <gward@python.net>
parents: 24949
diff changeset
500 class IndentTestCases(BaseTestCase):
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
501
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
502 # called before each test method
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
503 def setUp(self):
24952
6a18b4e838ea Simplification/cleanup in IndentTestCases.
Greg Ward <gward@python.net>
parents: 24951
diff changeset
504 self.text = '''\
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
505 This paragraph will be filled, first without any indentation,
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
506 and then with some (including a hanging indent).'''
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
507
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
508
24946
0c201548d3d4 Conform to standards documented in README:
Greg Ward <gward@python.net>
parents: 24945
diff changeset
509 def test_fill(self):
24962
c1f682beebea Standardize behavior: no docstrings in test functions. Also strip
Guido van Rossum <guido@python.org>
parents: 24958
diff changeset
510 # Test the fill() method
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
511
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
512 expect = '''\
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
513 This paragraph will be filled, first
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
514 without any indentation, and then with
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
515 some (including a hanging indent).'''
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
516
24952
6a18b4e838ea Simplification/cleanup in IndentTestCases.
Greg Ward <gward@python.net>
parents: 24951
diff changeset
517 result = fill(self.text, 40)
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
518 self.check(result, expect)
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
519
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
520
24946
0c201548d3d4 Conform to standards documented in README:
Greg Ward <gward@python.net>
parents: 24945
diff changeset
521 def test_initial_indent(self):
24962
c1f682beebea Standardize behavior: no docstrings in test functions. Also strip
Guido van Rossum <guido@python.org>
parents: 24958
diff changeset
522 # Test initial_indent parameter
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
523
24952
6a18b4e838ea Simplification/cleanup in IndentTestCases.
Greg Ward <gward@python.net>
parents: 24951
diff changeset
524 expect = [" This paragraph will be filled,",
6a18b4e838ea Simplification/cleanup in IndentTestCases.
Greg Ward <gward@python.net>
parents: 24951
diff changeset
525 "first without any indentation, and then",
6a18b4e838ea Simplification/cleanup in IndentTestCases.
Greg Ward <gward@python.net>
parents: 24951
diff changeset
526 "with some (including a hanging indent)."]
6a18b4e838ea Simplification/cleanup in IndentTestCases.
Greg Ward <gward@python.net>
parents: 24951
diff changeset
527 result = wrap(self.text, 40, initial_indent=" ")
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
528 self.check(result, expect)
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
529
24952
6a18b4e838ea Simplification/cleanup in IndentTestCases.
Greg Ward <gward@python.net>
parents: 24951
diff changeset
530 expect = "\n".join(expect)
6a18b4e838ea Simplification/cleanup in IndentTestCases.
Greg Ward <gward@python.net>
parents: 24951
diff changeset
531 result = fill(self.text, 40, initial_indent=" ")
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
532 self.check(result, expect)
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
533
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
534
24946
0c201548d3d4 Conform to standards documented in README:
Greg Ward <gward@python.net>
parents: 24945
diff changeset
535 def test_subsequent_indent(self):
24962
c1f682beebea Standardize behavior: no docstrings in test functions. Also strip
Guido van Rossum <guido@python.org>
parents: 24958
diff changeset
536 # Test subsequent_indent parameter
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
537
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
538 expect = '''\
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
539 * This paragraph will be filled, first
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
540 without any indentation, and then
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
541 with some (including a hanging
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
542 indent).'''
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
543
24952
6a18b4e838ea Simplification/cleanup in IndentTestCases.
Greg Ward <gward@python.net>
parents: 24951
diff changeset
544 result = fill(self.text, 40,
6a18b4e838ea Simplification/cleanup in IndentTestCases.
Greg Ward <gward@python.net>
parents: 24951
diff changeset
545 initial_indent=" * ", subsequent_indent=" ")
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
546 self.check(result, expect)
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
547
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
548
29023
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
549 # Despite the similar names, DedentTestCase is *not* the inverse
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
550 # of IndentTestCase!
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
551 class DedentTestCase(unittest.TestCase):
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
552
38734
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
553 def assertUnchanged(self, text):
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
554 """assert that dedent() has no effect on 'text'"""
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58472
diff changeset
555 self.assertEqual(text, dedent(text))
38734
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
556
29023
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
557 def test_dedent_nomargin(self):
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
558 # No lines indented.
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
559 text = "Hello there.\nHow are you?\nOh good, I'm glad."
38734
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
560 self.assertUnchanged(text)
29023
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
561
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
562 # Similar, with a blank line.
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
563 text = "Hello there.\n\nBoo!"
38734
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
564 self.assertUnchanged(text)
29023
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
565
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
566 # Some lines indented, but overall margin is still zero.
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
567 text = "Hello there.\n This is indented."
38734
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
568 self.assertUnchanged(text)
29023
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
569
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
570 # Again, add a blank line.
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
571 text = "Hello there.\n\n Boo!\n"
38734
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
572 self.assertUnchanged(text)
29023
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
573
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
574 def test_dedent_even(self):
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
575 # All lines indented by two spaces.
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
576 text = " Hello there.\n How are ya?\n Oh good."
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
577 expect = "Hello there.\nHow are ya?\nOh good."
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58472
diff changeset
578 self.assertEqual(expect, dedent(text))
29023
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
579
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
580 # Same, with blank lines.
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
581 text = " Hello there.\n\n How are ya?\n Oh good.\n"
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
582 expect = "Hello there.\n\nHow are ya?\nOh good.\n"
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58472
diff changeset
583 self.assertEqual(expect, dedent(text))
29023
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
584
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
585 # Now indent one of the blank lines.
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
586 text = " Hello there.\n \n How are ya?\n Oh good.\n"
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
587 expect = "Hello there.\n\nHow are ya?\nOh good.\n"
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58472
diff changeset
588 self.assertEqual(expect, dedent(text))
29023
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
589
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
590 def test_dedent_uneven(self):
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
591 # Lines indented unevenly.
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
592 text = '''\
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
593 def foo():
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
594 while 1:
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
595 return foo
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
596 '''
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
597 expect = '''\
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
598 def foo():
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
599 while 1:
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
600 return foo
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
601 '''
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58472
diff changeset
602 self.assertEqual(expect, dedent(text))
29023
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
603
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
604 # Uneven indentation with a blank line.
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
605 text = " Foo\n Bar\n\n Baz\n"
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
606 expect = "Foo\n Bar\n\n Baz\n"
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58472
diff changeset
607 self.assertEqual(expect, dedent(text))
29023
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
608
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
609 # Uneven indentation with a whitespace-only line.
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
610 text = " Foo\n Bar\n \n Baz\n"
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
611 expect = "Foo\n Bar\n\n Baz\n"
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58472
diff changeset
612 self.assertEqual(expect, dedent(text))
38734
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
613
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
614 # dedent() should not mangle internal tabs
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
615 def test_dedent_preserve_internal_tabs(self):
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
616 text = " hello\tthere\n how are\tyou?"
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
617 expect = "hello\tthere\nhow are\tyou?"
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58472
diff changeset
618 self.assertEqual(expect, dedent(text))
38734
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
619
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
620 # make sure that it preserves tabs when it's not making any
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
621 # changes at all
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58472
diff changeset
622 self.assertEqual(expect, dedent(expect))
38734
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
623
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
624 # dedent() should not mangle tabs in the margin (i.e.
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
625 # tabs and spaces both count as margin, but are *not*
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
626 # considered equivalent)
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
627 def test_dedent_preserve_margin_tabs(self):
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
628 text = " hello there\n\thow are you?"
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
629 self.assertUnchanged(text)
29023
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
630
38734
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
631 # same effect even if we have 8 spaces
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
632 text = " hello there\n\thow are you?"
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
633 self.assertUnchanged(text)
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
634
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
635 # dedent() only removes whitespace that can be uniformly removed!
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
636 text = "\thello there\n\thow are you?"
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
637 expect = "hello there\nhow are you?"
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58472
diff changeset
638 self.assertEqual(expect, dedent(text))
38734
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
639
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
640 text = " \thello there\n \thow are you?"
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58472
diff changeset
641 self.assertEqual(expect, dedent(text))
38734
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
642
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
643 text = " \t hello there\n \t how are you?"
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58472
diff changeset
644 self.assertEqual(expect, dedent(text))
38748
b50ab288ae27 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 38734
diff changeset
645
38734
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
646 text = " \thello there\n \t how are you?"
9d8478f732d5 Bug #1361643: fix textwrap.dedent() so it handles tabs appropriately,
Greg Ward <gward@python.net>
parents: 35309
diff changeset
647 expect = "hello there\n how are you?"
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58472
diff changeset
648 self.assertEqual(expect, dedent(text))
29023
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
649
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
650
24946
0c201548d3d4 Conform to standards documented in README:
Greg Ward <gward@python.net>
parents: 24945
diff changeset
651 def test_main():
29023
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
652 test_support.run_unittest(WrapTestCase,
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
653 LongWordTestCase,
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
654 IndentTestCases,
cb832c2cd54d Add DedentTestCase to test dedent() function.
Greg Ward <gward@python.net>
parents: 29006
diff changeset
655 DedentTestCase)
24946
0c201548d3d4 Conform to standards documented in README:
Greg Ward <gward@python.net>
parents: 24945
diff changeset
656
24945
7417a6dc7366 Test script for the textwrap module. Kindly provided by Peter Hansen
Greg Ward <gward@python.net>
parents:
diff changeset
657 if __name__ == '__main__':
24946
0c201548d3d4 Conform to standards documented in README:
Greg Ward <gward@python.net>
parents: 24945
diff changeset
658 test_main()