PythonUnitTestResultParser

public class PythonUnitTestResultParser
extends MultiLineReceiver

java.lang.Object
   ↳ com.android.ddmlib.MultiLineReceiver
     ↳ com.android.tradefed.testtype.PythonUnitTestResultParser


Interprets the output of tests run with Python's unittest framework and translates it into calls on a series of ITestRunListeners. Output from these tests follows this EBNF grammar: TestReport ::= TestResult* Line TimeMetric [FailMessage*] Status. TestResult ::= string “(“string”)” “…” SingleStatus. FailMessage ::= EqLine “ERROR:” string “(“string”)” Line Traceback Line. SingleStatus ::= “ok” | “ERROR”. TimeMetric ::= “Ran” integer “tests in” float ”s”. Status ::= “OK” | “FAILED (errors=” int “)”. Traceback ::= string+. Example output (passing): test_size (test_rangelib.RangeSetTest) ... ok test_str (test_rangelib.RangeSetTest) ... ok test_subtract (test_rangelib.RangeSetTest) ... ok test_to_string_raw (test_rangelib.RangeSetTest) ... ok test_union (test_rangelib.RangeSetTest) ... ok ---------------------------------------------------------------------- Ran 5 tests in 0.002s OK Example output (failed) test_size (test_rangelib.RangeSetTest) ... ERROR ====================================================================== ERROR: test_size (test_rangelib.RangeSetTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_rangelib.py", line 129, in test_rangelib raise ValueError() ValueError ---------------------------------------------------------------------- Ran 1 test in 0.001s FAILED (errors=1) Example output with several edge cases (failed): testError (foo.testFoo) ... ERROR testExpectedFailure (foo.testFoo) ... expected failure testFail (foo.testFoo) ... FAIL testFailWithDocString (foo.testFoo) foo bar ... FAIL testOk (foo.testFoo) ... ok testOkWithDocString (foo.testFoo) foo bar ... ok testSkipped (foo.testFoo) ... skipped 'reason foo' testUnexpectedSuccess (foo.testFoo) ... unexpected success ====================================================================== ERROR: testError (foo.testFoo) ---------------------------------------------------------------------- Traceback (most recent call last): File "foo.py", line 11, in testError self.assertEqual(2+2, 5/0) ZeroDivisionError: integer division or modulo by zero ====================================================================== FAIL: testFail (foo.testFoo) ---------------------------------------------------------------------- Traceback (most recent call last): File "foo.py", line 8, in testFail self.assertEqual(2+2, 5) AssertionError: 4 != 5 ====================================================================== FAIL: testFailWithDocString (foo.testFoo) foo bar ---------------------------------------------------------------------- Traceback (most recent call last): File "foo.py", line 31, in testFailWithDocString self.assertEqual(2+2, 5) AssertionError: 4 != 5 ---------------------------------------------------------------------- Ran 8 tests in 0.001s FAILED (failures=2, errors=1, skipped=1, expected failures=1, unexpected successes=1)

Summary

Nested classes

enum PythonUnitTestResultParser.ParserState

 

Constants

String DASH_LINE

String EQUAL_LINE

String SKIPPED_ENTRY

String TRACEBACK_LINE

Fields

static final Pattern PATTERN_FAIL_MESSAGE

static final Pattern PATTERN_ONE_LINE_RESULT

static final Pattern PATTERN_RUN_RESULT

static final Pattern PATTERN_RUN_SUMMARY

static final Pattern PATTERN_TEST_FAILURE

static final Pattern PATTERN_TEST_SKIPPED

static final Pattern PATTERN_TEST_SUCCESS

static final Pattern PATTERN_TEST_UNEXPECTED_SUCCESS

static final Pattern PATTERN_TWO_LINE_RESULT_FIRST

static final Pattern PATTERN_TWO_LINE_RESULT_SECOND

Public constructors

PythonUnitTestResultParser(Collection<ITestRunListener> listeners, String runName)

Create a new PythonUnitTestResultParser that reports to the given ITestRunListeners.

Public methods

boolean isCancelled()
void processNewLines(String[] lines)

Process Python unittest output and report parsed results.

Constants

DASH_LINE

String DASH_LINE

Constant Value: "----------------------------------------------------------------------"

EQUAL_LINE

String EQUAL_LINE

Constant Value: "======================================================================"

SKIPPED_ENTRY

String SKIPPED_ENTRY

Constant Value: "Skipped"

TRACEBACK_LINE

String TRACEBACK_LINE

Constant Value: "Traceback (most recent call last):"

Fields

PATTERN_FAIL_MESSAGE

Pattern PATTERN_FAIL_MESSAGE

PATTERN_ONE_LINE_RESULT

Pattern PATTERN_ONE_LINE_RESULT

PATTERN_RUN_RESULT

Pattern PATTERN_RUN_RESULT

PATTERN_RUN_SUMMARY

Pattern PATTERN_RUN_SUMMARY

PATTERN_TEST_FAILURE

Pattern PATTERN_TEST_FAILURE

PATTERN_TEST_SKIPPED

Pattern PATTERN_TEST_SKIPPED

PATTERN_TEST_SUCCESS

Pattern PATTERN_TEST_SUCCESS

PATTERN_TEST_UNEXPECTED_SUCCESS

Pattern PATTERN_TEST_UNEXPECTED_SUCCESS

PATTERN_TWO_LINE_RESULT_FIRST

Pattern PATTERN_TWO_LINE_RESULT_FIRST

PATTERN_TWO_LINE_RESULT_SECOND

Pattern PATTERN_TWO_LINE_RESULT_SECOND

Public constructors

PythonUnitTestResultParser

PythonUnitTestResultParser (Collection<ITestRunListener> listeners, 
                String runName)

Create a new PythonUnitTestResultParser that reports to the given ITestRunListeners.

Parameters
listeners Collection

runName String

Public methods

isCancelled

boolean isCancelled ()

Returns
boolean

processNewLines

void processNewLines (String[] lines)

Process Python unittest output and report parsed results.

This method should be called only once with the full output, unlike the base method in MultiLineReceiver.

Parameters
lines String