[py-svn] apipkg commit 6cb3976c8d8a: default to __version__ '0' and not set __loader__ or __path__ at all if it
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Thu Jan 21 20:01:28 CET 2010
# HG changeset patch -- Bitbucket.org
# Project apipkg
# URL http://bitbucket.org/hpk42/apipkg/overview/
# User holger krekel <holger at merlinux.eu>
# Date 1264100470 -3600
# Node ID 6cb3976c8d8aac3d332ed8f507cfdad34b4279a1
# Parent 8c7bb85c04f17cf3de710d7323ebe852d64ac8e5
default to __version__ '0' and not set __loader__ or __path__ at all if it
doesn't exist on the underlying init module
--- a/test_apipkg.py
+++ b/test_apipkg.py
@@ -196,13 +196,24 @@ def test_initpkg_transfers_attrs(monkeyp
assert newmod.__version__ == mod.__version__
assert newmod.__loader__ == mod.__loader__
+def test_initpkg_not_transfers_not_existing_attrs(monkeypatch):
+ mod = type(sys)('hello')
+ mod.__file__ = "hello.py"
+ monkeypatch.setitem(sys.modules, 'hello', mod)
+ apipkg.initpkg('hello', {})
+ newmod = sys.modules['hello']
+ assert newmod != mod
+ assert newmod.__file__ == mod.__file__
+ assert not hasattr(newmod, '__loader__')
+ assert not hasattr(newmod, '__path__')
+
def test_initpkg_defaults(monkeypatch):
mod = type(sys)('hello')
monkeypatch.setitem(sys.modules, 'hello', mod)
apipkg.initpkg('hello', {})
newmod = sys.modules['hello']
assert newmod.__file__ == None
- assert newmod.__version__ == None
+ assert newmod.__version__ == '0'
def test_name_attribute():
api = apipkg.ApiModule('name_test', {
--- a/apipkg.py
+++ b/apipkg.py
@@ -15,9 +15,10 @@ def initpkg(pkgname, exportdefs):
mod = ApiModule(pkgname, exportdefs, implprefix=pkgname)
oldmod = sys.modules[pkgname]
mod.__file__ = getattr(oldmod, '__file__', None)
- mod.__version__ = getattr(oldmod, '__version__', None)
- mod.__path__ = getattr(oldmod, '__path__', None)
- mod.__loader__ = getattr(oldmod, '__loader__', None)
+ mod.__version__ = getattr(oldmod, '__version__', '0')
+ for name in ('__path__', '__loader__'):
+ if hasattr(oldmod, name):
+ setattr(mod, name, getattr(oldmod, name))
sys.modules[pkgname] = mod
def importobj(modpath, attrname):
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,8 @@ 1.0.0b6
----------------------------------------
- fix recursive import issue resulting in a superflous KeyError
+- default to __version__ '0' and not set __loader__ or __path__ at all if it
+ doesn't exist on the underlying init module
1.0.0b5
----------------------------------------
More information about the pytest-commit
mailing list