54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
""" test reporting functionality. """
|
|
|
|
import py
|
|
from py.__.test import repevent
|
|
|
|
def test_wrapcall_ok():
|
|
l = []
|
|
def ok(x):
|
|
return x+1
|
|
i = repevent.wrapcall(l.append, ok, 1)
|
|
assert i == 2
|
|
assert len(l) == 2
|
|
assert isinstance(l[0], repevent.CallStart)
|
|
assert isinstance(l[1], repevent.CallFinish)
|
|
assert repr(l[0])
|
|
assert repr(l[1])
|
|
|
|
def test_wrapcall_exception():
|
|
l = []
|
|
def fail(x):
|
|
raise ValueError
|
|
py.test.raises(ValueError, "repevent.wrapcall(l.append, fail, 1)")
|
|
assert len(l) == 2
|
|
assert isinstance(l[0], repevent.CallStart)
|
|
assert isinstance(l[1], repevent.CallException)
|
|
|
|
def test_reporter_methods_sanity():
|
|
""" Checks if all the methods of reporter are sane
|
|
"""
|
|
from py.__.test.reporter import RemoteReporter
|
|
|
|
for method in dir(RemoteReporter):
|
|
|
|
if method.startswith("report_") and method != "report_unknown":
|
|
assert method[len('report_'):] in repevent.__dict__
|
|
|
|
def test_repevent_failures():
|
|
from py.__.test.outcome import SerializableOutcome, ReprOutcome
|
|
|
|
assert not repevent.ReportEvent().is_failure()
|
|
assert not repevent.CallEvent(None, None, None).is_failure()
|
|
assert repevent.FailedTryiter(None, None).is_failure()
|
|
out = ReprOutcome(SerializableOutcome().make_repr())
|
|
assert not repevent.ReceivedItemOutcome(None, None, out).is_failure()
|
|
out = ReprOutcome(SerializableOutcome(skipped="xxx").make_repr())
|
|
assert not repevent.ReceivedItemOutcome(None, None, out).is_failure()
|
|
try:
|
|
1/0
|
|
except:
|
|
exc = py.code.ExceptionInfo()
|
|
out = ReprOutcome(SerializableOutcome(excinfo=exc).make_repr())
|
|
assert repevent.ReceivedItemOutcome(None, None, out).is_failure()
|
|
|