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 ITestInvocationListeners. 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)

TODO: Consider refactoring the full class, handling is quite messy right now.

Summary

Public constructors

PythonUnitTestResultParser(ITestInvocationListener listener, String runName)

Create a new PythonUnitTestResultParser that reports to the given ITestInvocationListener.

PythonUnitTestResultParser( listeners, String runName)

Create a new PythonUnitTestResultParser that reports to the given ITestInvocationListeners.

Public methods

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

Process Python unittest output and report parsed results.

Public constructors

PythonUnitTestResultParser

public PythonUnitTestResultParser (ITestInvocationListener listener, 
                String runName)

Create a new PythonUnitTestResultParser that reports to the given ITestInvocationListener.

Parameters
listener ITestInvocationListener

runName String

PythonUnitTestResultParser

public PythonUnitTestResultParser ( listeners, 
                String runName)

Create a new PythonUnitTestResultParser that reports to the given ITestInvocationListeners.

Parameters
listeners

runName String

Public methods

isCancelled

public boolean isCancelled ()

Returns
boolean

processNewLines

public 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