def run( self, target, metrics=[] ): """ Run this Test. raises: IOError: Unable to write output to file in log directory. Test.RunError: If executing the test failed return: {string}: The test output. """ try: # run the actual test start = datetime.now() output = subp.check_output([ config.TEST_RUNNER, self.path ], test=self ) stop = datetime.now() # create a result instance result = TestResult( self, start, stop, target ) result.log( output.encode( 'utf8' )) for metric in metrics: value = metric.collect( self ) result.add_metric( metric, value ) # log the collection of the metric output = str( value ).strip() logger.info( "\t%s: %s" % ( metric.name, "%s ..." % output[:40] if len( output ) > 40 else output )) return result except subp.CalledProcessError as e: raise Test.RunError( self, e )
def collect(self, test): # run the collector script with working directory the test folder. abspath = os.path.abspath(test.path).encode('string-escape') try: output = subp.check_output([os.path.abspath(self.path), test.name], test=test, cwd=abspath) except IOError as e: logger.error("Script `%s` did not exit succesfully for test `%s`" % (self.path, test.name)) output = None # parse the output return self.parse_output(output)
def collect( self, test ): # run the collector script with working directory the test folder. abspath = os.path.abspath( test.path ).encode( 'string-escape' ) try: output = subp.check_output( [ os.path.abspath( self.path ), test.name ], test=test, cwd=abspath ) except IOError as e: logger.error( "Script `%s` did not exit succesfully for test `%s`" % ( self.path, test.name )) output = None # parse the output return self.parse_output( output )