[py-svn] r57128 - in py/branch/event/py/test2: . rep rep/testing
hpk at codespeak.net
hpk at codespeak.net
Sat Aug 9 13:19:04 CEST 2008
Author: hpk
Date: Sat Aug 9 13:19:03 2008
New Revision: 57128
Modified:
py/branch/event/py/test2/rep/base.py
py/branch/event/py/test2/rep/collectonly.py
py/branch/event/py/test2/rep/terminal.py
py/branch/event/py/test2/rep/testing/test_basereporter.py
py/branch/event/py/test2/rep/testing/test_collectonly.py
py/branch/event/py/test2/rep/testing/test_terminal.py
py/branch/event/py/test2/session.py
Log:
refactor reporter init
Modified: py/branch/event/py/test2/rep/base.py
==============================================================================
--- py/branch/event/py/test2/rep/base.py (original)
+++ py/branch/event/py/test2/rep/base.py Sat Aug 9 13:19:03 2008
@@ -2,15 +2,17 @@
import sys
class BaseReporter(object):
- def __init__(self):
+ def __init__(self, bus=None):
self._passed = []
self._skipped = []
self._failed = []
-
- def activate(self, bus):
- bus.subscribe(self.processevent)
- def deactivate(self, bus):
- bus.unsubscribe(self.processevent)
+ self._bus = bus
+ if bus:
+ self._bus.subscribe(self.processevent)
+
+ def deactivate(self):
+ if self._bus:
+ self._bus.unsubscribe(self.processevent)
def processevent(self, ev):
evname = ev.__class__.__name__
Modified: py/branch/event/py/test2/rep/collectonly.py
==============================================================================
--- py/branch/event/py/test2/rep/collectonly.py (original)
+++ py/branch/event/py/test2/rep/collectonly.py Sat Aug 9 13:19:03 2008
@@ -9,8 +9,8 @@
class CollectonlyReporter(BaseReporter):
INDENT = " "
- def __init__(self, config, out=None):
- super(CollectonlyReporter, self).__init__()
+ def __init__(self, config, out=None, bus=None):
+ super(CollectonlyReporter, self).__init__(bus=bus)
self.config = config
if out is None:
out = py.std.sys.stdout
Modified: py/branch/event/py/test2/rep/terminal.py
==============================================================================
--- py/branch/event/py/test2/rep/terminal.py (original)
+++ py/branch/event/py/test2/rep/terminal.py Sat Aug 9 13:19:03 2008
@@ -7,8 +7,8 @@
from py.__.test2.rep.base import getrelpath, repr_pythonversion
class TerminalReporter(BaseReporter):
- def __init__(self, config, file=None):
- super(TerminalReporter, self).__init__()
+ def __init__(self, config, file=None, bus=None):
+ super(TerminalReporter, self).__init__(bus=bus)
self.config = config
self.currentfspath = None
self.curdir = py.path.local()
Modified: py/branch/event/py/test2/rep/testing/test_basereporter.py
==============================================================================
--- py/branch/event/py/test2/rep/testing/test_basereporter.py (original)
+++ py/branch/event/py/test2/rep/testing/test_basereporter.py Sat Aug 9 13:19:03 2008
@@ -10,11 +10,10 @@
class TestBaseReporter:
def test_activate(self):
bus = EventBus()
- rep = BaseReporter()
- rep.activate(bus)
+ rep = BaseReporter(bus=bus)
assert bus._subscribers
assert rep.processevent in bus._subscribers
- rep.deactivate(bus)
+ rep.deactivate()
assert not bus._subscribers
def test_dispatch_to_matching_method(self):
Modified: py/branch/event/py/test2/rep/testing/test_collectonly.py
==============================================================================
--- py/branch/event/py/test2/rep/testing/test_collectonly.py (original)
+++ py/branch/event/py/test2/rep/testing/test_collectonly.py Sat Aug 9 13:19:03 2008
@@ -57,8 +57,7 @@
py.test2.skip("nomod")
""")
stringio = py.std.cStringIO.StringIO()
- rep = CollectonlyReporter(modcol._config, out=stringio)
- rep.activate(self.session.bus)
+ rep = CollectonlyReporter(modcol._config, bus=self.session.bus, out=stringio)
cols = list(self.session.genitems([modcol]))
assert len(cols) == 0
assert_stringio_contains_lines(stringio, """
@@ -71,8 +70,7 @@
raise ValueError(0)
""")
stringio = py.std.cStringIO.StringIO()
- rep = CollectonlyReporter(modcol._config, out=stringio)
- rep.activate(self.session.bus)
+ rep = CollectonlyReporter(modcol._config, bus=self.session.bus, out=stringio)
cols = list(self.session.genitems([modcol]))
assert len(cols) == 0
assert_stringio_contains_lines(stringio, """
Modified: py/branch/event/py/test2/rep/testing/test_terminal.py
==============================================================================
--- py/branch/event/py/test2/rep/testing/test_terminal.py (original)
+++ py/branch/event/py/test2/rep/testing/test_terminal.py Sat Aug 9 13:19:03 2008
@@ -47,8 +47,7 @@
import xyz
""")
stringio = py.std.cStringIO.StringIO()
- rep = TerminalReporter(modcol._config, file=stringio)
- rep.activate(self.session.bus)
+ rep = TerminalReporter(modcol._config, bus=self.session.bus, file=stringio)
l = list(self.session.genitems([modcol]))
assert len(l) == 0
s = popvalue(stringio)
Modified: py/branch/event/py/test2/session.py
==============================================================================
--- py/branch/event/py/test2/session.py (original)
+++ py/branch/event/py/test2/session.py Sat Aug 9 13:19:03 2008
@@ -81,8 +81,7 @@
def sessionstarts(self):
""" setup any neccessary resources ahead of the test run. """
- self.reporter = self.config.getreporter()
- self.reporter.activate(self.bus)
+ self.reporter = self.config.initreporter(self.bus)
self.bus.notify(repevent.SessionStart(self))
self._failurelist = []
self.bus.subscribe(self._processfailures)
@@ -98,7 +97,7 @@
py.test2.collect.Item._setupstate.teardown_all() # this can raise exceptions!
self.bus.notify(repevent.SessionFinish(self))
self.bus.unsubscribe(self._processfailures)
- self.reporter.deactivate(self.bus)
+ self.reporter.deactivate()
return self._failurelist
def main(self):
More information about the pytest-commit
mailing list