[Python-checkins] python/dist/src/Lib/test test_textwrap.py,1.21,1.22
gward@users.sourceforge.net
gward@users.sourceforge.net
Wed, 07 May 2003 18:58:28 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv32729
Modified Files:
test_textwrap.py
Log Message:
Add DedentTestCase to test dedent() function.
Index: test_textwrap.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_textwrap.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** test_textwrap.py 7 May 2003 01:19:22 -0000 1.21
--- test_textwrap.py 8 May 2003 01:58:26 -0000 1.22
***************
*** 12,16 ****
from test import test_support
! from textwrap import TextWrapper, wrap, fill
--- 12,16 ----
from test import test_support
! from textwrap import TextWrapper, wrap, fill, dedent
***************
*** 324,328 ****
-
class IndentTestCases(BaseTestCase):
--- 324,327 ----
***************
*** 374,379 ****
def test_main():
! test_support.run_unittest(WrapTestCase, LongWordTestCase, IndentTestCases)
if __name__ == '__main__':
--- 373,444 ----
+ # Despite the similar names, DedentTestCase is *not* the inverse
+ # of IndentTestCase!
+ class DedentTestCase(unittest.TestCase):
+
+ def test_dedent_nomargin(self):
+ # No lines indented.
+ text = "Hello there.\nHow are you?\nOh good, I'm glad."
+ self.assertEquals(dedent(text), text)
+
+ # Similar, with a blank line.
+ text = "Hello there.\n\nBoo!"
+ self.assertEquals(dedent(text), text)
+
+ # Some lines indented, but overall margin is still zero.
+ text = "Hello there.\n This is indented."
+ self.assertEquals(dedent(text), text)
+
+ # Again, add a blank line.
+ text = "Hello there.\n\n Boo!\n"
+ self.assertEquals(dedent(text), text)
+
+ def test_dedent_even(self):
+ # All lines indented by two spaces.
+ text = " Hello there.\n How are ya?\n Oh good."
+ expect = "Hello there.\nHow are ya?\nOh good."
+ self.assertEquals(dedent(text), expect)
+
+ # Same, with blank lines.
+ text = " Hello there.\n\n How are ya?\n Oh good.\n"
+ expect = "Hello there.\n\nHow are ya?\nOh good.\n"
+ self.assertEquals(dedent(text), expect)
+
+ # Now indent one of the blank lines.
+ text = " Hello there.\n \n How are ya?\n Oh good.\n"
+ expect = "Hello there.\n\nHow are ya?\nOh good.\n"
+ self.assertEquals(dedent(text), expect)
+
+ def test_dedent_uneven(self):
+ # Lines indented unevenly.
+ text = '''\
+ def foo():
+ while 1:
+ return foo
+ '''
+ expect = '''\
+ def foo():
+ while 1:
+ return foo
+ '''
+ self.assertEquals(dedent(text), expect)
+
+ # Uneven indentation with a blank line.
+ text = " Foo\n Bar\n\n Baz\n"
+ expect = "Foo\n Bar\n\n Baz\n"
+ self.assertEquals(dedent(text), expect)
+
+ # Uneven indentation with a whitespace-only line.
+ text = " Foo\n Bar\n \n Baz\n"
+ expect = "Foo\n Bar\n\n Baz\n"
+ self.assertEquals(dedent(text), expect)
+
+
+
def test_main():
! test_support.run_unittest(WrapTestCase,
! LongWordTestCase,
! IndentTestCases,
! DedentTestCase)
if __name__ == '__main__':