[py-svn] r63911 - in py/trunk/py/test: . plugin testing

hpk at codespeak.net hpk at codespeak.net
Thu Apr 9 20:40:00 CEST 2009


Author: hpk
Date: Thu Apr  9 20:39:59 2009
New Revision: 63911

Modified:
   py/trunk/py/test/collect.py
   py/trunk/py/test/plugin/api.py
   py/trunk/py/test/plugin/pytest__pytest.py
   py/trunk/py/test/pluginmanager.py
   py/trunk/py/test/testing/test_pluginmanager.py
Log:
striking unneeded call_each from pluginmanager


Modified: py/trunk/py/test/collect.py
==============================================================================
--- py/trunk/py/test/collect.py	(original)
+++ py/trunk/py/test/collect.py	Thu Apr  9 20:39:59 2009
@@ -443,8 +443,7 @@
     def consider_dir(self, path, usefilters=None):
         if usefilters is not None:
             APIWARN("0.99", "usefilters argument not needed")
-        res = self.config.pluginmanager.call_firstresult(
-            'pytest_collect_recurse', path=path, parent=self)
+        res = self.config.api.pytest_collect_recurse(path=path, parent=self)
         if res is None or res:
             return self.config.api.pytest_collect_directory(
                 path=path, parent=self)

Modified: py/trunk/py/test/plugin/api.py
==============================================================================
--- py/trunk/py/test/plugin/api.py	(original)
+++ py/trunk/py/test/plugin/api.py	Thu Apr  9 20:39:59 2009
@@ -44,6 +44,7 @@
         """ return True/False to cause/prevent recursion into given directory. 
             return None if you do not want to make the decision. 
         """ 
+    pytest_collect_recurse.firstresult = True
 
     def pytest_collect_directory(self, path, parent):
         """ return Collection node or None. """

Modified: py/trunk/py/test/plugin/pytest__pytest.py
==============================================================================
--- py/trunk/py/test/plugin/pytest__pytest.py	(original)
+++ py/trunk/py/test/plugin/pytest__pytest.py	Thu Apr  9 20:39:59 2009
@@ -106,7 +106,7 @@
         def xyz(self, arg):
             pass
     rec.start_recording(ApiClass)
-    comregistry.call_each("xyz", 123)
+    rec.api.xyz(arg=123)
     call = rec.popcall("xyz")
     assert call.arg == 123 
     assert call._name == "xyz"
@@ -124,7 +124,7 @@
                 def xyz(self, arg):
                     return arg + 1
             rec._comregistry.register(Plugin())
-            res = rec._comregistry.call_firstresult("xyz", 41)
-            assert res == 42
+            res = rec.api.xyz(arg=41)
+            assert res == [42]
     """)
     sorter.assertoutcome(passed=1)

Modified: py/trunk/py/test/pluginmanager.py
==============================================================================
--- py/trunk/py/test/pluginmanager.py	(original)
+++ py/trunk/py/test/pluginmanager.py	Thu Apr  9 20:39:59 2009
@@ -79,16 +79,12 @@
         for x in self.comregistry.listattr(attrname):
             return x
 
-    def listattr(self, attrname):
-        return self.comregistry.listattr(attrname)
+    def listattr(self, attrname, plugins=None):
+        return self.comregistry.listattr(attrname, plugins=plugins)
 
     def call_firstresult(self, *args, **kwargs):
         return self.comregistry.call_firstresult(*args, **kwargs)
 
-    def call_each(self, *args, **kwargs):
-        #print "plugins.call_each", args[0], args[1:], kwargs
-        return self.comregistry.call_each(*args, **kwargs)
-
     def notify_exception(self, excinfo=None):
         if excinfo is None:
             excinfo = py.code.ExceptionInfo()
@@ -102,8 +98,12 @@
 
     def pytest_plugin_registered(self, plugin):
         if hasattr(self, '_config'):
-            self.comregistry.call_plugin(plugin, "pytest_addoption", parser=self._config._parser)
-            self.comregistry.call_plugin(plugin, "pytest_configure", config=self._config)
+            self.call_plugin(plugin, "pytest_addoption", parser=self._config._parser)
+            self.call_plugin(plugin, "pytest_configure", config=self._config)
+
+    def call_plugin(self, plugin, methname, **kwargs):
+        return self.MultiCall(self.listattr(methname, plugins=[plugin]), 
+                **kwargs).execute(firstresult=True)
 
     def do_configure(self, config):
         assert not hasattr(self, '_config')

Modified: py/trunk/py/test/testing/test_pluginmanager.py
==============================================================================
--- py/trunk/py/test/testing/test_pluginmanager.py	(original)
+++ py/trunk/py/test/testing/test_pluginmanager.py	Thu Apr  9 20:39:59 2009
@@ -172,12 +172,9 @@
     def test_configure(self, testdir):
         config = testdir.parseconfig()
         l = []
-        events = []
         class A:
             def pytest_configure(self, config):
                 l.append(self)
-            def xyz(self, obj):
-                events.append(obj)
                 
         config.pluginmanager.register(A())
         assert len(l) == 0
@@ -186,11 +183,7 @@
         config.pluginmanager.register(A())  # this should lead to a configured() plugin
         assert len(l) == 2
         assert l[0] != l[1]
-        
-        config.pluginmanager.call_each("xyz", obj=42)
-        assert len(events) == 2
-        assert events == [42,42]
-
+       
         config.pluginmanager.do_unconfigure(config=config)
         config.pluginmanager.register(A())
         assert len(l) == 2
@@ -209,16 +202,6 @@
         pluginmanager.register(My1())
         assert pluginmanager.getfirst("x") == 1
 
-    def test_call_each(self):
-        pluginmanager = PluginManager()
-        class My:
-            def method(self, arg):
-                pass
-        pluginmanager.register(My())
-        py.test.raises(TypeError, 'pluginmanager.call_each("method")')
-        l = pluginmanager.call_each("method", arg=42)
-        assert l == []
-        py.test.raises(TypeError, 'pluginmanager.call_each("method", arg=42, s=13)')
 
     def test_call_firstresult(self):
         pluginmanager = PluginManager()



More information about the pytest-commit mailing list