Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Bug 788828 - Allow moztest to infer results, r=jgriffin
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Griffin committed Sep 7, 2012
1 parent f050183 commit a5f76f0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
41 changes: 35 additions & 6 deletions moztest/moztest/results.py
Expand Up @@ -129,22 +129,51 @@ def calculate_result(self, expected, actual):
# here it is definitely some kind of error
return 'ERROR'

def infer_results(self, computed_result):
assert computed_result in self.COMPUTED_RESULTS
if computed_result == 'ERROR':
expected = 'PASS'
actual = 'ERROR'
elif computed_result == 'UNEXPECTED-PASS':
expected = 'FAIL'
actual = 'PASS'
elif computed_result == 'UNEXPECTED-FAIL':
expected = 'PASS'
actual = 'FAIL'
elif computed_result == 'PASS':
expected = actual = 'PASS'
elif computed_result == 'KNOWN-FAIL':
expected = actual = 'FAIL'
elif computed_result == 'SKIPPED':
expected = actual = 'SKIP'
else:
return
self._result_expected = expected
self._result_actual = actual

def finish(self, result, time_end=None, output=None, reason=None):
""" Marks the test as finished, storing its end time and status
! Provide the duration as time_end if you only have that. """
msg = "Result '%s' not in possible results: %s" %\
(result, ', '.join(self.POSSIBLE_RESULTS))
assert result in self.POSSIBLE_RESULTS, msg

if result in self.COMPUTED_RESULTS:
self.infer_results(result)
self.result = result
elif result in self.POSSIBLE_RESULTS:
self._result_actual = result
self.result = self.calculate_result(self._result_expected,
self._result_actual)
else:
valid = self.POSSIBLE_RESULTS + self.COMPUTED_RESULTS
msg = "Result '%s' not valid. Need one of: %s" %\
(result, ', '.join(valid))
raise ValueError(msg)

# use lists instead of multiline strings
if isinstance(output, basestring):
output = output.splitlines()

self.time_end = time_end if time_end is not None else time.time()
self.output = output or self.output
self._result_actual = result
self.result = self.calculate_result(self._result_expected,
self._result_actual)
self.reason = reason

@property
Expand Down
2 changes: 1 addition & 1 deletion moztest/tests/test.py
Expand Up @@ -15,7 +15,7 @@ def test_results(self):
self.assertRaises(AssertionError,
lambda: TestResult('test', result_expected='hello'))
t = TestResult('test')
self.assertRaises(AssertionError, lambda: t.finish(result='good bye'))
self.assertRaises(ValueError, lambda: t.finish(result='good bye'))

def test_time(self):
now = time.time()
Expand Down

0 comments on commit a5f76f0

Please sign in to comment.