<s> import unittest <EOL> from test import test_support <EOL> import py <EOL> textwrap = py . compat . textwrap <EOL> TextWrapper = textwrap . TextWrapper <EOL> wrap = textwrap . wrap <EOL> fill = textwrap . fill <EOL> dedent = textwrap . dedent <EOL> class BaseTestCase ( unittest . TestCase ) : <EOL> '''<STR_LIT>''' <EOL> def show ( self , textin ) : <EOL> if isinstance ( textin , list ) : <EOL> result = [ ] <EOL> for i in range ( len ( textin ) ) : <EOL> result . append ( "<STR_LIT>" % ( i , textin [ i ] ) ) <EOL> result = '<STR_LIT:\n>' . join ( result ) <EOL> elif isinstance ( textin , basestring ) : <EOL> result = "<STR_LIT>" % repr ( textin ) <EOL> return result <EOL> def check ( self , result , expect ) : <EOL> self . assertEquals ( result , expect , <EOL> '<STR_LIT>' % ( <EOL> self . show ( expect ) , self . show ( result ) ) ) <EOL> def check_wrap ( self , text , width , expect , ** kwargs ) : <EOL> result = wrap ( text , width , ** kwargs ) <EOL> self . check ( result , expect ) <EOL> def check_split ( self , text , expect ) : <EOL> result = self . wrapper . _split ( text ) <EOL> self . assertEquals ( result , expect , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( expect , result ) ) <EOL> class WrapTestCase ( BaseTestCase ) : <EOL> def setUp ( self ) : <EOL> self . wrapper = TextWrapper ( width = <NUM_LIT> ) <EOL> def test_simple ( self ) : <EOL> text = "<STR_LIT>" <EOL> self . check_wrap ( text , <NUM_LIT:12> , <EOL> [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> self . check_wrap ( text , <NUM_LIT> , <EOL> [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> self . check_wrap ( text , <NUM_LIT> , [ text ] ) <EOL> def test_whitespace ( self ) : <EOL> text = """<STR_LIT>""" <EOL> expect = [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> wrapper = TextWrapper ( <NUM_LIT> , fix_sentence_endings = True ) <EOL> result = wrapper . wrap ( text ) <EOL> self . check ( result , expect ) <EOL> result = wrapper . fill ( text ) <EOL> self . check ( result , '<STR_LIT:\n>' . join ( expect ) ) <EOL> def test_fix_sentence_endings ( self ) : <EOL> wrapper = TextWrapper ( <NUM_LIT> , fix_sentence_endings = True ) <EOL> text = "<STR_LIT>" <EOL> expect = [ "<STR_LIT>" ] <EOL> self . check ( wrapper . wrap ( text ) , expect ) <EOL> text = "<STR_LIT>" <EOL> expect = [ "<STR_LIT>" ] <EOL> self . check ( wrapper . wrap ( text ) , expect ) <EOL> text = "<STR_LIT>" <EOL> self . check ( wrapper . wrap ( text ) , expect ) <EOL> text = '<STR_LIT>' <EOL> expect = [ '<STR_LIT>' ] <EOL> self . check ( wrapper . wrap ( text ) , expect ) <EOL> wrapper . width = <NUM_LIT:20> <EOL> expect = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . check ( wrapper . wrap ( text ) , expect ) <EOL> text = '<STR_LIT>' <EOL> expect = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> self . check ( wrapper . wrap ( text ) , expect ) <EOL> wrapper . width = <NUM_LIT> <EOL> expect = [ '<STR_LIT>' ] <EOL> self . check ( wrapper . wrap ( text ) , expect ) <EOL> def test_wrap_short ( self ) : <EOL> text = "<STR_LIT>" <EOL> self . check_wrap ( text , <NUM_LIT:20> , [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> self . check_wrap ( text , <NUM_LIT> , [ "<STR_LIT>" ] ) <EOL> def test_wrap_short_1line ( self ) : <EOL> text = "<STR_LIT>" <EOL> self . check_wrap ( text , <NUM_LIT:30> , [ "<STR_LIT>" ] ) <EOL> self . check_wrap ( text , <NUM_LIT:30> , [ "<STR_LIT>" ] , <EOL> initial_indent = "<STR_LIT>" ) <EOL> def test_hyphenated ( self ) : <EOL> text = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . check_wrap ( text , <NUM_LIT> , <EOL> [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> self . check_wrap ( text , <NUM_LIT> , <EOL> [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> self . check_wrap ( text , <NUM_LIT> , <EOL> [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> def test_hyphenated_numbers ( self ) : <EOL> text = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . check_wrap ( text , <NUM_LIT:30> , [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> self . check_wrap ( text , <NUM_LIT> , [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> text = "<STR_LIT>" <EOL> self . check_wrap ( text , <NUM_LIT> , [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> self . check_wrap ( text , <NUM_LIT> , [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> self . check_wrap ( text , <NUM_LIT> , [ "<STR_LIT>" ] ) <EOL> def test_em_dash ( self ) : <EOL> text = "<STR_LIT>" <EOL> self . check_wrap ( text , <NUM_LIT> , <EOL> [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> self . check_wrap ( text , <NUM_LIT> , <EOL> [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> expect = [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> self . check_wrap ( text , <NUM_LIT:30> , expect ) <EOL> self . check_wrap ( text , <NUM_LIT> , expect ) <EOL> self . check_wrap ( text , <NUM_LIT> , <EOL> [ "<STR_LIT>" ] ) <EOL> text = "<STR_LIT>" <EOL> expect = [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> self . check_wrap ( text , <NUM_LIT:15> , expect ) <EOL> self . check_wrap ( text , <NUM_LIT:16> , expect ) <EOL> expect = [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> self . check_wrap ( text , <NUM_LIT> , expect ) <EOL> self . check_wrap ( text , <NUM_LIT> , expect ) <EOL> expect = [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> self . check_wrap ( text , <NUM_LIT> , expect ) <EOL> self . check_wrap ( text , <NUM_LIT> , expect ) <EOL> expect = [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> self . check_wrap ( text , <NUM_LIT:32> , expect ) <EOL> self . check_wrap ( text , <NUM_LIT> , expect ) <EOL> text = "<STR_LIT>" <EOL> expect = [ "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:U+0020>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" ] <EOL> self . check_split ( text , expect ) <EOL> text = "<STR_LIT>" <EOL> expect = [ "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" ] <EOL> self . check_split ( text , expect ) <EOL> def test_unix_options ( self ) : <EOL> text = "<STR_LIT>" <EOL> self . check_wrap ( text , <NUM_LIT:20> , <EOL> [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> self . check_wrap ( text , <NUM_LIT> , <EOL> [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> expect = [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> self . check_wrap ( text , <NUM_LIT:32> , expect ) <EOL> self . check_wrap ( text , <NUM_LIT> , expect ) <EOL> self . check_wrap ( text , <NUM_LIT> , expect ) <EOL> self . check_wrap ( text , <NUM_LIT> , expect ) <EOL> expect = [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> self . check_wrap ( text , <NUM_LIT> , expect ) <EOL> self . check_wrap ( text , <NUM_LIT> , expect ) <EOL> expect = [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> self . check_wrap ( text , <NUM_LIT> , expect ) <EOL> text = "<STR_LIT>" <EOL> expect = [ "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , "<STR_LIT:U+0020>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" ] <EOL> self . check_split ( text , expect ) <EOL> def test_funky_hyphens ( self ) : <EOL> self . check_split ( "<STR_LIT>" , [ "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . check_split ( "<STR_LIT>" , [ "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" ] ) <EOL> self . check_split ( "<STR_LIT>" , [ "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" ] ) <EOL> self . check_split ( "<STR_LIT>" , [ "<STR_LIT>" ] ) <EOL> self . check_split ( "<STR_LIT>" , [ "<STR_LIT>" ] ) <EOL> self . check_split ( "<STR_LIT>" , [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . check_split ( "<STR_LIT>" , <EOL> [ "<STR_LIT:foo>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT:bar>" ] ) <EOL> def test_punct_hyphens ( self ) : <EOL> self . check_split ( "<STR_LIT>" , <EOL> [ '<STR_LIT>' , '<STR_LIT:U+0020>' , "<STR_LIT>" , "<STR_LIT>" , '<STR_LIT:U+0020>' , '<STR_LIT>' ] ) <EOL> self . check_split ( '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT:U+0020>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:U+0020>' , '<STR_LIT>' ] ) <EOL> self . check_split ( "<STR_LIT>" , <EOL> [ '<STR_LIT>' , '<STR_LIT:U+0020>' , "<STR_LIT>" , "<STR_LIT>" , '<STR_LIT:U+0020>' , '<STR_LIT>' ] ) <EOL> self . check_split ( "<STR_LIT>" , <EOL> [ '<STR_LIT>' , '<STR_LIT:U+0020>' , "<STR_LIT>" , "<STR_LIT>" , '<STR_LIT:U+0020>' , '<STR_LIT>' ] ) <EOL> def test_funky_parens ( self ) : <EOL> self . check_split ( "<STR_LIT>" , <EOL> [ "<STR_LIT:foo>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT:bar>" ] ) <EOL> self . check_split ( "<STR_LIT>" , <EOL> [ "<STR_LIT:foo>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" ] ) <EOL> self . check_split ( "<STR_LIT>" , <EOL> [ "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , <EOL> "<STR_LIT:U+0020>" , "<STR_LIT>" ] ) <EOL> def test_initial_whitespace ( self ) : <EOL> text = "<STR_LIT>" <EOL> self . check_wrap ( text , <NUM_LIT:50> , <EOL> [ "<STR_LIT>" ] ) <EOL> self . check_wrap ( text , <NUM_LIT:30> , <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> def test_unicode ( self ) : <EOL> text = u"<STR_LIT>" <EOL> self . check_wrap ( text , <NUM_LIT:50> , [ u"<STR_LIT>" ] ) <EOL> self . check_wrap ( text , <NUM_LIT:20> , [ u"<STR_LIT>" , "<STR_LIT>" ] ) <EOL> olines = self . wrapper . wrap ( text ) <EOL> assert isinstance ( olines , list ) and isinstance ( olines [ <NUM_LIT:0> ] , unicode ) <EOL> otext = self . wrapper . fill ( text ) <EOL> assert isinstance ( otext , unicode ) <EOL> def test_split ( self ) : <EOL> text = "<STR_LIT>" <EOL> result = self . wrapper . _split ( text ) <EOL> self . check ( result , <EOL> [ "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" , "<STR_LIT:U+0020>" , "<STR_LIT>" ] ) <EOL> def test_bad_width ( self ) : <EOL> text = "<STR_LIT>" <EOL> self . assertRaises ( ValueError , wrap , text , <NUM_LIT:0> ) <EOL> self . assertRaises ( ValueError , wrap , text , - <NUM_LIT:1> ) <EOL> class LongWordTestCase ( BaseTestCase ) : <EOL> def setUp ( self ) : <EOL> self . wrapper = TextWrapper ( ) <EOL> self . text = '''<STR_LIT>''' <EOL> def test_break_long ( self ) : <EOL> self . check_wrap ( self . text , <NUM_LIT:30> , <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> self . check_wrap ( self . text , <NUM_LIT:50> , <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> self . check_wrap ( '<STR_LIT:->' * <NUM_LIT:10> + '<STR_LIT:hello>' , <NUM_LIT:10> , <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> subsequent_indent = '<STR_LIT:U+0020>' * <NUM_LIT:15> ) <EOL> def test_nobreak_long ( self ) : <EOL> self . wrapper . break_long_words = <NUM_LIT:0> <EOL> self . wrapper . width = <NUM_LIT:30> <EOL> expect = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> result = self . wrapper . wrap ( self . text ) <EOL> self . check ( result , expect ) <EOL> result = wrap ( self . text , width = <NUM_LIT:30> , break_long_words = <NUM_LIT:0> ) <EOL> self . check ( result , expect ) <EOL> class IndentTestCases ( BaseTestCase ) : <EOL> def setUp ( self ) : <EOL> self . text = '''<STR_LIT>''' <EOL> def test_fill ( self ) : <EOL> expect = '''<STR_LIT>''' <EOL> result = fill ( self . text , <NUM_LIT> ) <EOL> self . check ( result , expect ) <EOL> def test_initial_indent ( self ) : <EOL> expect = [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> result = wrap ( self . text , <NUM_LIT> , initial_indent = "<STR_LIT:U+0020>" ) <EOL> self . check ( result , expect ) <EOL> expect = "<STR_LIT:\n>" . join ( expect ) <EOL> result = fill ( self . text , <NUM_LIT> , initial_indent = "<STR_LIT:U+0020>" ) <EOL> self . check ( result , expect ) <EOL> def test_subsequent_indent ( self ) : <EOL> expect = '''<STR_LIT>''' <EOL> result = fill ( self . text , <NUM_LIT> , <EOL> initial_indent = "<STR_LIT>" , subsequent_indent = "<STR_LIT:U+0020>" ) <EOL> self . check ( result , expect ) <EOL> class DedentTestCase ( unittest . TestCase ) : <EOL> def test_dedent_nomargin ( self ) : <EOL> text = "<STR_LIT>" <EOL> self . assertEquals ( dedent ( text ) , text ) <EOL> text = "<STR_LIT>" <EOL> self . assertEquals ( dedent ( text ) , text ) <EOL> text = "<STR_LIT>" <EOL> self . assertEquals ( dedent ( text ) , text ) <EOL> text = "<STR_LIT>" <EOL> self . assertEquals ( dedent ( text ) , text ) <EOL> def test_dedent_even ( self ) : <EOL> text = "<STR_LIT>" <EOL> expect = "<STR_LIT>" <EOL> self . assertEquals ( dedent ( text ) , expect ) <EOL> text = "<STR_LIT>" <EOL> expect = "<STR_LIT>" <EOL> self . assertEquals ( dedent ( text ) , expect ) <EOL> text = "<STR_LIT>" <EOL> expect = "<STR_LIT>" <EOL> self . assertEquals ( dedent ( text ) , expect ) <EOL> def test_dedent_uneven ( self ) : <EOL> text = '''<STR_LIT>''' <EOL> expect = '''<STR_LIT>''' <EOL> self . assertEquals ( dedent ( text ) , expect ) <EOL> text = "<STR_LIT>" <EOL> expect = "<STR_LIT>" <EOL> self . assertEquals ( dedent ( text ) , expect ) <EOL> text = "<STR_LIT>" <EOL> expect = "<STR_LIT>" <EOL> self . assertEquals ( dedent ( text ) , expect ) <EOL> def test_main ( ) : <EOL> test_support . run_unittest ( WrapTestCase , <EOL> LongWordTestCase , <EOL> IndentTestCases , <EOL> DedentTestCase ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> test_main ( ) </s>
