Changes between Initial Version and Version 1 of RubyTestUnitStep


Ignore:
Timestamp:
Oct 19, 2007, 1:29:33 AM (13 years ago)
Author:
keturn
Comment:

a Step to parse output from ruby Test::Unit console runner

Legend:

Unmodified
Added
Removed
Modified
  • RubyTestUnitStep

    v1 v1  
     1{{{
     2#!ruby
     3class RubyTest(shell.Test):
     4    """Parse the summary line from the Test::Unit Console runner.
     5
     6    Our script does not modify its error code when tests fail, so
     7    we parse the last line of the output to get the numbers.
     8    """
     9    summary_re = re.compile('^(?P<tests>d+) tests, '
     10                            '(?P<assertions>d+) assertions, '
     11                            '(?P<failures>d+) failures, '
     12                            '(?P<errors>d+) errors')
     13
     14    testunit_results = None
     15
     16
     17    def commandComplete(self, cmd):
     18        output = cmd.logs['stdio'].getText()
     19        summary_line = output.splitlines()[-1]
     20        match = self.summary_re.match(summary_line)
     21        if match:
     22            result_strings = match.groupdict()
     23            self.testunit_results = {}
     24            for k, v in result_strings.items():
     25                self.testunit_results[k] = int(v)
     26        else:
     27            from twisted.python import log
     28            log.msg("match failed: %s from %r" % (match, summary_line))
     29
     30
     31    def evaluateCommand(self, cmd):
     32        if (cmd.rc != 0) or (not self.testunit_results):
     33            return shell.FAILURE
     34        if self.testunit_results['failures'] or self.testunit_results['errors']:
     35            return shell.FAILURE
     36        return shell.SUCCESS
     37
     38
     39    def getText2(self, cmd, results):
     40        if not self.testunit_results:
     41            return [self.name]
     42
     43        r = []
     44        for x in 'errors', 'failures':
     45            if self.testunit_results[x]:
     46                r.append('%d %s' % (self.testunit_results[x], x))
     47
     48        return r
     49
     50
     51    def describe(self, done=False):
     52        if not done:
     53            return ["testing"]
     54        if not self.testunit_results:
     55            return ["tests"]
     56
     57        r = []
     58
     59        for x in 'errors', 'failures', 'tests', 'assertions':
     60            if self.testunit_results[x]:
     61                r.append('%d %s' % (self.testunit_results[x], x))
     62
     63        return r
     64}}}