summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGreg Ward <gward@python.net>2002-08-22 18:55:38 (GMT)
committerGreg Ward <gward@python.net>2002-08-22 18:55:38 (GMT)
commitee413849b5015117b3f5c08e3447ee4c619b3dc1 (patch)
treec17bfeb3b9872a484f7c81a5694912e5549d871b /Lib
parent9ebba9ace31ce0027d8f487a853bda7c2e1661cc (diff)
downloadcpython-ee413849b5015117b3f5c08e3447ee4c619b3dc1.zip
cpython-ee413849b5015117b3f5c08e3447ee4c619b3dc1.tar.gz
cpython-ee413849b5015117b3f5c08e3447ee4c619b3dc1.tar.bz2
Ditch the whole loop-over-subcases way of working. Add check_wrap() to
base class (WrapperTestCase) instead, and call it repeatedly in the methods that used to have a loop-over-subcases. Much simpler. Rename perennial temp variable 't' to 'text'.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_textwrap.py133
1 files changed, 59 insertions, 74 deletions
diff --git a/Lib/test/test_textwrap.py b/Lib/test/test_textwrap.py
index cb63387..3e51193 100644
--- a/Lib/test/test_textwrap.py
+++ b/Lib/test/test_textwrap.py
@@ -33,6 +33,10 @@ class WrapperTestCase(unittest.TestCase):
'Expected:\n%s\nbut got:\n%s' % (
self.show(result), self.show(expect)))
+ def check_wrap (self, text, width, expect):
+ result = wrap(text, width)
+ self.check(result, expect)
+
class WrapTestCase(WrapperTestCase):
@@ -42,29 +46,25 @@ class WrapTestCase(WrapperTestCase):
def test_simple(self):
'''Simple case: just words, spaces, and a bit of punctuation.'''
- t = "Hello there, how are you this fine day? I'm glad to hear it!"
-
- subcases = [
- (12, ["Hello there,",
- "how are you",
- "this fine",
- "day? I'm",
- "glad to hear",
- "it!"]),
- (42, ["Hello there, how are you this fine day?",
- "I'm glad to hear it!"]),
- (80, [t]),
- ]
+ text = "Hello there, how are you this fine day? I'm glad to hear it!"
- for width, expect in subcases:
- result = wrap(t, width)
- self.check(result, expect)
+ self.check_wrap(text, 12,
+ ["Hello there,",
+ "how are you",
+ "this fine",
+ "day? I'm",
+ "glad to hear",
+ "it!"])
+ self.check_wrap(text, 42,
+ ["Hello there, how are you this fine day?",
+ "I'm glad to hear it!"])
+ self.check_wrap(text, 80, [text])
def test_whitespace(self):
'''Whitespace munging and end-of-sentence detection.'''
- t = """\
+ text = """\
This is a paragraph that already has
line breaks. But some of its lines are much longer than the others,
so it needs to be wrapped.
@@ -72,63 +72,53 @@ Some lines are \ttabbed too.
What a mess!
"""
- expect = [
- "This is a paragraph that already has line",
- "breaks. But some of its lines are much",
- "longer than the others, so it needs to be",
- "wrapped. Some lines are tabbed too. What a",
- "mess!"
- ]
-
- result = self.wrapper.wrap(t)
+ expect = ["This is a paragraph that already has line",
+ "breaks. But some of its lines are much",
+ "longer than the others, so it needs to be",
+ "wrapped. Some lines are tabbed too. What a",
+ "mess!"]
+
+ result = self.wrapper.wrap(text)
self.check(result, expect)
- result = self.wrapper.fill(t)
+ result = self.wrapper.fill(text)
self.check(result, '\n'.join(expect))
def test_wrap_short(self):
'''Wrapping to make short lines longer.'''
- t = "This is a\nshort paragraph."
+ text = "This is a\nshort paragraph."
- subcases = [
- (20, ["This is a short",
- "paragraph."]),
- (40, ["This is a short paragraph."]),
- ]
-
- for width, expect in subcases:
- result = wrap(t, width)
- self.check(result, expect)
+ self.check_wrap(text, 20, ["This is a short",
+ "paragraph."])
+ self.check_wrap(text, 40, ["This is a short paragraph."])
def test_hyphenated(self):
'''Test breaking hyphenated words.'''
- t = "this-is-a-useful-feature-for-reformatting-posts-from-tim-peters'ly"
-
- subcases = [
- (40, ["this-is-a-useful-feature-for-",
- "reformatting-posts-from-tim-peters'ly"]),
- (41, ["this-is-a-useful-feature-for-",
- "reformatting-posts-from-tim-peters'ly"]),
- (42, ["this-is-a-useful-feature-for-reformatting-",
- "posts-from-tim-peters'ly"]),
- ]
+ text = ("this-is-a-useful-feature-for-"
+ "reformatting-posts-from-tim-peters'ly")
- for width, expect in subcases:
- result = wrap(t, width)
- self.check(result, expect)
+ self.check_wrap(text, 40,
+ ["this-is-a-useful-feature-for-",
+ "reformatting-posts-from-tim-peters'ly"])
+ self.check_wrap(text, 41,
+ ["this-is-a-useful-feature-for-",
+ "reformatting-posts-from-tim-peters'ly"])
+ self.check_wrap(text, 42,
+ ["this-is-a-useful-feature-for-reformatting-",
+ "posts-from-tim-peters'ly"])
def test_split(self):
'''Ensure that the standard _split() method works as advertised
in the comments.'''
- t = "Hello there -- you goof-ball, use the -b option!"
+ text = "Hello there -- you goof-ball, use the -b option!"
- result = self.wrapper._split(t)
+ result = self.wrapper._split(text)
self.check(result,
["Hello", " ", "there", " ", "--", " ", "you", " ", "goof-",
"ball,", " ", "use", " ", "the", " ", "-b", " ", "option!"])
@@ -137,43 +127,38 @@ What a mess!
def test_funky_punc(self):
'''Wrap text with long words and lots of punctuation.'''
- t = '''
+ text = '''
Did you say "supercalifragilisticexpialidocious?"
How *do* you spell that odd word, anyways?
'''
- subcases = [
- (30, ['Did you say "supercalifragilis',
- 'ticexpialidocious?" How *do*',
- 'you spell that odd word,',
- 'anyways?']),
- (50, ['Did you say "supercalifragilisticexpialidocious?"',
- 'How *do* you spell that odd word, anyways?']),
- ]
-
- for width, expect in subcases:
- result = wrap(t, width)
- self.check(result, expect)
+ self.check_wrap(text, 30,
+ ['Did you say "supercalifragilis',
+ 'ticexpialidocious?" How *do*',
+ 'you spell that odd word,',
+ 'anyways?'])
+ self.check_wrap(text, 50,
+ ['Did you say "supercalifragilisticexpialidocious?"',
+ 'How *do* you spell that odd word, anyways?'])
def test_long_words(self):
'''Test with break_long_words disabled.'''
- t = '''
+ text = '''
Did you say "supercalifragilisticexpialidocious?"
How *do* you spell that odd word, anyways?
'''
self.wrapper.break_long_words = 0
self.wrapper.width = 30
- result = self.wrapper.wrap(t)
- expect = [
- 'Did you say',
- '"supercalifragilisticexpialidocious?"',
- 'How *do* you spell that odd',
- 'word, anyways?'
- ]
+ expect = ['Did you say',
+ '"supercalifragilisticexpialidocious?"',
+ 'How *do* you spell that odd',
+ 'word, anyways?'
+ ]
+ result = self.wrapper.wrap(text)
self.check(result, expect)
# Same thing with kwargs passed to standalone wrap() function.
- result = wrap(t, width=30, break_long_words=0)
+ result = wrap(text, width=30, break_long_words=0)
self.check(result, expect)