mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
Bug 904682 - Mirror moztest to m-c. r=jhammel
This commit is contained in:
parent
b023d06977
commit
e89079d032
@ -100,6 +100,12 @@ class TestResult(object):
|
||||
self.output = []
|
||||
self.reason = None
|
||||
|
||||
@property
|
||||
def test_name(self):
|
||||
return '%s.py %s.%s' % (self.test_class.split('.')[0],
|
||||
self.test_class,
|
||||
self.name)
|
||||
|
||||
def __str__(self):
|
||||
return '%s | %s (%s) | %s' % (self.result or 'PENDING',
|
||||
self.name, self.test_class, self.reason)
|
||||
@ -190,10 +196,14 @@ class TestResult(object):
|
||||
class TestResultCollection(list):
|
||||
""" Container class that stores test results """
|
||||
|
||||
def __init__(self, suite_name, time_taken=0):
|
||||
resultClass = TestResult
|
||||
|
||||
def __init__(self, suite_name, time_taken=0, resultClass=None):
|
||||
list.__init__(self)
|
||||
self.suite_name = suite_name
|
||||
self.time_taken = time_taken
|
||||
if resultClass is not None:
|
||||
self.resultClass = resultClass
|
||||
|
||||
def __str__(self):
|
||||
return "%s (%.2fs)\n%s" % (self.suite_name, self.time_taken,
|
||||
@ -222,8 +232,8 @@ class TestResultCollection(list):
|
||||
def tests_with_result(self, result):
|
||||
""" Returns a generator of TestResults with the given result """
|
||||
msg = "Result '%s' not in possible results: %s" %\
|
||||
(result, ', '.join(TestResult.COMPUTED_RESULTS))
|
||||
assert result in TestResult.COMPUTED_RESULTS, msg
|
||||
(result, ', '.join(self.resultClass.COMPUTED_RESULTS))
|
||||
assert result in self.resultClass.COMPUTED_RESULTS, msg
|
||||
return self.filter(lambda t: t.result == result)
|
||||
|
||||
@property
|
||||
@ -231,58 +241,57 @@ class TestResultCollection(list):
|
||||
""" Generator of all tests in the collection """
|
||||
return (t for t in self)
|
||||
|
||||
@property
|
||||
def num_failures(self):
|
||||
fails = 0
|
||||
for t in self:
|
||||
if t.result in TestResult.FAIL_RESULTS:
|
||||
fails += 1
|
||||
return fails
|
||||
|
||||
def add_unittest_result(self, result, context=None):
|
||||
""" Adds the python unittest result provided to the collection"""
|
||||
|
||||
def add_result(self, test, result_expected='PASS',
|
||||
result_actual='PASS', output='', context=None):
|
||||
def get_class(test):
|
||||
return test.__class__.__module__ + '.' + test.__class__.__name__
|
||||
|
||||
def add_test_result(test, result_expected='PASS',
|
||||
result_actual='PASS', output=''):
|
||||
t = TestResult(name=str(test).split()[0], test_class=get_class(test),
|
||||
t = self.resultClass(name=str(test).split()[0], test_class=get_class(test),
|
||||
time_start=0, result_expected=result_expected,
|
||||
context=context)
|
||||
t.finish(result_actual, time_end=0, reason=relevant_line(output),
|
||||
output=output)
|
||||
self.append(t)
|
||||
|
||||
@property
|
||||
def num_failures(self):
|
||||
fails = 0
|
||||
for t in self:
|
||||
if t.result in self.resultClass.FAIL_RESULTS:
|
||||
fails += 1
|
||||
return fails
|
||||
|
||||
def add_unittest_result(self, result, context=None):
|
||||
""" Adds the python unittest result provided to the collection"""
|
||||
if hasattr(result, 'time_taken'):
|
||||
self.time_taken += result.time_taken
|
||||
|
||||
for test, output in result.errors:
|
||||
add_test_result(test, result_actual='ERROR', output=output)
|
||||
self.add_result(test, result_actual='ERROR', output=output)
|
||||
|
||||
for test, output in result.failures:
|
||||
add_test_result(test, result_actual='FAIL',
|
||||
self.add_result(test, result_actual='FAIL',
|
||||
output=output)
|
||||
|
||||
if hasattr(result, 'unexpectedSuccesses'):
|
||||
for test in result.unexpectedSuccesses:
|
||||
add_test_result(test, result_expected='FAIL',
|
||||
self.add_result(test, result_expected='FAIL',
|
||||
result_actual='PASS')
|
||||
|
||||
if hasattr(result, 'skipped'):
|
||||
for test, output in result.skipped:
|
||||
add_test_result(test, result_expected='SKIP',
|
||||
self.add_result(test, result_expected='SKIP',
|
||||
result_actual='SKIP', output=output)
|
||||
|
||||
if hasattr(result, 'expectedFailures'):
|
||||
for test, output in result.expectedFailures:
|
||||
add_test_result(test, result_expected='FAIL',
|
||||
self.add_result(test, result_expected='FAIL',
|
||||
result_actual='FAIL', output=output)
|
||||
|
||||
# unittest does not store these by default
|
||||
if hasattr(result, 'tests_passed'):
|
||||
for test in result.tests_passed:
|
||||
add_test_result(test)
|
||||
self.add_result(test)
|
||||
|
||||
@classmethod
|
||||
def from_unittest_results(cls, context, *results):
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
from setuptools import setup
|
||||
|
||||
PACKAGE_VERSION = '0.2'
|
||||
PACKAGE_VERSION = '0.3'
|
||||
|
||||
# dependencies
|
||||
deps = ['mozinfo']
|
||||
|
Loading…
Reference in New Issue
Block a user