using apipkg 1.0b2 snapshot version - adjusting/cleaning up some impl-detail accesses
--HG-- branch : trunk
This commit is contained in:
parent
cc3404b832
commit
33bd39053f
|
@ -0,0 +1,5 @@
|
|||
|
||||
import py
|
||||
import _py
|
||||
|
||||
impldir = py.path.local(_py.__file__).dirpath()
|
|
@ -5,18 +5,21 @@ see http://pypi.python.org/pypi/apipkg
|
|||
|
||||
(c) holger krekel, 2009 - MIT license
|
||||
"""
|
||||
import os, sys
|
||||
import sys
|
||||
from types import ModuleType
|
||||
|
||||
__version__ = "1.0b1"
|
||||
__version__ = "1.0b2"
|
||||
|
||||
def initpkg(pkgname, exportdefs):
|
||||
""" initialize given package from the export definitions. """
|
||||
pkgmodule = sys.modules[pkgname]
|
||||
""" initialize given package from the export definitions.
|
||||
replace it in sys.modules
|
||||
"""
|
||||
mod = ApiModule(pkgname, exportdefs)
|
||||
for name, value in mod.__dict__.items():
|
||||
if name[:2] != "__" or name == "__all__":
|
||||
setattr(pkgmodule, name, value)
|
||||
oldmod = sys.modules[pkgname]
|
||||
mod.__file__ = getattr(oldmod, '__file__', None)
|
||||
mod.__version__ = getattr(oldmod, '__version__', None)
|
||||
mod.__path__ = getattr(oldmod, '__path__', None)
|
||||
sys.modules[pkgname] = mod
|
||||
|
||||
def importobj(importspec):
|
||||
""" return object specified by importspec."""
|
||||
|
@ -29,26 +32,24 @@ class ApiModule(ModuleType):
|
|||
self.__name__ = name
|
||||
self.__all__ = list(importspec)
|
||||
self.__map__ = {}
|
||||
if parent:
|
||||
fullname = parent.__fullname__ + "." + name
|
||||
setattr(parent, name, self)
|
||||
else:
|
||||
fullname = name
|
||||
self.__fullname__ = fullname
|
||||
for name, importspec in importspec.items():
|
||||
if isinstance(importspec, dict):
|
||||
apimod = ApiModule(name, importspec, parent=self)
|
||||
sys.modules[apimod.__fullname__] = apimod
|
||||
package = '%s.%s'%(self.__name__, name)
|
||||
apimod = ApiModule(package, importspec, parent=self)
|
||||
sys.modules[package] = apimod
|
||||
setattr(self, name, apimod)
|
||||
else:
|
||||
if not importspec.count(":") == 1:
|
||||
raise ValueError("invalid importspec %r" % (importspec,))
|
||||
if name == '__doc__':
|
||||
self.__doc__ = importobj(importspec)
|
||||
else:
|
||||
if importspec[0] == '.':
|
||||
importspec = self.__name__ + importspec
|
||||
self.__map__[name] = importspec
|
||||
|
||||
def __repr__(self):
|
||||
return '<ApiModule %r>' % (self.__fullname__,)
|
||||
return '<ApiModule %r>' % (self.__name__,)
|
||||
|
||||
def __getattr__(self, name):
|
||||
try:
|
||||
|
|
|
@ -4,7 +4,6 @@ Collectors and test Items form a tree
|
|||
that is usually built iteratively.
|
||||
"""
|
||||
import py
|
||||
pydir = py.path.local(py._py.__file__).dirpath()
|
||||
|
||||
def configproperty(name):
|
||||
def fget(self):
|
||||
|
@ -336,7 +335,7 @@ class Collector(Node):
|
|||
path = self.fspath
|
||||
ntraceback = traceback.cut(path=self.fspath)
|
||||
if ntraceback == traceback:
|
||||
ntraceback = ntraceback.cut(excludepath=pydir)
|
||||
ntraceback = ntraceback.cut(excludepath=py._impldir)
|
||||
traceback = ntraceback.filter()
|
||||
return traceback
|
||||
|
||||
|
|
|
@ -261,8 +261,8 @@ class Config(object):
|
|||
conftestroots = config.getconftest_pathlist("rsyncdirs")
|
||||
if conftestroots:
|
||||
roots.extend(conftestroots)
|
||||
pydirs = [py.path.local(x).dirpath()
|
||||
for x in (py.__file__, py._py.__file__)]
|
||||
pydirs = [py.path.local(py.__file__).dirpath(),
|
||||
py._impldir]
|
||||
roots = [py.path.local(root) for root in roots]
|
||||
for root in roots:
|
||||
if not root.check():
|
||||
|
|
|
@ -175,7 +175,7 @@ class ReSTSyntaxTest(py.test.collect.Item):
|
|||
'to the py package') % (text,)
|
||||
relpath = '/'.join(text.split('/')[1:])
|
||||
if check:
|
||||
pkgroot = py.path.local(py._py.__file__).dirpath()
|
||||
pkgroot = py._impldir
|
||||
abspath = pkgroot.join(relpath)
|
||||
assert pkgroot.join(relpath).check(), (
|
||||
'problem with linkrole :source:`%s`: '
|
||||
|
|
|
@ -19,7 +19,6 @@ a tree of collectors and test items that this modules provides::
|
|||
import py
|
||||
import inspect
|
||||
from _py.test.collect import configproperty, warnoldcollect
|
||||
pydir = py.path.local(py._py.__file__).dirpath()
|
||||
from _py.test import funcargs
|
||||
|
||||
class PyobjMixin(object):
|
||||
|
@ -258,7 +257,7 @@ class FunctionMixin(PyobjMixin):
|
|||
if ntraceback == traceback:
|
||||
ntraceback = ntraceback.cut(path=path)
|
||||
if ntraceback == traceback:
|
||||
ntraceback = ntraceback.cut(excludepath=pydir)
|
||||
ntraceback = ntraceback.cut(excludepath=py._impldir)
|
||||
traceback = ntraceback.filter()
|
||||
return traceback
|
||||
|
||||
|
|
|
@ -26,6 +26,9 @@ _py.apipkg.initpkg(__name__, dict(
|
|||
# access to all posix errno's as classes
|
||||
error = '_py.error:error',
|
||||
|
||||
_impldir = '_py._metainfo:impldir',
|
||||
version = 'py:__version__', # backward compatibility
|
||||
|
||||
_com = {
|
||||
'Registry': '_py._com:Registry',
|
||||
'MultiCall': '_py._com:MultiCall',
|
||||
|
|
|
@ -112,7 +112,7 @@ class TestTraceback_f_g_h:
|
|||
def test_traceback_cut_excludepath(self, testdir):
|
||||
p = testdir.makepyfile("def f(): raise ValueError")
|
||||
excinfo = py.test.raises(ValueError, "p.pyimport().f()")
|
||||
basedir = py.path.local(py._py.__file__).dirpath()
|
||||
basedir = py._impldir
|
||||
newtraceback = excinfo.traceback.cut(excludepath=basedir)
|
||||
assert len(newtraceback) == 1
|
||||
assert newtraceback[0].frame.code.path == p
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import py
|
||||
|
||||
pytest_plugins = "pytester"
|
||||
plugindir = py.path.local(py._py.__file__).dirpath('test', 'plugin')
|
||||
plugindir = py._impldir.join('test', 'plugin')
|
||||
from _py.test.defaultconftest import pytest_plugins as default_plugins
|
||||
|
||||
def pytest_collect_file(path, parent):
|
||||
|
|
|
@ -7,6 +7,7 @@ def checksubpackage(name):
|
|||
if hasattr(obj, '__map__'): # isinstance(obj, Module):
|
||||
keys = dir(obj)
|
||||
assert len(keys) > 0
|
||||
print (obj.__map__)
|
||||
assert getattr(obj, '__map__') == {}
|
||||
|
||||
def test_dir():
|
||||
|
|
Loading…
Reference in New Issue