def testConvertXmlReportToTextSummary( self ): MomBuildMockupTestCase.setUp( self, useScm = True ) # enable SCM self._executeBuild() converter = XmlReportConverter( self._getXmlReport() ) text = converter.convertToTextSummary() self.assertTrue( len( text ) > 100 )
def testConvertXmlReportToHtmlWithoutLxml( self ): # write a new method implementation def hasXsltSupport_new( self ): return False converter = XmlReportConverter( self._getXmlReport() ) replace_bound_method( converter, converter.hasXsltSupport, hasXsltSupport_new ) # replace method xmlString = converter.convertToHtml() self.assertTrue( xmlString == None, "If no XSLT support is available, converting to HTML should not work" )
def report( self ): if self.isReportSent(): return report = InstructionsXmlReport( self.getInstructions() ) converter = XmlReportConverter( report ) print( " " ) print( converter.convertToTextSummary().encode( "utf-8" ) ) print( converter.convertToText().encode( "utf-8" ) ) print( " " ) # empty line self._setIsReportSent( True )
def testXmlReportOnStepFailure( self ): self._executeBuild() def failed_new( self ): return Step.Result.Failure step = self.project.getStep( 'cleanup' ) replace_bound_method( step, step.getResult, failed_new ) converter = XmlReportConverter( self._getXmlReport() ) logText = converter.convertToFailedStepsLog() self.assertTrue( "cleanup" in logText )
def testXmlReportOnExceptionInXmlReportGeneration( self ): # inject invalid XML template function into plugin def command_new( self ): raise MomError( "Test Error" ) logger = ConsoleLogger() self.build.addPlugin( logger ) replace_bound_method( logger, logger.getObjectStatus, command_new ) self._executeBuild() converter = XmlReportConverter( self._getXmlReport() ) text = converter.convertToText() self.assertTrue( "Exception" in text )
def testXmlReportOnUnicodeOutput( self ): # inject plugin producing unicode strings class TestPlugin( Plugin ): def setup( self ): raise MomError( u"äöü" ) self.build.addPlugin( TestPlugin() ) self._executeBuild() converter = XmlReportConverter( self._getXmlReport() ) text = converter.convertToText() self.assertTrue( u"äöü" in text )
def testConvertXmlReportToHtml( self ): self._executeBuild() converter = XmlReportConverter( self._getXmlReport() ) xmlString = converter.convertToHtml() if converter.hasXsltSupport(): # can convert to HTML self.assertNotEquals( xmlString, None ) else: # cannot convert, should be None self.assertEquals( xmlString, None ) return # quit test case, to HTML conversion is not possible here doc = etree.XML( xmlString ) self.assertEqual( doc.tag, "{http://www.w3.org/1999/xhtml}html" ) # root self.assertNotEquals( doc.find( ".//{http://www.w3.org/1999/xhtml}table" ), None ) self.assertNotEquals( doc.find( ".//{http://www.w3.org/1999/xhtml}td" ), None )
def testXmlReportOnUnicodeFromApplicationOutput( self ): class TestPlugin( Plugin ): EXECUTABLE = ['python', os.path.join( self.MY_DIRECTORY, '..', 'scripts', 'print_unicode_output.py' )] def setup( self ): step = self.getInstructions().getStep( 'cleanup' ) action = ShellCommandAction( command = self.EXECUTABLE ) step.addMainAction( action ) self.build.addPlugin( TestPlugin() ) self._executeBuild() converter = XmlReportConverter( self._getXmlReport() ) converter.convertToText() # test if conversion does not crash something self.assertTrue( self.build.getReturnCode() == 0 )
def getObjectStatus( self ): if not XmlReportConverter.hasXsltSupport(): return "Cannot generate HTML, probably due to missing python-lxml package" if len( self.getRecipients() ) > 0: typeString = "full report" if self.getEnableFullReport() else "summary" return "Recipients: {0} ({1})".format( ", ".join( self.__recipientList ), typeString ) return "Recipients: (Using pre-configured settings)"
def _initEmailBody( self, email ): # body reporterUseCompression = mApp().getSettings().get( Settings.EmailReporterUseCompressionForAttachments, False ) report = InstructionsXmlReport( mApp() ) converter = XmlReportConverter( report ) ### text and html part # summary email.attachAlternativeTextPart( converter.convertToTextSummary(), converter.convertToHtml( summaryOnly = True ) ) # report if self.getEnableFullReport(): email.attachAlternativeTextPart( converter.convertToText( short = True ), converter.convertToHtml() ) returnCode = mApp().getReturnCode() if returnCode != 0: email.addTextAttachment( converter.convertToFailedStepsLog(), "failed-steps.log", useCompression = reporterUseCompression ) # attachments exception = mApp().getException() if exception: traceback = u"\n".join( exception[1] ) email.addTextAttachment( "{0}\n\n{1}".format( exception[0], traceback ), "exception.log", useCompression = reporterUseCompression ) return email
def main(): # instantiate MApplication, required for debug() calls MApplication() # check if first parameter is set try: inputFile = sys.argv[1] except IndexError: usage() sys.exit( 1 ) # check if second parameter in TARGET_FORMATS try: if sys.argv[2] in TARGET_FORMATS: targetFormat = sys.argv[2] else: usage() sys.exit( 1 ) except IndexError: # second parameter not set => using default targetFormat = "text" # start IO fin = open( inputFile ) xmlReport = StringBasedXmlReport( fin.read() ) fin.close converter = XmlReportConverter( xmlReport ) if targetFormat == "text": print( converter.convertToText() ) elif targetFormat == "text_summary": print( converter.convertToTextSummary() ) elif targetFormat == "html": print( converter.convertToHtml( enableCrossLinking = True ) ) elif targetFormat == "html_summary": print( converter.convertToHtml( summaryOnly = True, enableCrossLinking = True ) )
def report( self ): # create temporary directories self._cloneDirectories() report = InstructionsXmlReport( mApp() ) converter = XmlReportConverter( report ) html = converter.convertToHtml( enableCrossLinking = True ) # write file filePath = os.path.join( self.getTemporaryLocation(), "index.html" ) f = codecs.open( filePath, 'w', encoding = "utf-8" ) f.write( html or '' ) f.close() # temporary: also write report filePath = os.path.join( self.getTemporaryLocation(), "build-report.xml" ) f = codecs.open( filePath, 'w', encoding = "utf-8" ) f.write( report.getReport() ) f.close() self._upload() # cleanup temporary directories again self._deleteClonedDirectories()
def testConvertXmlReportToText( self ): self._executeBuild() converter = XmlReportConverter( self._getXmlReport() ) text = converter.convertToText() self.assertTrue( len( text ) > 1000 )
def _printHtmlReport( self, instructions = None ): conv = XmlReportConverter( self._getReport( instructions ) ) print( conv.convertToHtml() )
def convert( self, report ): converter = XmlReportConverter( report ) return converter.convertTo( self.__reportFormat )