Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/test/test_textwrap.py

    r2 r391  
    66# Currently maintained by Greg Ward.
    77#
    8 # $Id: test_textwrap.py 67896 2008-12-21 17:01:26Z benjamin.peterson $
     8# $Id$
    99#
    1010
     
    3030
    3131    def check(self, result, expect):
    32         self.assertEquals(result, expect,
     32        self.assertEqual(result, expect,
    3333            'expected:\n%s\nbut got:\n%s' % (
    3434                self.show(expect), self.show(result)))
     
    4040    def check_split(self, text, expect):
    4141        result = self.wrapper._split(text)
    42         self.assertEquals(result, expect,
    43                           "\nexpected %r\n"
    44                           "but got  %r" % (expect, result))
     42        self.assertEqual(result, expect,
     43                         "\nexpected %r\n"
     44                         "but got  %r" % (expect, result))
    4545
    4646
     
    6767        self.check_wrap(text, 80, [text])
    6868
     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)
    6978
    7079    def test_whitespace(self):
     
    324333                          " ", "wubba"])
    325334
    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).
    327361        # SF bug #622849 reported inconsistent handling of leading
    328362        # whitespace; let's test that a bit, shall we?
     
    333367                        [" This is a sentence with", "leading whitespace."])
    334368
    335     def test_no_drop_whitespace(self):
    336         # SF patch #1581073
    337         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"],
    341375                        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="  ")
    342390
    343391    if test_support.have_unicode:
     
    350398            self.check_wrap(text, 20, [u"Hello there, how are", "you today?"])
    351399            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)
    353402            otext = self.wrapper.fill(text)
    354             assert isinstance(otext, unicode)
     403            self.assertIsInstance(otext, unicode)
    355404
    356405        def test_no_split_at_umlaut(self):
     
    504553    def assertUnchanged(self, text):
    505554        """assert that dedent() has no effect on 'text'"""
    506         self.assertEquals(text, dedent(text))
     555        self.assertEqual(text, dedent(text))
    507556
    508557    def test_dedent_nomargin(self):
     
    527576        text = "  Hello there.\n  How are ya?\n  Oh good."
    528577        expect = "Hello there.\nHow are ya?\nOh good."
    529         self.assertEquals(expect, dedent(text))
     578        self.assertEqual(expect, dedent(text))
    530579
    531580        # Same, with blank lines.
    532581        text = "  Hello there.\n\n  How are ya?\n  Oh good.\n"
    533582        expect = "Hello there.\n\nHow are ya?\nOh good.\n"
    534         self.assertEquals(expect, dedent(text))
     583        self.assertEqual(expect, dedent(text))
    535584
    536585        # Now indent one of the blank lines.
    537586        text = "  Hello there.\n  \n  How are ya?\n  Oh good.\n"
    538587        expect = "Hello there.\n\nHow are ya?\nOh good.\n"
    539         self.assertEquals(expect, dedent(text))
     588        self.assertEqual(expect, dedent(text))
    540589
    541590    def test_dedent_uneven(self):
     
    551600        return foo
    552601'''
    553         self.assertEquals(expect, dedent(text))
     602        self.assertEqual(expect, dedent(text))
    554603
    555604        # Uneven indentation with a blank line.
    556605        text = "  Foo\n    Bar\n\n   Baz\n"
    557606        expect = "Foo\n  Bar\n\n Baz\n"
    558         self.assertEquals(expect, dedent(text))
     607        self.assertEqual(expect, dedent(text))
    559608
    560609        # Uneven indentation with a whitespace-only line.
    561610        text = "  Foo\n    Bar\n \n   Baz\n"
    562611        expect = "Foo\n  Bar\n\n Baz\n"
    563         self.assertEquals(expect, dedent(text))
     612        self.assertEqual(expect, dedent(text))
    564613
    565614    # dedent() should not mangle internal tabs
     
    567616        text = "  hello\tthere\n  how are\tyou?"
    568617        expect = "hello\tthere\nhow are\tyou?"
    569         self.assertEquals(expect, dedent(text))
     618        self.assertEqual(expect, dedent(text))
    570619
    571620        # make sure that it preserves tabs when it's not making any
    572621        # changes at all
    573         self.assertEquals(expect, dedent(expect))
     622        self.assertEqual(expect, dedent(expect))
    574623
    575624    # dedent() should not mangle tabs in the margin (i.e.
     
    587636        text = "\thello there\n\thow are you?"
    588637        expect = "hello there\nhow are you?"
    589         self.assertEquals(expect, dedent(text))
     638        self.assertEqual(expect, dedent(text))
    590639
    591640        text = "  \thello there\n  \thow are you?"
    592         self.assertEquals(expect, dedent(text))
     641        self.assertEqual(expect, dedent(text))
    593642
    594643        text = "  \t  hello there\n  \t  how are you?"
    595         self.assertEquals(expect, dedent(text))
     644        self.assertEqual(expect, dedent(text))
    596645
    597646        text = "  \thello there\n  \t  how are you?"
    598647        expect = "hello there\n  how are you?"
    599         self.assertEquals(expect, dedent(text))
     648        self.assertEqual(expect, dedent(text))
    600649
    601650
Note: See TracChangeset for help on using the changeset viewer.