[svn r57321] merging the event branch:
* moving in test, misc, code, io directories and py/__init__.py * py/bin/_find.py does not print to stderr anymore * a few fixes to conftest files in other dirs some more fixes and adjustments pending --HG-- branch : trunk
This commit is contained in:
58
py/test/testing/test_event.py
Normal file
58
py/test/testing/test_event.py
Normal file
@@ -0,0 +1,58 @@
|
||||
import py
|
||||
from py.__.test.event import EventBus
|
||||
from py.__.test import event
|
||||
import suptest
|
||||
from py.__.code.testing.test_excinfo import TWMock
|
||||
|
||||
class TestEventBus:
|
||||
def test_simple(self):
|
||||
bus = EventBus()
|
||||
l = []
|
||||
bus.subscribe(l.append)
|
||||
bus.notify(1)
|
||||
bus.notify(2)
|
||||
bus.notify(3)
|
||||
assert l == [1,2,3]
|
||||
|
||||
def test_multi_sub(self):
|
||||
bus = EventBus()
|
||||
l1 = []
|
||||
l2 = []
|
||||
bus.subscribe(l1.append)
|
||||
bus.subscribe(l2.append)
|
||||
bus.notify(1)
|
||||
bus.notify(2)
|
||||
bus.notify(3)
|
||||
assert l1 == [1,2,3]
|
||||
assert l2 == [1,2,3]
|
||||
|
||||
def test_remove(self):
|
||||
bus = EventBus()
|
||||
l = []
|
||||
bus.subscribe(l.append)
|
||||
bus.notify(1)
|
||||
bus.unsubscribe(l.append)
|
||||
bus.notify(2)
|
||||
assert l == [1]
|
||||
|
||||
|
||||
class TestItemTestReport(object):
|
||||
def test_toterminal(self):
|
||||
sorter = suptest.events_run_example("filetest.py")
|
||||
reports = sorter.get(event.ItemTestReport)
|
||||
ev = reports[0]
|
||||
assert ev.failed
|
||||
twmock = TWMock()
|
||||
ev.toterminal(twmock)
|
||||
assert twmock.lines
|
||||
twmock = TWMock()
|
||||
ev.outcome.longrepr = "hello"
|
||||
ev.toterminal(twmock)
|
||||
assert twmock.lines[0] == "hello"
|
||||
assert not twmock.lines[1:]
|
||||
|
||||
##assert ev.repr_run.find("AssertionError") != -1
|
||||
filepath = ev.colitem.fspath
|
||||
#filepath , modpath = ev.itemrepr_path
|
||||
assert str(filepath).endswith("filetest.py")
|
||||
#assert modpath.endswith("filetest.test_one")
|
||||
Reference in New Issue
Block a user