Changeset 391 for python/trunk/Lib/test/test_textwrap.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/test/test_textwrap.py
r2 r391 6 6 # Currently maintained by Greg Ward. 7 7 # 8 # $Id : test_textwrap.py 67896 2008-12-21 17:01:26Z benjamin.peterson$8 # $Id$ 9 9 # 10 10 … … 30 30 31 31 def check(self, result, expect): 32 self.assertEqual s(result, expect,32 self.assertEqual(result, expect, 33 33 'expected:\n%s\nbut got:\n%s' % ( 34 34 self.show(expect), self.show(result))) … … 40 40 def check_split(self, text, expect): 41 41 result = self.wrapper._split(text) 42 self.assertEqual s(result, expect,43 44 42 self.assertEqual(result, expect, 43 "\nexpected %r\n" 44 "but got %r" % (expect, result)) 45 45 46 46 … … 67 67 self.check_wrap(text, 80, [text]) 68 68 69 def test_empty_string(self): 70 # Check that wrapping the empty string returns an empty list. 71 self.check_wrap("", 6, []) 72 self.check_wrap("", 6, [], drop_whitespace=False) 73 74 def test_empty_string_with_initial_indent(self): 75 # Check that the empty string is not indented. 76 self.check_wrap("", 6, [], initial_indent="++") 77 self.check_wrap("", 6, [], initial_indent="++", drop_whitespace=False) 69 78 70 79 def test_whitespace(self): … … 324 333 " ", "wubba"]) 325 334 326 def test_initial_whitespace(self): 335 def test_drop_whitespace_false(self): 336 # Check that drop_whitespace=False preserves whitespace. 337 # SF patch #1581073 338 text = " This is a sentence with much whitespace." 339 self.check_wrap(text, 10, 340 [" This is a", " ", "sentence ", 341 "with ", "much white", "space."], 342 drop_whitespace=False) 343 344 def test_drop_whitespace_false_whitespace_only(self): 345 # Check that drop_whitespace=False preserves a whitespace-only string. 346 self.check_wrap(" ", 6, [" "], drop_whitespace=False) 347 348 def test_drop_whitespace_false_whitespace_only_with_indent(self): 349 # Check that a whitespace-only string gets indented (when 350 # drop_whitespace is False). 351 self.check_wrap(" ", 6, [" "], drop_whitespace=False, 352 initial_indent=" ") 353 354 def test_drop_whitespace_whitespace_only(self): 355 # Check drop_whitespace on a whitespace-only string. 356 self.check_wrap(" ", 6, []) 357 358 def test_drop_whitespace_leading_whitespace(self): 359 # Check that drop_whitespace does not drop leading whitespace (if 360 # followed by non-whitespace). 327 361 # SF bug #622849 reported inconsistent handling of leading 328 362 # whitespace; let's test that a bit, shall we? … … 333 367 [" This is a sentence with", "leading whitespace."]) 334 368 335 def test_ no_drop_whitespace(self):336 # SF patch #1581073337 text = " This is a sentence with much whitespace."338 self.check_wrap(text, 10,339 [" This is a", " ", "sentence ",340 "with ", "much white", "space."],369 def test_drop_whitespace_whitespace_line(self): 370 # Check that drop_whitespace skips the whole line if a non-leading 371 # line consists only of whitespace. 372 text = "abcd efgh" 373 # Include the result for drop_whitespace=False for comparison. 374 self.check_wrap(text, 6, ["abcd", " ", "efgh"], 341 375 drop_whitespace=False) 376 self.check_wrap(text, 6, ["abcd", "efgh"]) 377 378 def test_drop_whitespace_whitespace_only_with_indent(self): 379 # Check that initial_indent is not applied to a whitespace-only 380 # string. This checks a special case of the fact that dropping 381 # whitespace occurs before indenting. 382 self.check_wrap(" ", 6, [], initial_indent="++") 383 384 def test_drop_whitespace_whitespace_indent(self): 385 # Check that drop_whitespace does not drop whitespace indents. 386 # This checks a special case of the fact that dropping whitespace 387 # occurs before indenting. 388 self.check_wrap("abcd efgh", 6, [" abcd", " efgh"], 389 initial_indent=" ", subsequent_indent=" ") 342 390 343 391 if test_support.have_unicode: … … 350 398 self.check_wrap(text, 20, [u"Hello there, how are", "you today?"]) 351 399 olines = self.wrapper.wrap(text) 352 assert isinstance(olines, list) and isinstance(olines[0], unicode) 400 self.assertIsInstance(olines, list) 401 self.assertIsInstance(olines[0], unicode) 353 402 otext = self.wrapper.fill(text) 354 assert isinstance(otext, unicode)403 self.assertIsInstance(otext, unicode) 355 404 356 405 def test_no_split_at_umlaut(self): … … 504 553 def assertUnchanged(self, text): 505 554 """assert that dedent() has no effect on 'text'""" 506 self.assertEqual s(text, dedent(text))555 self.assertEqual(text, dedent(text)) 507 556 508 557 def test_dedent_nomargin(self): … … 527 576 text = " Hello there.\n How are ya?\n Oh good." 528 577 expect = "Hello there.\nHow are ya?\nOh good." 529 self.assertEqual s(expect, dedent(text))578 self.assertEqual(expect, dedent(text)) 530 579 531 580 # Same, with blank lines. 532 581 text = " Hello there.\n\n How are ya?\n Oh good.\n" 533 582 expect = "Hello there.\n\nHow are ya?\nOh good.\n" 534 self.assertEqual s(expect, dedent(text))583 self.assertEqual(expect, dedent(text)) 535 584 536 585 # Now indent one of the blank lines. 537 586 text = " Hello there.\n \n How are ya?\n Oh good.\n" 538 587 expect = "Hello there.\n\nHow are ya?\nOh good.\n" 539 self.assertEqual s(expect, dedent(text))588 self.assertEqual(expect, dedent(text)) 540 589 541 590 def test_dedent_uneven(self): … … 551 600 return foo 552 601 ''' 553 self.assertEqual s(expect, dedent(text))602 self.assertEqual(expect, dedent(text)) 554 603 555 604 # Uneven indentation with a blank line. 556 605 text = " Foo\n Bar\n\n Baz\n" 557 606 expect = "Foo\n Bar\n\n Baz\n" 558 self.assertEqual s(expect, dedent(text))607 self.assertEqual(expect, dedent(text)) 559 608 560 609 # Uneven indentation with a whitespace-only line. 561 610 text = " Foo\n Bar\n \n Baz\n" 562 611 expect = "Foo\n Bar\n\n Baz\n" 563 self.assertEqual s(expect, dedent(text))612 self.assertEqual(expect, dedent(text)) 564 613 565 614 # dedent() should not mangle internal tabs … … 567 616 text = " hello\tthere\n how are\tyou?" 568 617 expect = "hello\tthere\nhow are\tyou?" 569 self.assertEqual s(expect, dedent(text))618 self.assertEqual(expect, dedent(text)) 570 619 571 620 # make sure that it preserves tabs when it's not making any 572 621 # changes at all 573 self.assertEqual s(expect, dedent(expect))622 self.assertEqual(expect, dedent(expect)) 574 623 575 624 # dedent() should not mangle tabs in the margin (i.e. … … 587 636 text = "\thello there\n\thow are you?" 588 637 expect = "hello there\nhow are you?" 589 self.assertEqual s(expect, dedent(text))638 self.assertEqual(expect, dedent(text)) 590 639 591 640 text = " \thello there\n \thow are you?" 592 self.assertEqual s(expect, dedent(text))641 self.assertEqual(expect, dedent(text)) 593 642 594 643 text = " \t hello there\n \t how are you?" 595 self.assertEqual s(expect, dedent(text))644 self.assertEqual(expect, dedent(text)) 596 645 597 646 text = " \thello there\n \t how are you?" 598 647 expect = "hello there\n how are you?" 599 self.assertEqual s(expect, dedent(text))648 self.assertEqual(expect, dedent(text)) 600 649 601 650
Note:
See TracChangeset
for help on using the changeset viewer.