Source

django-coverage / django_coverage / utils / result_processor.py

Full commit
from datetime import time, datetime

class TestGroup():
  def __init__(self, name):
    self.name = name
    self.count = 0
    self.classes = ''
    self._classes = []
    self.items = []

  def appendTestInfo(self, tInfo):
    self.items.append( tInfo )
    if not tInfo.result_class in self.classes:
      self._classes.append( tInfo.result_class )
      self.classes = " ".join( self._classes )
    self.count += 1

class TestInfo():
  def __init__(self, test, result_class, data):
    self.module_name = test.__class__.__module__
    self.class_name = test.__class__.__name__
    self.name = test.id().split('.')[-1]
    self.group = self.module_name + '.' + self.class_name
    self.result_class = result_class
    self.data = data

  def stackTrace(self):
    return ''

class Summary():
  def __init__(self, result):
    fails = errors = 0
    try:
      results = map(len, ( result.failures, result.errors )  )
      fails, errors = results
    except AttributeError:
      pass
    expectedFails = unexpectedSuccesses = skipped = 0
    try:
      results = map(len, (result.expectedFailures,
                          result.unexpectedSuccesses,
                          result.skipped))
      expectedFails, unexpectedSuccesses, skipped = results
    except AttributeError:
      pass
    self.testsRun = result.testsRun
    self.successes = result.testsRun - errors - fails
    self.errors = errors
    self.fails = fails
    self.skips = skipped
    self.unexpected_successes = unexpectedSuccesses
    self.expected_fails = expectedFails


class ResultProcessor():
  def __init__(self, result, coverage_result):
    self.result = result
    self.coverage_result = coverage_result

  def context(self):
    tests = []
    for test_info in self.result.all_tests.values():
      tests.append( test_info )
    return { 'summary': Summary( self.result )
            , 'coverage_summary': self.coverage_result
            , 'TestTime': self.result.timeTaken
            , 'result_list': tests
            , 'report_generator': 'HTMLTestRunner'
            , 'creation_time': datetime.now().strftime( '%a %Y-%m-%d %H:%M %Z' ) }

class CoverageProcessor():
  def __init__(self, results):
    self.result = results

  def context(self):
    return {}