[py-svn] r56784 - py/branch/event/py/test2/testing

hpk at codespeak.net hpk at codespeak.net
Fri Jul 25 15:06:01 CEST 2008


Author: hpk
Date: Fri Jul 25 15:06:00 2008
New Revision: 56784

Modified:
   py/branch/event/py/test2/testing/suptest.py
   py/branch/event/py/test2/testing/test_runner.py
Log:
recover some help machinery for tests 


Modified: py/branch/event/py/test2/testing/suptest.py
==============================================================================
--- py/branch/event/py/test2/testing/suptest.py	(original)
+++ py/branch/event/py/test2/testing/suptest.py	Fri Jul 25 15:06:00 2008
@@ -126,3 +126,44 @@
     assert len(failevents) == 1
     return failevents[0],tfile
 
+
+# XXX below some code to help with inlining examples 
+#     as source code.  
+ 
+class XXXBaseInlineCollectionTests:
+    
+    def setup_method(self, method):
+        self.tmpdir = tmpdir.join("%s_%s_%s" % 
+            (__name__, self.__class__.__name__, method.__name__))
+
+    def getmodulecol(self, func, funcname="testfunc"):
+        funcname = getattr(func, '__name__', funcname)
+        self.tmpdir.ensure("__init__.py")
+        path = self.tmpdir.ensure(funcname + ".py")
+        path.write(py.code.Source(func))
+        self.config = py.test2.config._reparse([path.dirpath()])
+        modulecol = self.config._getcollector(path)
+        return modulecol
+
+    def makeitem(self, source, funcname="testfunc"):
+        modulecol = self.getmodulecol(source)
+        item = modulecol.join(funcname) 
+        assert item is not None, (item, funcname) 
+        return item 
+
+    def getitems(self, source):
+        modulecol = self.getmodulecol(source)
+        return [modulecol.join(x) for x in modulecol.listdir()]
+
+    def runtestfunc(self, func, funcname="testfunc"):
+        item = self.makeitem(func, funcname=funcname)
+        runner = self.getrunner()
+        return runner(item)
+
+    def exampleusage(self):
+        testrep = self.runtestfunc("""
+            def testfunc():
+                pass
+        """)
+        assert testrep.passed 
+       

Modified: py/branch/event/py/test2/testing/test_runner.py
==============================================================================
--- py/branch/event/py/test2/testing/test_runner.py	(original)
+++ py/branch/event/py/test2/testing/test_runner.py	Fri Jul 25 15:06:00 2008
@@ -3,7 +3,6 @@
 from py.__.test2 import runner
 from py.__.test2.outcome import Exit
 from py.__.test2 import pypresent
-from py.__.test2 import mock 
 
 class MockItem:
     def __init__(self, func):



More information about the pytest-commit mailing list