[py-svn] r56912 - in py/branch/event/py/test2: . rep/testing rsession testing

hpk at codespeak.net hpk at codespeak.net
Sat Aug 2 10:34:14 CEST 2008


Author: hpk
Date: Sat Aug  2 10:34:13 2008
New Revision: 56912

Modified:
   py/branch/event/py/test2/collect.py
   py/branch/event/py/test2/config.py
   py/branch/event/py/test2/item.py
   py/branch/event/py/test2/rep/testing/test_terminal.py
   py/branch/event/py/test2/rsession/slave.py
   py/branch/event/py/test2/session.py
   py/branch/event/py/test2/testing/test_collect.py
Log:
remove another kitchen-sink attribute of config,
put "setupstate" to collection nodes.  


Modified: py/branch/event/py/test2/collect.py
==============================================================================
--- py/branch/event/py/test2/collect.py	(original)
+++ py/branch/event/py/test2/collect.py	Sat Aug  2 10:34:13 2008
@@ -33,11 +33,42 @@
         return self._config.getvalue(name, self.fspath) 
     return property(fget)
 
+class SetupState(object):
+    """ shared state for setting up/tearing down tests. """
+    def __init__(self):
+        self.stack = []
+
+    def teardown_all(self): 
+        while self.stack: 
+            col = self.stack.pop() 
+            col.teardown() 
+
+    def teardown_exact(self, item):
+        if self.stack[-1] == item:
+            col = self.stack.pop()
+            col.teardown()
+     
+    def prepare(self, colitem): 
+        """ setup objects along the collector chain to the test-method
+            Teardown any unneccessary previously setup objects."""
+
+        needed_collectors = colitem.listchain() 
+        while self.stack: 
+            if self.stack == needed_collectors[:len(self.stack)]: 
+                break 
+            col = self.stack.pop() 
+            col.teardown()
+        for col in needed_collectors[len(self.stack):]: 
+            #print "setting up", col
+            col.setup() 
+            self.stack.append(col) 
+
 class Node(object): 
     """ base class for Nodes in the collection tree.  
         Nodes with Children are "Collectors" and 
         leaves are runnable Test Items.  
     """
+    _setupstate = SetupState() 
     def __init__(self, name, parent=None, config=None):
         self.name = name 
         self.parent = parent
@@ -462,11 +493,12 @@
         itemlist = self._name2items
         return [itemlist["[%d]" % num].name for num in xrange(len(itemlist))]
     
-    def _buildname2items(self): 
+    def _buildname2items(self):
         d = {} 
-        # test generators participate in 
-        # the setup and teardown protocol 
-        self._config._setupstate.prepare(self)
+        # XXX test generators are collectors yet participate in 
+        # the test-item setup and teardown protocol 
+        # if not for this we could probably avoid global setupstate
+        self._setupstate.prepare(self) 
         for i, x in py.builtin.enumerate(self.obj()): 
             call, args = self.getcallargs(x)
             if not callable(call): 

Modified: py/branch/event/py/test2/config.py
==============================================================================
--- py/branch/event/py/test2/config.py	(original)
+++ py/branch/event/py/test2/config.py	Sat Aug  2 10:34:13 2008
@@ -4,7 +4,6 @@
 from conftesthandle import Conftest
 from py.__.test2.defaultconftest import adddefaultoptions
 from py.__.test2.eventbus import EventBus
-from py.__.test2.item import SetupState
 
 optparse = py.compat.optparse
 
@@ -36,7 +35,6 @@
             usage="usage: %prog [options] [query] [filenames of tests]")
         self._conftest = Conftest()
         self._initialized = False
-        self._setupstate = SetupState()
 
     def __getstate__(self):
         return self._makerepr([])

Modified: py/branch/event/py/test2/item.py
==============================================================================
--- py/branch/event/py/test2/item.py	(original)
+++ py/branch/event/py/test2/item.py	Sat Aug  2 10:34:13 2008
@@ -5,36 +5,6 @@
 
 _dummy = object()
 
-class SetupState(object):
-    """ shared state for setting up/tearing down tests. """
-    def __init__(self):
-        self.stack = []
-
-    def teardown_all(self): 
-        while self.stack: 
-            col = self.stack.pop() 
-            col.teardown() 
-
-    def teardown_exact(self, item):
-        if self.stack[-1] == item:
-            col = self.stack.pop()
-            col.teardown()
-     
-    def prepare(self, colitem): 
-        """ setup objects along the collector chain to the test-method
-            Teardown any unneccessary previously setup objects."""
-
-        needed_collectors = colitem.listchain() 
-        while self.stack: 
-            if self.stack == needed_collectors[:len(self.stack)]: 
-                break 
-            col = self.stack.pop() 
-            col.teardown()
-        for col in needed_collectors[len(self.stack):]: 
-            #print "setting up", col
-            col.setup() 
-            self.stack.append(col) 
-
 class Item(Node): 
     def repr_path(self):
         """ return (filepath, testpath) tuple with

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  2 10:34:13 2008
@@ -30,7 +30,7 @@
         rep = TerminalReporter(modcol._config, file=stringio)
         for item in self.session.genitems([modcol]):
             ev = basic_run_report(item, 
-                 setupstate=modcol._config._setupstate, 
+                 setupstate=modcol._setupstate, 
                  getcapture=modcol._config._getcapture
             )
             rep.processevent(ev)

Modified: py/branch/event/py/test2/rsession/slave.py
==============================================================================
--- py/branch/event/py/test2/rsession/slave.py	(original)
+++ py/branch/event/py/test2/rsession/slave.py	Sat Aug  2 10:34:13 2008
@@ -36,6 +36,6 @@
             break
         item = config._getcollector(itemspec) 
         runner = item._getrunner()
-        testrep = runner(item, item._config._setupstate, item._config._getcapture)
+        testrep = runner(item, item._setupstate, item._config._getcapture)
         send(testrep.dumps()) 
 

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  2 10:34:13 2008
@@ -89,7 +89,7 @@
 
     def sessionfinishes(self):
         """ teardown any resources after a test run. """ 
-        self.config._setupstate.teardown_all() # xxx this can raise exceptions! 
+        py.test2.collect.Item._setupstate.teardown_all() # this can raise exceptions!
         if not self.config.option.nomagic:
             py.magic.revoke(assertion=1)
         self.bus.notify(repevent.SessionFinish(self))
@@ -120,7 +120,7 @@
         runner = item._getrunner()
         pdb = self.config.option.usepdb and self.runpdb or None
         return runner(item, 
-                      setupstate=item._config._setupstate, 
-                      getcapture=item._config._getcapture,
+                      setupstate=item._setupstate, 
+                      getcapture=self.config._getcapture,
                       pdb=pdb)
 

Modified: py/branch/event/py/test2/testing/test_collect.py
==============================================================================
--- py/branch/event/py/test2/testing/test_collect.py	(original)
+++ py/branch/event/py/test2/testing/test_collect.py	Sat Aug  2 10:34:13 2008
@@ -4,7 +4,7 @@
 from py.__.test2.doctest import DoctestText
 import setupdata, suptest
 from py.__.test2.conftesthandle import Conftest
-from py.__.test2.item import SetupState
+from py.__.test2.collect import SetupState
 
 class DummyConfig:
     def __init__(self):



More information about the pytest-commit mailing list