[Python-checkins] python/dist/src/Lib/test test_textwrap.py,1.4,1.5

gward@users.sourceforge.net gward@users.sourceforge.net
Thu, 22 Aug 2002 11:55:41 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv14594

Modified Files:
	test_textwrap.py 
Log Message:
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'.


Index: test_textwrap.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_textwrap.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** test_textwrap.py	22 Aug 2002 18:45:02 -0000	1.4
--- test_textwrap.py	22 Aug 2002 18:55:38 -0000	1.5
***************
*** 34,37 ****
--- 34,41 ----
                  self.show(result), self.show(expect)))
  
+     def check_wrap (self, text, width, expect):
+         result = wrap(text, width)
+         self.check(result, expect)
+ 
  
  class WrapTestCase(WrapperTestCase):
***************
*** 43,63 ****
          '''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]),
!             ]
  
!         for width, expect in subcases:
!             result = wrap(t, width)
!             self.check(result, expect)
  
  
--- 47,63 ----
          '''Simple case: just words, spaces, and a bit of punctuation.'''
  
!         text = "Hello there, how are you this fine day?  I'm glad to hear it!"
  
!         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])
  
  
***************
*** 65,69 ****
          '''Whitespace munging and end-of-sentence detection.'''
  
!         t = """\
  This is a paragraph that already has
  line breaks.  But some of its lines are much longer than the others,
--- 65,69 ----
          '''Whitespace munging and end-of-sentence detection.'''
  
!         text = """\
  This is a paragraph that already has
  line breaks.  But some of its lines are much longer than the others,
***************
*** 73,88 ****
  """
  
!         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)
          self.check(result, expect)
  
!         result = self.wrapper.fill(t)
          self.check(result, '\n'.join(expect))
  
--- 73,86 ----
  """
  
!         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(text)
          self.check(result, '\n'.join(expect))
  
***************
*** 91,105 ****
          '''Wrapping to make short lines longer.'''
  
!         t = "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)
  
  
--- 89,97 ----
          '''Wrapping to make short lines longer.'''
  
!         text = "This is a\nshort paragraph."
  
!         self.check_wrap(text, 20, ["This is a short",
!                                    "paragraph."])
!         self.check_wrap(text, 40, ["This is a short paragraph."])
  
  
***************
*** 107,124 ****
          '''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"]),
!             ]
  
!         for width, expect in subcases:
!             result = wrap(t, width)
!             self.check(result, expect)
  
  
--- 99,114 ----
          '''Test breaking hyphenated words.'''
  
!         text = ("this-is-a-useful-feature-for-"
!                 "reformatting-posts-from-tim-peters'ly")
  
!         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"])
  
  
***************
*** 127,133 ****
             in the comments.'''
  
!         t = "Hello there -- you goof-ball, use the -b option!"
  
!         result = self.wrapper._split(t)
          self.check(result,
               ["Hello", " ", "there", " ", "--", " ", "you", " ", "goof-",
--- 117,123 ----
             in the comments.'''
  
!         text = "Hello there -- you goof-ball, use the -b option!"
  
!         result = self.wrapper._split(text)
          self.check(result,
               ["Hello", " ", "there", " ", "--", " ", "you", " ", "goof-",
***************
*** 138,162 ****
          '''Wrap text with long words and lots of punctuation.'''
  
!         t = '''
  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)
  
  
      def test_long_words(self):        
          '''Test with break_long_words disabled.'''
!         t = '''
  Did you say "supercalifragilisticexpialidocious?"
  How *do* you spell that odd word, anyways?
--- 128,148 ----
          '''Wrap text with long words and lots of punctuation.'''
  
!         text = '''
  Did you say "supercalifragilisticexpialidocious?"
  How *do* you spell that odd word, anyways?
  '''
!         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.'''
!         text = '''
  Did you say "supercalifragilisticexpialidocious?"
  How *do* you spell that odd word, anyways?
***************
*** 164,178 ****
          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?'
!                 ] 
          self.check(result, expect)
  
          # Same thing with kwargs passed to standalone wrap() function.
!         result = wrap(t, width=30, break_long_words=0)
          self.check(result, expect)
  
--- 150,163 ----
          self.wrapper.break_long_words = 0
          self.wrapper.width = 30
!         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(text, width=30, break_long_words=0)
          self.check(result, expect)