def testUnwrapMixedQuoted( self ):
     flow = flowtext.parser()
     testText = ( "This line is \n" +
         "quoted and has a couple of soft \n" +
         "breaks in it.\n\n" +
         ">This line is also \n" + 
         ">quoted and has an \n" + 
         ">example of embaressing wrap\n")
     expectedText = ( "This line is " +
         "quoted and has a couple of soft " +
         "breaks in it.\n\n" +
         ">This line is also " + 
         "quoted and has an " + 
         "example of embaressing wrap\n")
     debug = False
     if(debug):
         print "\n---------------------------\ninput text\n"
         print testText
     outputText = flow.unwrap( testText, debug ) 
     if(debug):
         print "\n---------------------------\nExpected text\n"
         print expectedText
         print "\n---------------------------\noutput text\n"
         print outputText
     self.assertEqual( expectedText, outputText )
 def testUnwrapIllegalQuoteChange( self ):
     flow = flowtext.parser()
     testText = ( ">>This line is quoted \n"
                 ">>to a depth of 2 \n"
                 ">but this line it wraps to is only 1 and fixed\n"
                 ">>>This line is quoted to \n"
                 ">>>a depth of 3 \n"
                 ">>but this line it wraps to \n"
                 ">>is flowed and quoted to a \n"
                 ">>depth of 2.\n")
     expectedText = ( ">>This line is quoted to a depth of 2\n"
                 ">but this line it wraps to is only 1 and fixed\n"
                 ">>>This line is quoted to a depth of 3\n"
                 ">>but this line it wraps to is flowed and quoted to a "
                 "depth of 2.\n" )
     debug = False
     if(debug):
         print "\n---------------------------\ninput text\n"
         print testText
     outputText = flow.unwrap( testText, debug ) 
     if(debug):
         print "\n---------------------------\nExpected text\n"
         print expectedText
         print "\n---------------------------\noutput text\n"
         print outputText
     self.assertEqual( expectedText, outputText )
 def testUnwrapUsenetSignature(self):
     flow = flowtext.parser()
     testText = ( "This line is \n"
         "quoted and has a couple of soft \n"
         "breaks in it.\n\n"
         ">This line is also \n" 
         ">quoted and has an \n"
         ">example of embaressing wrap\n"
         "-- \n" 
         "And this is a usenet signature\n")
     expectedText = ( "This line is "
         "quoted and has a couple of soft "
         "breaks in it.\n\n"
         ">This line is also "
         "quoted and has an "
         "example of embaressing wrap\n"
         "-- \n"
         "And this is a usenet signature\n")
     debug = False
     if(debug):
         print "\n---------------------------\ninput text\n"
         print testText
     outputText = flow.unwrap( testText, debug ) 
     if(debug):
         print "\n---------------------------\nExpected text\n"
         print expectedText
         print "\n---------------------------\noutput text\n"
         print outputText
     self.assertEqual( expectedText, outputText )       
 def testSetMaxWidth( self ):
     flow = flowtext.parser()
     flow.setMaxWidth( 40 )
     self.assertEqual( 40, flow.getMaxWidth() )
     def setOverWide():
         flow.setMaxWidth( 99 )
     self.assertRaises( ValueError, setOverWide )
 def testUnwrapQuotedWithSoftWrapAndQuoted(self):
     flow = flowtext.parser()
     testText = ( ">This line is \n" +
         "quoted and has a couple of soft \n" +
         ">breaks in it.\n")
     expectedText = ( ">This line is " +
         "quoted and has a couple of soft " +
         "breaks in it.\n")
     self.assertEqual( expectedText, flow.unwrap( testText ) )
 def testStandardiseNewlines(self):
     flow = flowtext.parser()
     testText = ("This is a basic newline\n" + 
                 "And another type\r" + 
                 "And another\n\r" + 
                 "And yet another\r\n")
     expectedText = ("This is a basic newline\n" + 
                 "And another type\n" + 
                 "And another\n" + 
                 "And yet another\n")
     self.assertEqual( expectedText, flow.standardiseNewlines(testText))
    def testUnwrapTwoParagraphs( self ):
        flow = flowtext.parser()
        testText = ( "This line spans a few \n" +
            "lines and has a couple of soft \n" +
            "breaks in it.\n\n" + 
            "and sneakily has a second \n" + 
            "paragraph\n" )
        expectedText = ( "This line spans a few " + 
            "lines and has a couple of soft " +
            "breaks in it.\n\n" +
            "and sneakily has a second " + 
            "paragraph\n" )

        self.assertEqual( expectedText, flow.unwrap( testText ) )
    def testUnwrapTwoGTQuotedLines( self ):
        flow = flowtext.parser()
        testText = ( ">This line is \n" +
            ">quoted and has a couple of soft \n" +
            ">breaks in it.\n\n" +
            ">This line is also \n" + 
            ">quoted\n" )
        expectedText = ( ">This line is " +
            "quoted and has a couple of soft " +
            "breaks in it.\n\n" +
            ">This line is also " + 
            "quoted\n" )

        self.assertEqual( expectedText, flow.unwrap( testText ) )
 def testUnwrapMixedNormalAndQuoted( self ):
     flow = flowtext.parser()
     testText = ( ">This line is \n" +
         ">quoted and has a couple of soft \n" +
         ">breaks in it.\n\n" +
         "This line is not \n" + 
         "quoted\n" )
     expectedText = ( ">This line is " +
         "quoted and has a couple of soft " +
         "breaks in it.\n\n" +
         "This line is not " + 
         "quoted\n" )
         
     self.assertEqual( expectedText, flow.unwrap( testText ) )
 def testGenerateMessage(self):
     flow = flowtext.parser()
     msg = flow.generateMessage(">This line is very, very long \nindeed and will go on and on and on "
         "and will be over 66 characters long hopefully \nforcing the wrapping "
         "mechanism into action. Of course we then \nneed to investigate real word "
         "boundary wrapping, not merely character \nsplitting\n")
     expectedText = (">This line is very, very long indeed and will go on and on and on \n"
         ">and will be over 66 characters long hopefully forcing the \n"
         ">wrapping mechanism into action. Of course we then need to \n"
         ">investigate real word boundary wrapping, not merely character \n"
         ">splitting\n" )
     
     self.assertEqual(msg.get_content_type(), "text/plain")
     self.assertEqual(msg.get_param("format"), "flowed")
     self.assertEqual(msg.get_payload(), expectedText)
 def testUnwrapEndingWithCr(self):
     flow = flowtext.parser()
     testText = ( "This line ends with a CR which should be untouched\n")
     expectedText = ( "This line ends with a CR which should be untouched\n")
     debug = False
     if(debug):
         print "\n---------------------------\ninput text\n"
         print testText
     outputText = flow.unwrap( testText, debug ) 
     if(debug):
         print "\n---------------------------\nExpected text\n"
         print expectedText
         print "\n---------------------------\noutput text\n"
         print outputText
     self.assertEqual( expectedText, outputText )
    def testASimpleUnwrapQuotedWithGt( self ):
        flow = flowtext.parser()
        testText = ( ">This line is \n>quoted\n" )
        expectedText = ( ">This line is quoted\n" )
        debug = False
        if(debug):
            print "\n---------------------------\ninput text\n"
            print testText
        outputText = flow.unwrap( testText, debug ) 
        if(debug):
            print "\n---------------------------\nExpected text\n"
            print expectedText
            print "\n---------------------------\noutput text\n"
            print outputText

        self.assertEqual( expectedText, outputText )
    def testNegativeUnwrap( self ):
        flow = flowtext.parser()
        testText = ( "This line spans a few \n" +
            "lines and has a couple of soft \n" +
            "breaks in it. \n" )
        debug = False
        if(debug):
            print "\n---------------------------\ninput text\n"
            print testText
        outputText = flow.unwrap( testText, debug ) 
        if(debug):
            print "\n---------------------------\nExpected text\n"
            print expectedText            
            print "\n---------------------------\noutput text\n"
            print outputText

        self.assertNotEqual( testText, outputText )    
    def testParsesMessage(self):
        flow = flowtext.parser()
        msg = Message()
        def test():
            flow.parseMessage(msg)
        self.assertRaises(ValueError, test)

        msg = flow.generateMessage(">This line is very, very long \nindeed and will go on and on and on "
            "and will be over 66 characters long hopefully \nforcing the wrapping "
            "mechanism into action. Of course we then \nneed to investigate real word "
            "boundary wrapping, not merely character \nsplitting\n")
        expectedText = (">This line is very, very long indeed and will go on and on and on \n"
            ">and will be over 66 characters long hopefully forcing the \n"
            ">wrapping mechanism into action. Of course we then need to \n"
            ">investigate real word boundary wrapping, not merely character \n"
            ">splitting\n" )
        
        self.assertEqual(flow.parseMessage(msg), expectedText)
    def testUnwrapSpaceStuffed(self):
        flow = flowtext.parser()
        testText = ( " >This is a special line, and although it is more than 66 characters, \n"
            " it is space stuffed, and therefore the > should be ignored\n" )
        expectedText = (" >This is a special line, and although it is more than 66 characters, "
            "it is space stuffed, and therefore the > should be ignored\n" )
        debug = False
        if(debug):
            print "\n---------------------------\ninput text\n"
            print testText
        outputText = flow.unwrap( testText, debug ) 
        if(debug):
            print "\n---------------------------\nExpected text\n"
            print expectedText
            print "\n---------------------------\noutput text\n"
            print outputText

        self.assertEqual( expectedText, outputText )        
    def testWrapLongestLine(self):
        flow = flowtext.parser()
        testText = ( "ThisIsAllOneWordAndWillNotBeWrappedThislineisvery,verylongindeedandwillgoonandonandon"
            "andwillbeover66characterslonghopefullyforcingthewrapping"
            "mechanismintoaction.Ofcoursewethenneedtoinvestigaterealword"
            "boundarywrapping,notmerelycharactersplitting\n" )
        expectedText = testText
        debug = False
        if(debug):
            print "\n---------------------------\ninput text\n"
            print testText
        outputText = flow.wrap( testText, debug ) 
        if(debug):
            print "\n---------------------------\nExpected text\n"
            print expectedText
            print "\n---------------------------\noutput text\n"
            print outputText

        self.assertEqual( expectedText, outputText )        
 def testWrapQuotedLongQuote(self):
     flow = flowtext.parser()
     testText = ( ">>>>>This line is very, very long indeed and will go on and on and on "
         "and will be over 66 characters long hopefully forcing the wrapping "
         "mechanism into action. Of course we then need to investigate real word "
         "boundary wrapping, not merely character splitting\n" )
     expectedText = (">>>>>This line is very, very long indeed and will go on and on \n"
         ">>>>>and on and will be over 66 characters long hopefully forcing \n"
         ">>>>>the wrapping mechanism into action. Of course we then need \n"
         ">>>>>to investigate real word boundary wrapping, not merely \n"
         ">>>>>character splitting\n" )
     debug = False
     if(debug):
         print "\n---------------------------\ninput text\n"
         print testText
     outputText = flow.wrap( testText, debug ) 
     if(debug):
         print "\n---------------------------\nExpected text\n"
         print expectedText
         print "\n---------------------------\noutput text\n"
         print outputText
 def testUnwrapAll( self ):
     flow = flowtext.parser()
     testText = ( "This line spans a few \n"
         "lines and has a couple of soft \n"
         "breaks in it. It also has a very, very long line which spans a little "
         "too long and therefore needs to be well wrapped.\n"
         "\nAfter which there is a new paragraph. This new paragraph has only "
         "one long line\n"
         " And now an indented (therefore space stuffed) section \n"
         " which also spans a few lines, with soft line breaks (using the space "
         "then crlf convention)\n\n"
         ">Another quoted test using the greater than sign \n"
         ">but its otherwise nothing special.\n\n"
         ">And here I am going to give a soft break \n"
         ">>And change the quoting depth - this is an illegal operation\n" )
     expectedText = ( "This line spans a few "
         "lines and has a couple of soft "
         "breaks in it. It also has a very, very long line which spans a little "
         "too long and therefore needs to be well wrapped.\n"
         "\nAfter which there is a new paragraph. This new paragraph has only "
         "one long line\n"
         " And now an indented (therefore space stuffed) section "
         "which also spans a few lines, with soft line breaks (using the space "
         "then crlf convention)\n\n"
         ">Another quoted test using the greater than sign "
         "but its otherwise nothing special.\n\n"
         ">And here I am going to give a soft break\n"
         ">>And change the quoting depth - this is an illegal operation\n" )
     debug = False
     if(debug):
         print "\n---------------------------\ninput text\n"
         print testText
     outputText = flow.unwrap( testText, debug ) 
     if(debug):
         print "\n---------------------------\nExpected text\n"
         print expectedText
         print "\n---------------------------\noutput text\n"
         print outputText
     self.assertEqual( expectedText, outputText )
    def testPrepare(self):
        flow = flowtext.parser()
        testText = ( "This small document needs to be space stuffed\n"
                    ">It contains this line which is not quoted\n"
                    " And this line with an intentional space\n"
                    "From here to infinity\n" )
        expectedText = ("This small document needs to be space stuffed\n"
                    " >It contains this line which is not quoted\n"
                    "  And this line with an intentional space\n"
                    " From here to infinity\n"  )
        debug = False
        if(debug):
            print "\n---------------------------\ninput text\n"
            print testText
        outputText = flow.prepNonQuotedText( testText, debug ) 
        if(debug):
            print "\n---------------------------\nExpected text\n"
            print expectedText
            print "\n---------------------------\noutput text\n"
            print outputText

        self.assertEqual( expectedText, outputText )
    def testFlow79(self):
        flow = flowtext.parser(79)
        testText = ( ">This line is very, very long \nindeed and will go on and on and on "
            "and will be over 79 characters long hopefully \nforcing the wrapping "
            "mechanism into action. Of course we then \nneed to investigate real word "
            "boundary wrapping, not merely character \nsplitting\n" )
        expectedText = (">This line is very, very long indeed and will go on and on and on and will be \n"
            ">over 79 characters long hopefully forcing the wrapping mechanism into action. \n"
            ">Of course we then need to investigate real word boundary wrapping, not merely \n"
            ">character splitting\n" )
        debug = False
        if(debug):
            print "\n---------------------------\ninput text\n"
            print testText
        outputText = flow.flow( testText, debug ) 
        if(debug):
            print "\n---------------------------\nExpected text\n"
            print expectedText
            print "\n---------------------------\noutput text\n"
            print outputText

        self.assertEqual( expectedText, outputText )
 def testConstruction( self ):
     flow = flowtext.parser()
     self.assertEqual( 66, flow.getMaxWidth() )
     #Try constructing again
     flow = flowtext.parser( 23 )
     self.assertEqual( 23, flow.getMaxWidth() )
 def setUp( self ):
     self.flow = flowtext.parser()