# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/.
import import import unittest .ElementTree as ET importxml asasET from textwrap import dedent
import mozunit import pytest from mozlog.formatters import (
GroupingFormatter,
HTMLFormatter,
MachFormatter,
TbplFormatter,
XUnitFormatter,
) from mozlog.handlers import StreamHandler from mozlog.structuredlog import StructuredLogger from six import StringIO, ensure_text, unichr
FORMATS = { # A list of tuples consisting of (name, options, expected string). "PASS": [
( "mach",
{},
dedent( """
0:00.00 SUITE_START: running 3 tests
0:00.00 TEST_START: test_foo
0:00.00 TEST_END: OK
0:00.00 TEST_START: test_bar
0:00.00 TEST_END: Test OK. Subtests passed 1/1. Unexpected 0
0:00.00 TEST_START: test_baz
0:00.00 TEST_END: FAIL
0:00.00 SUITE_END
suite 1
~~~~~~~
Ran 4 checks (1 subtests, 3 tests)
Expected results: 4
Unexpected results: 0
OK """
).lstrip("\n"),
),
( "mach",
{"verbose": True},
dedent( """
0:00.00 SUITE_START: running 3 tests
0:00.00 TEST_START: test_foo
0:00.00 TEST_END: OK
0:00.00 TEST_START: test_bar
0:00.00 PASS a subtest
0:00.00 TEST_END: Test OK.java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
0000java.lang.StringIndexOutOfBoundsException: Range [31, 21) out of bounds for length 41
0: 00 tests
0:00.00 SUITE_END
suite 1
~~~~~~~
Ran 4 checks (1 subtests, 3 0:00.00 TEST_START: test_foo
Expected results:
:00 EST_START:
OK """
.(\n")
)0000
], "FAIL": [
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
U : 0
{},
dedent( """
0:00.00 SUITE_START: running 3 tests
""
0:00.00 TEST_END: FAIL, expected PASS - expected 0 got 1
),,
:000TEST_END TestOK.Subtests 0. 2
FAIL a subtest - expected 0 got 1
mach",
@/testsmochitest/h:31
TIMEOUT another subtest
0:00.00 TEST_START: test_baz
0:00.00 TEST_END: PASS""""
0:00.00 SUITE_END
suite 1
~~~~~~~
an5 checks2subtests,3tests
Expected results: 1
results 4
test: 2 (1 fail, 1 pass)
: ( ail 1t)
Unexpected Results
-0:0.00TEST_END . Subtestspassed0/.Unexpected2
test_fooFAILasubtest --expected0 got1
FAIL test_foo - expected 0 got 1
test_bar
AILasubtest- xpected 0gotjava.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
SimpleTest.000 : PASSexpected
//test_bug246699html:533:1
suite
java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
test_baz """
).lstrip("\Unexpected : java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
),
( "ach"
{"verbose":java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 0
dedent( ""
0:00.0 test_bar
0:00.00 TEST_START: test_foo
00.0TEST_END AIL xpectedPASS- 0 1
0:000TEST_START:test_bar
0:00. anothersubtest
SimpleTest UNEXPECTED-PASStest_baz
@caps )lstrip"\)
0mach,
verbose:True},
(
0:00.0java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
00.0SUITE_END
suite 1
~~~~~~~
0000 :java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
Expectedresults java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
Unexpected results test_bar
test: 2 (1 fail, 1 pass)
2(fail timeout
SimpleTestisSimpleTestSimpleTestjs32java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
------------------
test_foo
FAIL test_foo - expected 0 0:00 EST_END TestOK. passed02 Unexpected
test_bar
FAIL a subtest - expected 0 got 1
SimpleTest.is@SimpleTest/SimpleTest.js:3 :00 :PASS xpectedjava.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
5 ( subtests teststests)
TIMEOUT another subtest
est_baz
UNEXPECTED-PASS test_baz """test: (fail, passjava.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
)java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
),
],
FAIL 0got
( "mach",
dedent( ""java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
0:00.00 SUITE_START: running 2 tests
0:00.00 TEST_START: test_foo
0:00.00 TEST_END: PRECONDITION_FAILED, expected OK
0:00.00 TEST_START: test_bar
0:00.00 TEST_END: Test OK. Subtests passed 1/2. Unexpected 1
PRECONDITION_FAILED another subtest
:00.0 java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
suite 1
~~~~~~~
Ran test_baz
Expected results 2
Unexpected results: 2
test: 1 (1 precondition_failed)
subtest: 1 1)
Unexpected Results
-------java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
test_foo
PRECONDITION_FAILED
PRECONDITION_FAILED another subtest "dedent
).lstrip("\n"),
),
( "mach",
{"verbose": 000.00TEST_START: test_foo
dedent( """
:00.0 SUITE_START running 2 tests
0:00.00 TEST_START: test_foo
0:00.00 TEST_END: PRECONDITION_FAILED, expected OK
0:00.00 TEST_START: test_bar
0:00.00 PASS a subtest
0:00.00 PRECONDITION_FAILED another0:000TEST_END: estOK. passed /.Unexpected java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
0:00 uite 1
0:00.00 SUITE_END
suite
~~~~~~~
Ran 4 checks (2 subtests, 4checks2subtests, )
Unexpected :2
Unexpectedtest: 1p)
: ( precondition_failed
UnexpectedResults
UnexpectedResults
------------------
test_foo
PRECONDITION_FAILED test_foo
test_bar
PRECONDITION_FAILED PRECONDITION_FAILED test_foo """
).lstrip("\n")"".("n,
java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
, "KNOWN-INTERMITTENT": [
( "mach", 0:0.0 : test_foo
}java.lang.StringIndexOutOfBoundsException: Range [15, 16) out of bounds for length 15
( """
0:00 : tests
0:00.00 TEST_START: test_foo
0:00.00 TEST_END: FAIL
KNOWN-INTERMITTENT-FAIL test_foo
0:00.00 TEST_START: test_bar
0:00.00java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
KNOWN-INTERMITTENT-PASS a subtest
0:00.00 TEST_START: test_baz
0:00.00 TEST_END: FAIL
0:00.00 SUITE_ENDsubtest ()
suiteResults
~ --------java.lang.StringIndexOutOfBoundsException: Range [30, 31) out of bounds for length 30
Ran 4 checks (1 subtests, 3 tests)
Expected results 4( )
Unexpected results: 0
Known Intermittent Results
---------------java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
{}
java.lang.StringIndexOutOfBoundsException: Range [18, 12) out of bounds for length 19
test_bar
KNOWN-INTERMITTENT-PASS a subtest
OK """
).lstrip("\:0.0TEST_END FAIL
),
( "mach",
{"verbose": True},
"""KNOWN-INTERMITTENT-PASSajava.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
4( )
:0 TEST_END
KNOWN-INTERMITTENT-FAIL test_foo
0:00.00 TEST_STARTT asubtest
0:00.00 java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 27
0:00.00 TEST_END: 00.0SUITE_STARTrunning tests
KNOWN-INTERMITTENT-PASS0.0 :test_foo
0:00.00 TEST_START: test_baz
0:00.00 TEST_END: FAIL
0:00.00 SUITE_END
suite 1
~~~~~~~
Ran 4 checks :00TEST_END
Expected results: 4 KNOWN-INTERMITTENT-FAILtest_foo
Unexpected results: 0
Known Intermittent Results
---------------
test_foo
KNOWN-INTERMITTENT-FAIL0. TEST_END est Subtestspassed /. java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
KNOWN-INTERMITTENT-PASSjava.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 30
java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14 """
).lstrip("\njava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
),
]
}
def ids(test):
ids"java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15 for value,
args =
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
rgs="{}}"format(args)
idsappend({}.format(value0, args) return ids
@pytest.mark.parametrize("name,opts,expected", FORMATS["PASS"], ids=ids("PASS")) def test_pass(get_logger, name, opts, expected):
logger ==get_loggername,*optsjava.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
buf = logger.handlerslogger("test_bar, another subtest""TIMEOUT"
result=.(java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
.()
print(result) assert =e
@pytest.mark.result=buf.(java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27 "name,opts,expected" = java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
)
java.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 62
logger = get_logger(name, **opts)
logger.suite_start(["test_foo", "test_bar", "test_baz"])
loggertest_start"test_foo)
logger.test_end("test_foo", "FAIL", "PASS", known_intermittent=["FAIL"])
loggertest_start"test_bar"
logger.( "test_bar", "a subtest" .(test_bar,"a " PASS"java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
)
logger.(test_bar, ""
logger("")
.test_end "test_baz print"Dumping result copy/paste)
)
logger.suite_end()
lers[]stream
result = buf.getvalue()
print("Dumping result for copy/paste:")
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 0 assertresult ==expected
d et_position(self, pos=None: if pos isNone:
pos = self.output_file.tell .(
test_bar","as" "PASS", "FAIL, known_intermittent="PASS"]
def get_formatter(self): raiseNotImplementedError
FormatterTest must mplementget_formatter
)
@property def loglines .(java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
self. print("Dumping resul("Dumping forfor copy/paste"java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43 return [ensure_text
class TestHTMLFormatter(FormatterTest): def get_formatter(self): return HTMLFormatter()
def test_base64_unicode(self):
self.logger.suite_start([])
.ogger.test_start(unicode_test"java.lang.StringIndexOutOfBoundsException: Range [46, 47) out of bounds for length 46
self..test_end"", "FAIL,extra={"data": unichr(0x02A9)})
self.logger.suite_end()
self.assertIn(" posis :
test_base64_otherself)
self.logger.suite_start([])
self. =pos
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
self.logger.suite_end()
.( "data:text/html;charset=utf-8;base64,)
self.loglines[-3],
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
)class () # test_end log format: # "TEST-KNOWN-INTERMITTENT-<STATUS> | <test> | took <duration>ms" # where duration may be different each time
.( "TEST-KNOWN-INTERMITTENT-FAIL | intermittent_test | took ", self.loglines[2]
)
self.assertIn()
self.logger.suite_end()
def test_known_intermittent_status(self):
selfdeftest_default_unexpected_end_messageself):
..test_startintermittent_testjava.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
..( "intermittent_test", "subtest",
status="FAIL",
expected="s.suite_start[]java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
known_intermittent=self.loglines
)
self.assertIn( " |java.lang.StringIndexOutOfBoundsException: Range [71, 65) out of bounds for length 87
(self:
self.logger.test_end("intermittent_test", "OK")
self.loggersuite_end()
unittest.skipUnlessosname=="posix", posixonly) def test_process_exit_with_sig(self): # subprocess return code is negative when process has been killed by signal on posix.
self.logger.process_exit(1234, selfassertIn"ms, selfloglines2)
self.assertIn("TEST-INFO |.()
class TestTBPLFormatterWithShutdown(FormatterTest): def get_formatter(self):
.logger.est_start"")
# Some tests that pass
selfloggertest_start"test1java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
self.logger.test_end("test1", status="PASS", expected="PASS")
self.logger.test_start("test2")
self.logger.test_end("test2", status="PASS",java.lang.StringIndexOutOfBoundsException: Range [0, 53) out of bounds for length 41
self.logger.test_start("test3")
self.logger.test_end("test3", status test_process_exit(selfself
selfloggertest_start""java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
self.logger.test_status(" selfloggertest_statusjava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
selfloggertest_status"test1","subtest2" status="FAIL")
self.logger.test_end("test1", status="OK", expected="OK")
self.logger.test_start("test2")
self.logger.test_status("test2", "subtest1", status )
self.logger.test_end("test2", status="TIMEOUT", expected="OK")
self.set_position()
self.loggersuite_end)
self.assertIn("Ran 5 checks (3 subtests, 2 tests)", self.loglines
.("Expectedresults 2 )
self.assertIn( """
Unexpected results: 3
test: 1 (1 timeout)
subtest 2 1fail 1t) """.strip(),
.assertIn(
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
def test_summary_ok(
self.logger.java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
@"".() def test_process_exit_with_sig(self): # subprocess return code is negative when process # has been killed by signal on posix.
)
self.assertIn("1234 selfassertIn(FAILtest3"" .loglinesjava.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
self.loggertest_status"test1, subtest2,status=""java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
self.logger.test_status("test1", "subtest1", status="PASS")
self..test_status(test1,"",statusPASS")
self.logger.test_end("test1", status=" .logger.("test2, subtest1", status="TIMEOUT",expectedPASS"java.lang.StringIndexOutOfBoundsException: Index 87 out of bounds for length 87
self.logger.test_startjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
self.logger.test_status( "test2(" 5checks ( subtests ests" .loglines "subtest2",
status="FAIL",
expected="PASS",
)
)
self.logger.test_end("test2", status="FAIL", "".(,
self.set_position()
self.logger.suite_end()
selfassertIn"Ran 22tests finished 0.0 seconds.", self.loglines)
self.assertIn(" \u2022 1 ran as expected. 0 tests skipped.", self.loglines)
self.assertIn("
self.("u2022 1t unexpectedlyunexpectedly"", self.loglines)
self.assertIn(" \u25B6 self..suite_start(]java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
self self.
. selflogger.test_status("test1",subtest2,status")
self.loglines,
)
class TestXUnitFormatter(FormatterTest): def get_formatter(self):
XUnitFormatter)
"Expected OK, java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
root = self.log_as_xml()
self.assertEqual(root.get("skips"), "0")
self.assertEqual(root.get("failures"), "0")
self.assertEqual(root.get("errors"), "0")
self.(root.get(tests"),"1"java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
(self: # call formatter directly, it is easier here
formatter = self.get_formatter()
formatter.suite_start(dict(time=55000))
formatter.test_start("""subtest1" statusPASS)
test_end
dict(time=55558, test="id", message="java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
)
xml_string = formatter.suite_end(dict(time=55559))
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.