[py-svn] r57219 - in py/branch/event/py/test2/dsession: . testing
hpk at codespeak.net
hpk at codespeak.net
Wed Aug 13 10:34:37 CEST 2008
Author: hpk
Date: Wed Aug 13 10:34:36 2008
New Revision: 57219
Added:
py/branch/event/py/test2/dsession/looponfailing.py
- copied, changed from r57215, py/branch/event/py/test2/dsession/filechange.py
py/branch/event/py/test2/dsession/testing/test_looponfailing.py
- copied, changed from r57215, py/branch/event/py/test2/dsession/testing/test_filechange.py
Removed:
py/branch/event/py/test2/dsession/filechange.py
py/branch/event/py/test2/dsession/testing/test_filechange.py
Log:
move to common helper for looponfailing
Deleted: /py/branch/event/py/test2/dsession/filechange.py
==============================================================================
--- /py/branch/event/py/test2/dsession/filechange.py Wed Aug 13 10:34:36 2008
+++ (empty file)
@@ -1,41 +0,0 @@
-import py
-
-class StatRecorder:
- def __init__(self, rootdirlist):
- self.rootdirlist = rootdirlist
- self.statcache = {}
- self.check() # snapshot state
-
- def fil(self, p):
- return p.ext in ('.py', '.txt', '.c', '.h')
- def rec(self, p):
- return p.check(dotfile=0)
-
- def check(self):
- changed = False
- statcache = self.statcache
- newstat = {}
- for rootdir in self.rootdirlist:
- for path in rootdir.visit(self.fil, self.rec):
- oldstat = statcache.get(path, None)
- if oldstat is not None:
- del statcache[path]
- try:
- newstat[path] = curstat = path.stat()
- except py.error.ENOENT:
- if oldstat:
- del statcache[path]
- changed = True
- else:
- if oldstat:
- if oldstat.mtime != curstat.mtime or \
- oldstat.size != curstat.size:
- changed = True
- print "# MODIFIED", path
- else:
- changed = True
- if statcache:
- changed = True
- self.statcache = newstat
- return changed
-
Copied: py/branch/event/py/test2/dsession/looponfailing.py (from r57215, py/branch/event/py/test2/dsession/filechange.py)
==============================================================================
--- py/branch/event/py/test2/dsession/filechange.py (original)
+++ py/branch/event/py/test2/dsession/looponfailing.py Wed Aug 13 10:34:36 2008
@@ -1,4 +1,5 @@
import py
+from py.__.test2 import event
class StatRecorder:
def __init__(self, rootdirlist):
@@ -39,3 +40,19 @@
self.statcache = newstat
return changed
+
+class EventRecorder(object):
+ def __init__(self, bus):
+ self.events = []
+ self.bus = bus
+ self.bus.subscribe(self.events.append)
+
+ def getfailures(self):
+ return [ev for ev in self.events
+ if isinstance(ev, event.BaseReport) and \
+ ev.failed]
+ def clear(self):
+ self.events[:] = []
+
+ def unsubscribe(self):
+ self.bus.unsubscribe(self.events.append)
Deleted: /py/branch/event/py/test2/dsession/testing/test_filechange.py
==============================================================================
--- /py/branch/event/py/test2/dsession/testing/test_filechange.py Wed Aug 13 10:34:36 2008
+++ (empty file)
@@ -1,42 +0,0 @@
-import py
-from py.__.test2.dsession.filechange import StatRecorder
-
-def test_filechange():
- tmp = py.test.ensuretemp("test_filechange")
- hello = tmp.ensure("hello.py")
- sd = StatRecorder([tmp])
- changed = sd.check()
- assert not changed
-
- hello.write("world")
- changed = sd.check()
- assert changed
-
- tmp.ensure("new.py")
- changed = sd.check()
- assert changed
-
- tmp.join("new.py").remove()
- changed = sd.check()
- assert changed
-
- tmp.join("a", "b", "c.py").ensure()
- changed = sd.check()
- assert changed
-
- tmp.join("a", "c.txt").ensure()
- changed = sd.check()
- assert changed
- changed = sd.check()
- assert not changed
-
- tmp.join("a").remove()
- changed = sd.check()
- assert changed
-
-
-
-
-
-
-
Copied: py/branch/event/py/test2/dsession/testing/test_looponfailing.py (from r57215, py/branch/event/py/test2/dsession/testing/test_filechange.py)
==============================================================================
--- py/branch/event/py/test2/dsession/testing/test_filechange.py (original)
+++ py/branch/event/py/test2/dsession/testing/test_looponfailing.py Wed Aug 13 10:34:36 2008
@@ -1,5 +1,6 @@
import py
-from py.__.test2.dsession.filechange import StatRecorder
+from py.__.test2.dsession.looponfailing import StatRecorder, EventRecorder
+from py.__.test2 import event
def test_filechange():
tmp = py.test.ensuretemp("test_filechange")
@@ -34,8 +35,27 @@
changed = sd.check()
assert changed
+def test_eventrecorder():
+ bus = event.EventBus()
+ recorder = EventRecorder(bus)
+ bus.notify(event.NOP())
+ assert recorder.events
+ assert not recorder.getfailures()
+ rep = event.ItemTestReport(None, failed=True)
+ bus.notify(rep)
+ failures = recorder.getfailures()
+ assert failures == [rep]
+ recorder.clear()
+ assert not recorder.events
+ assert not recorder.getfailures()
+ recorder.unsubscribe()
+ bus.notify(rep)
+ assert not recorder.events
+ assert not recorder.getfailures()
+
+
More information about the pytest-commit
mailing list