[pypy-svn] r74323 - in pypy/branch/py12: py py/_plugin py/_test pypy pypy/translator/benchmark

hpk at codespeak.net hpk at codespeak.net
Sun May 2 16:39:34 CEST 2010


Author: hpk
Date: Sun May  2 16:39:33 2010
New Revision: 74323

Modified:
   pypy/branch/py12/py/__init__.py
   pypy/branch/py12/py/_plugin/hookspec.py
   pypy/branch/py12/py/_plugin/pytest_default.py
   pypy/branch/py12/py/_test/cmdline.py
   pypy/branch/py12/py/_test/collect.py
   pypy/branch/py12/py/_test/pluginmanager.py
   pypy/branch/py12/pypy/conftest.py
   pypy/branch/py12/pypy/translator/benchmark/conftest.py
Log:
copy again from py-trunk, now to be released as 1.3.0 because of the new hooks
that were introduced to ease pypy porting 


Modified: pypy/branch/py12/py/__init__.py
==============================================================================
--- pypy/branch/py12/py/__init__.py	(original)
+++ pypy/branch/py12/py/__init__.py	Sun May  2 16:39:33 2010
@@ -8,7 +8,7 @@
 
 (c) Holger Krekel and others, 2004-2010
 """
-__version__ = version = "1.2.2"
+__version__ = version = "1.3.0"
 
 import py.apipkg
 

Modified: pypy/branch/py12/py/_plugin/hookspec.py
==============================================================================
--- pypy/branch/py12/py/_plugin/hookspec.py	(original)
+++ pypy/branch/py12/py/_plugin/hookspec.py	Sun May  2 16:39:33 2010
@@ -6,14 +6,14 @@
 # Command line and configuration 
 # -------------------------------------------------------------------------
 
-def pytest_addoption(parser):
-    """ called before commandline parsing.  """
+def pytest_namespace():
+    "return dict of name->object which will get stored at py.test. namespace"
 
-def pytest_registerhooks(pluginmanager):
-    """ called after commandline parsing before pytest_configure.  """
+def pytest_addoption(parser):
+    "add optparse-style options via parser.addoption."
 
-def pytest_namespace():
-    """ return dict of name->object which will get stored at py.test. namespace"""
+def pytest_addhooks(pluginmanager):
+    "add hooks via pluginmanager.registerhooks(module)"
 
 def pytest_configure(config):
     """ called after command line options have been parsed. 
@@ -27,12 +27,12 @@
 # collection hooks
 # -------------------------------------------------------------------------
 
-def pytest_ignore_collect_path(path, config):
+def pytest_ignore_collect(path, config):
     """ return true value to prevent considering this path for collection. 
     This hook is consulted for all files and directories prior to considering
     collection hooks. 
     """
-pytest_ignore_collect_path.firstresult = True
+pytest_ignore_collect.firstresult = True
 
 def pytest_collect_directory(path, parent):
     """ return Collection node or None for the given path. """

Modified: pypy/branch/py12/py/_plugin/pytest_default.py
==============================================================================
--- pypy/branch/py12/py/_plugin/pytest_default.py	(original)
+++ pypy/branch/py12/py/_plugin/pytest_default.py	Sun May  2 16:39:33 2010
@@ -28,7 +28,7 @@
     """ the pytest config object with access to command line opts."""
     return request.config
 
-def pytest_ignore_collect_path(path, config):
+def pytest_ignore_collect(path, config):
     ignore_paths = config.getconftest_pathlist("collect_ignore", path=path) 
     ignore_paths = ignore_paths or []
     excludeopt = config.getvalue("ignore")

Modified: pypy/branch/py12/py/_test/cmdline.py
==============================================================================
--- pypy/branch/py12/py/_test/cmdline.py	(original)
+++ pypy/branch/py12/py/_test/cmdline.py	Sun May  2 16:39:33 2010
@@ -21,4 +21,3 @@
         e = sys.exc_info()[1]
         sys.stderr.write("ERROR: %s\n" %(e.args[0],))
         raise SystemExit(3)
-

Modified: pypy/branch/py12/py/_test/collect.py
==============================================================================
--- pypy/branch/py12/py/_test/collect.py	(original)
+++ pypy/branch/py12/py/_test/collect.py	Sun May  2 16:39:33 2010
@@ -297,7 +297,7 @@
         return l
 
     def consider(self, path):
-        if self.ihook.pytest_ignore_collect_path(path=path, config=self.config):
+        if self.ihook.pytest_ignore_collect(path=path, config=self.config):
            return
         if path.check(file=1):
             res = self.consider_file(path)

Modified: pypy/branch/py12/py/_test/pluginmanager.py
==============================================================================
--- pypy/branch/py12/py/_test/pluginmanager.py	(original)
+++ pypy/branch/py12/py/_test/pluginmanager.py	Sun May  2 16:39:33 2010
@@ -39,8 +39,7 @@
         if name in self._name2plugin:
             return False
         self._name2plugin[name] = plugin
-        self.call_plugin(plugin, "pytest_registerhooks", 
-            {'pluginmanager': self})
+        self.call_plugin(plugin, "pytest_addhooks", {'pluginmanager': self})
         self.hook.pytest_plugin_registered(manager=self, plugin=plugin)
         self.registry.register(plugin)
         return True
@@ -59,8 +58,8 @@
             if plugin == val:
                 return True
 
-    def registerhooks(self, spec):
-        self.hook._registerhooks(spec)
+    def addhooks(self, spec):
+        self.hook._addhooks(spec, prefix="pytest_")
 
     def getplugins(self):
         return list(self.registry)
@@ -304,22 +303,31 @@
         return l
 
 class HookRelay: 
-    def __init__(self, hookspecs, registry):
+    def __init__(self, hookspecs, registry, prefix="pytest_"):
         if not isinstance(hookspecs, list):
             hookspecs = [hookspecs]
         self._hookspecs = []
         self._registry = registry
         for hookspec in hookspecs:
-            self._registerhooks(hookspec)
+            self._addhooks(hookspec, prefix)
 
-    def _registerhooks(self, hookspecs):
+    def _addhooks(self, hookspecs, prefix):
         self._hookspecs.append(hookspecs)
+        added = False
         for name, method in vars(hookspecs).items():
-            if name[:1] != "_":
+            if name.startswith(prefix):
+                if not method.__doc__:
+                    raise ValueError("docstring required for hook %r, in %r"
+                        % (method, hookspecs))
                 firstresult = getattr(method, 'firstresult', False)
                 hc = HookCaller(self, name, firstresult=firstresult)
                 setattr(self, name, hc)
+                added = True
                 #print ("setting new hook", name)
+        if not added:
+            raise ValueError("did not find new %r hooks in %r" %(
+                prefix, hookspecs,))
+            
 
     def _performcall(self, name, multicall):
         return multicall.execute()

Modified: pypy/branch/py12/pypy/conftest.py
==============================================================================
--- pypy/branch/py12/pypy/conftest.py	(original)
+++ pypy/branch/py12/pypy/conftest.py	Sun May  2 16:39:33 2010
@@ -515,5 +515,5 @@
             py.test.skip("pexpect not found")
 
 
-def pytest_ignore_collect_path(path):
+def pytest_ignore_collect(path):
     return path.check(link=1)

Modified: pypy/branch/py12/pypy/translator/benchmark/conftest.py
==============================================================================
--- pypy/branch/py12/pypy/translator/benchmark/conftest.py	(original)
+++ pypy/branch/py12/pypy/translator/benchmark/conftest.py	Sun May  2 16:39:33 2010
@@ -1,4 +1,4 @@
 import py
 
-def pytest_ignore_collect_path(path):
+def pytest_ignore_collect(path):
     return path.basename == "test"



More information about the Pypy-commit mailing list