diff --git a/py/__init__.py b/py/__init__.py index 783640e8e..f04bd67c6 100644 --- a/py/__init__.py +++ b/py/__init__.py @@ -25,8 +25,8 @@ version = "1.0.0b1" initpkg(__name__, description = "pylib and py.test: agile development and test support library", - revision = int('$LastChangedRevision: 63894 $'.split(':')[1][:-1]), - lastchangedate = '$LastChangedDate: 2009-04-09 16:03:09 +0200 (Thu, 09 Apr 2009) $', + revision = int('$LastChangedRevision: 63896 $'.split(':')[1][:-1]), + lastchangedate = '$LastChangedDate: 2009-04-09 16:21:07 +0200 (Thu, 09 Apr 2009) $', version = version, url = "http://pylib.org", download_url = "http://codespeak.net/py/%s/download.html" % version, @@ -70,7 +70,7 @@ initpkg(__name__, # helpers for use from test functions or collectors 'test.__doc__' : ('./test/__init__.py', '__doc__'), - 'test._PluginManager' : ('./test/pytestplugin.py', 'PluginManager'), + 'test._PluginManager' : ('./test/pluginmanager.py', 'PluginManager'), 'test.raises' : ('./test/outcome.py', 'raises'), 'test.mark' : ('./test/outcome.py', 'mark',), 'test.deprecated_call' : ('./test/outcome.py', 'deprecated_call'), @@ -198,7 +198,5 @@ initpkg(__name__, 'compat.subprocess' : ('./compat/subprocess.py', '*'), }) -import py -py._com.comregistry.consider_env() diff --git a/py/_com.py b/py/_com.py index 80efdb139..a42fd56c3 100644 --- a/py/_com.py +++ b/py/_com.py @@ -73,29 +73,6 @@ class Registry: plugins = [] self.plugins = plugins - def import_module(self, modspec): - # XXX allow modspec to specify version / lookup - modpath = modspec - __import__(modpath) - - def consider_env(self): - """ consider ENV variable for loading modules. """ - for spec in self._envlist("PYLIB"): - self.import_module(spec) - - def _envlist(self, varname): - val = py.std.os.environ.get(varname, None) - if val is not None: - return val.split(',') - return () - - def consider_module(self, mod, varname="pylib"): - speclist = getattr(mod, varname, ()) - if not isinstance(speclist, (list, tuple)): - speclist = (speclist,) - for spec in speclist: - self.import_module(spec) - def register(self, plugin): assert not isinstance(plugin, str) self.call_each("pytest_plugin_registered", plugin) @@ -105,12 +82,12 @@ class Registry: self.call_each("pytest_plugin_unregistered", plugin) self.plugins.remove(plugin) - def getplugins(self): - return list(self.plugins) - def isregistered(self, plugin): return plugin in self.plugins + def __iter__(self): + return iter(self.plugins) + def listattr(self, attrname, plugins=None, extra=(), reverse=False): l = [] if plugins is None: diff --git a/py/misc/testing/test_com.py b/py/misc/testing/test_com.py index 26c121c07..50cbe4386 100644 --- a/py/misc/testing/test_com.py +++ b/py/misc/testing/test_com.py @@ -81,21 +81,21 @@ class TestRegistry: assert hasattr(plugins, "MultiCall") def test_register(self): - plugins = Registry() + registry = Registry() class MyPlugin: pass my = MyPlugin() - plugins.register(my) - assert plugins.getplugins() == [my] + registry.register(my) + assert list(registry) == [my] my2 = MyPlugin() - plugins.register(my2) - assert plugins.getplugins() == [my, my2] + registry.register(my2) + assert list(registry) == [my, my2] - assert plugins.isregistered(my) - assert plugins.isregistered(my2) - plugins.unregister(my) - assert not plugins.isregistered(my) - assert plugins.getplugins() == [my2] + assert registry.isregistered(my) + assert registry.isregistered(my2) + registry.unregister(my) + assert not registry.isregistered(my) + assert list(registry) == [my2] def test_call_methods(self): plugins = Registry() @@ -160,35 +160,9 @@ class TestRegistry: l = list(plugins.listattr('x', reverse=True)) assert l == [43, 42, 41] - def test_consider_env(self, monkeypatch): - plugins = Registry() - monkeypatch.setitem(os.environ, 'PYLIB', "unknownconsider_env") - py.test.raises(ImportError, "plugins.consider_env()") - - def test_consider_module(self): - plugins = Registry() - mod = py.std.new.module("temp") - mod.pylib = ["xxx nomod"] - excinfo = py.test.raises(ImportError, "plugins.consider_module(mod)") - mod.pylib = "os" - plugins.consider_module(mod) - def test_api_and_defaults(): assert isinstance(py._com.comregistry, Registry) -def test_subprocess_env(testdir, monkeypatch): - plugins = Registry() - old = py.path.local(py.__file__).dirpath().dirpath().chdir() - try: - monkeypatch.setitem(os.environ, "PYLIB", 'unknownconsider') - excinfo = py.test.raises(py.process.cmdexec.Error, """ - py.process.cmdexec('%s -c "import py"') - """ % py.std.sys.executable) - assert str(excinfo.value).find("ImportError") != -1 - assert str(excinfo.value).find("unknownconsider") != -1 - finally: - old.chdir() - class TestPluginAPI: def test_happypath(self): plugins = Registry() diff --git a/py/test/pytestplugin.py b/py/test/pluginmanager.py similarity index 94% rename from py/test/pytestplugin.py rename to py/test/pluginmanager.py index f7e94fcc9..bce60ea86 100644 --- a/py/test/pytestplugin.py +++ b/py/test/pluginmanager.py @@ -24,16 +24,22 @@ class PluginManager(object): return self.comregistry.isregistered(plugin) def getplugins(self): - return self.comregistry.getplugins() + return self.comregistry.plugins # API for bootstrapping # def getplugin(self, importname): impname, clsname = canonical_names(importname) return self.plugins[impname] + + def _envlist(self, varname): + val = py.std.os.environ.get(varname, None) + if val is not None: + return val.split(',') + return () def consider_env(self): - for spec in self.comregistry._envlist("PYTEST_PLUGINS"): + for spec in self._envlist("PYTEST_PLUGINS"): self.import_plugin(spec) def consider_conftest(self, conftestmodule): diff --git a/py/test/testing/test_pytestplugin.py b/py/test/testing/test_pluginmanager.py similarity index 97% rename from py/test/testing/test_pytestplugin.py rename to py/test/testing/test_pluginmanager.py index 8570e9cda..e1e1c11ce 100644 --- a/py/test/testing/test_pytestplugin.py +++ b/py/test/testing/test_pluginmanager.py @@ -1,6 +1,6 @@ import py, os -from py.__.test.pytestplugin import PluginManager, canonical_names -from py.__.test.pytestplugin import registerplugin, importplugin +from py.__.test.pluginmanager import PluginManager, canonical_names +from py.__.test.pluginmanager import registerplugin, importplugin class TestBootstrapping: def test_consider_env_fails_to_import(self, monkeypatch): @@ -22,7 +22,7 @@ class TestBootstrapping: l3 = len(plugins.getplugins()) assert l2 == l3 - def test_pytestplugin_ENV_startup(self, testdir, monkeypatch): + def test_pluginmanager_ENV_startup(self, testdir, monkeypatch): x500 = testdir.makepyfile(pytest_x500="class X500Plugin: pass") p = testdir.makepyfile(""" import py