[svn r63896] more renames, killing redundant code

--HG--
branch : trunk
This commit is contained in:
hpk 2009-04-09 16:21:07 +02:00
parent 5d271b2bde
commit a4863c3f7b
5 changed files with 27 additions and 72 deletions

View File

@ -25,8 +25,8 @@ version = "1.0.0b1"
initpkg(__name__, initpkg(__name__,
description = "pylib and py.test: agile development and test support library", description = "pylib and py.test: agile development and test support library",
revision = int('$LastChangedRevision: 63894 $'.split(':')[1][:-1]), revision = int('$LastChangedRevision: 63896 $'.split(':')[1][:-1]),
lastchangedate = '$LastChangedDate: 2009-04-09 16:03:09 +0200 (Thu, 09 Apr 2009) $', lastchangedate = '$LastChangedDate: 2009-04-09 16:21:07 +0200 (Thu, 09 Apr 2009) $',
version = version, version = version,
url = "http://pylib.org", url = "http://pylib.org",
download_url = "http://codespeak.net/py/%s/download.html" % version, download_url = "http://codespeak.net/py/%s/download.html" % version,
@ -70,7 +70,7 @@ initpkg(__name__,
# helpers for use from test functions or collectors # helpers for use from test functions or collectors
'test.__doc__' : ('./test/__init__.py', '__doc__'), '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.raises' : ('./test/outcome.py', 'raises'),
'test.mark' : ('./test/outcome.py', 'mark',), 'test.mark' : ('./test/outcome.py', 'mark',),
'test.deprecated_call' : ('./test/outcome.py', 'deprecated_call'), 'test.deprecated_call' : ('./test/outcome.py', 'deprecated_call'),
@ -198,7 +198,5 @@ initpkg(__name__,
'compat.subprocess' : ('./compat/subprocess.py', '*'), 'compat.subprocess' : ('./compat/subprocess.py', '*'),
}) })
import py
py._com.comregistry.consider_env()

View File

@ -73,29 +73,6 @@ class Registry:
plugins = [] plugins = []
self.plugins = 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): def register(self, plugin):
assert not isinstance(plugin, str) assert not isinstance(plugin, str)
self.call_each("pytest_plugin_registered", plugin) self.call_each("pytest_plugin_registered", plugin)
@ -105,12 +82,12 @@ class Registry:
self.call_each("pytest_plugin_unregistered", plugin) self.call_each("pytest_plugin_unregistered", plugin)
self.plugins.remove(plugin) self.plugins.remove(plugin)
def getplugins(self):
return list(self.plugins)
def isregistered(self, plugin): def isregistered(self, plugin):
return plugin in self.plugins return plugin in self.plugins
def __iter__(self):
return iter(self.plugins)
def listattr(self, attrname, plugins=None, extra=(), reverse=False): def listattr(self, attrname, plugins=None, extra=(), reverse=False):
l = [] l = []
if plugins is None: if plugins is None:

View File

@ -81,21 +81,21 @@ class TestRegistry:
assert hasattr(plugins, "MultiCall") assert hasattr(plugins, "MultiCall")
def test_register(self): def test_register(self):
plugins = Registry() registry = Registry()
class MyPlugin: class MyPlugin:
pass pass
my = MyPlugin() my = MyPlugin()
plugins.register(my) registry.register(my)
assert plugins.getplugins() == [my] assert list(registry) == [my]
my2 = MyPlugin() my2 = MyPlugin()
plugins.register(my2) registry.register(my2)
assert plugins.getplugins() == [my, my2] assert list(registry) == [my, my2]
assert plugins.isregistered(my) assert registry.isregistered(my)
assert plugins.isregistered(my2) assert registry.isregistered(my2)
plugins.unregister(my) registry.unregister(my)
assert not plugins.isregistered(my) assert not registry.isregistered(my)
assert plugins.getplugins() == [my2] assert list(registry) == [my2]
def test_call_methods(self): def test_call_methods(self):
plugins = Registry() plugins = Registry()
@ -160,35 +160,9 @@ class TestRegistry:
l = list(plugins.listattr('x', reverse=True)) l = list(plugins.listattr('x', reverse=True))
assert l == [43, 42, 41] 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(): def test_api_and_defaults():
assert isinstance(py._com.comregistry, Registry) 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: class TestPluginAPI:
def test_happypath(self): def test_happypath(self):
plugins = Registry() plugins = Registry()

View File

@ -24,16 +24,22 @@ class PluginManager(object):
return self.comregistry.isregistered(plugin) return self.comregistry.isregistered(plugin)
def getplugins(self): def getplugins(self):
return self.comregistry.getplugins() return self.comregistry.plugins
# API for bootstrapping # API for bootstrapping
# #
def getplugin(self, importname): def getplugin(self, importname):
impname, clsname = canonical_names(importname) impname, clsname = canonical_names(importname)
return self.plugins[impname] 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): def consider_env(self):
for spec in self.comregistry._envlist("PYTEST_PLUGINS"): for spec in self._envlist("PYTEST_PLUGINS"):
self.import_plugin(spec) self.import_plugin(spec)
def consider_conftest(self, conftestmodule): def consider_conftest(self, conftestmodule):

View File

@ -1,6 +1,6 @@
import py, os import py, os
from py.__.test.pytestplugin import PluginManager, canonical_names from py.__.test.pluginmanager import PluginManager, canonical_names
from py.__.test.pytestplugin import registerplugin, importplugin from py.__.test.pluginmanager import registerplugin, importplugin
class TestBootstrapping: class TestBootstrapping:
def test_consider_env_fails_to_import(self, monkeypatch): def test_consider_env_fails_to_import(self, monkeypatch):
@ -22,7 +22,7 @@ class TestBootstrapping:
l3 = len(plugins.getplugins()) l3 = len(plugins.getplugins())
assert l2 == l3 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") x500 = testdir.makepyfile(pytest_x500="class X500Plugin: pass")
p = testdir.makepyfile(""" p = testdir.makepyfile("""
import py import py