[py-svn] apipkg commit 69b6f42e005c: merge ronny's changes, fix for py3 and added a tox.ini
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Sun Aug 1 15:19:51 CEST 2010
# HG changeset patch -- Bitbucket.org
# Project apipkg
# URL http://bitbucket.org/hpk42/apipkg/overview
# User holger krekel <holger at merlinux.eu>
# Date 1280668765 -7200
# Node ID 69b6f42e005c7ab969722dc79dc1123e424888f0
# Parent e31678d39e272aabc016355eda6aab0149518eb1
# Parent 031b6257823acbd6bfbd49ff67065413ab38921a
merge ronny's changes, fix for py3 and added a tox.ini
bump version to 1.0b7
--- a/test_apipkg.py
+++ b/test_apipkg.py
@@ -2,6 +2,7 @@ import types
import sys
import py
import apipkg
+import subprocess
#
# test support for importing modules
#
@@ -192,7 +193,7 @@ def test_initpkg_transfers_attrs(monkeyp
apipkg.initpkg('hello', {})
newmod = sys.modules['hello']
assert newmod != mod
- assert newmod.__file__ == mod.__file__
+ assert newmod.__file__ == py.path.local(mod.__file__)
assert newmod.__version__ == mod.__version__
assert newmod.__loader__ == mod.__loader__
@@ -203,7 +204,7 @@ def test_initpkg_not_transfers_not_exist
apipkg.initpkg('hello', {})
newmod = sys.modules['hello']
assert newmod != mod
- assert newmod.__file__ == mod.__file__
+ assert newmod.__file__ == py.path.local(mod.__file__)
assert not hasattr(newmod, '__loader__')
assert not hasattr(newmod, '__path__')
@@ -284,7 +285,7 @@ def test_onfirstaccess_setsnewattr(tmpdi
if mode == 'attr':
assert mod.newattr == 42
elif mode == "dict":
- print mod.__dict__.keys()
+ print (list(mod.__dict__.keys()))
assert 'newattr' in mod.__dict__
elif mode == "onfirst":
assert not hasattr(mod, '__onfirstaccess__')
@@ -300,4 +301,36 @@ def test_bpython_getattr_override(tmpdir
})
d = api.__dict__
assert 'abspath' in d
-
+
+
+
+
+def test_chdir_with_relative_imports_shouldnt_break_lazy_loading(tmpdir):
+ pkg = tmpdir.mkdir('pkg')
+ messy = tmpdir.mkdir('messy')
+ pkg.join('__init__.py').write(py.code.Source("""
+ import apipkg
+ apipkg.initpkg(__name__, {
+ 'test': '.sub:test',
+ })
+ """))
+ pkg.join('sub.py').write('def test(): pass')
+
+ tmpdir.join('main.py').write(py.code.Source("""
+ import os
+ import sys
+ sys.path.insert(0, '')
+ import pkg
+ import py
+ py.builtin.print_(pkg.__path__, file=sys.stderr)
+ py.builtin.print_(pkg.__file__, file=sys.stderr)
+ py.builtin.print_(pkg, file=sys.stderr)
+ os.chdir('messy')
+ pkg.test()
+ """))
+ res = subprocess.call(
+ ['python', 'main.py'],
+ cwd=str(tmpdir),
+ )
+ assert res == 0
+
--- a/apipkg.py
+++ b/apipkg.py
@@ -5,20 +5,26 @@ see http://pypi.python.org/pypi/apipkg
(c) holger krekel, 2009 - MIT license
"""
+import os
import sys
from types import ModuleType
-__version__ = "1.0b6"
+__version__ = "1.0b7"
def initpkg(pkgname, exportdefs):
""" initialize given package from the export definitions. """
mod = ApiModule(pkgname, exportdefs, implprefix=pkgname)
oldmod = sys.modules[pkgname]
- mod.__file__ = getattr(oldmod, '__file__', None)
+ file = getattr(oldmod, '__file__', None)
+ if file:
+ file = os.path.abspath(file)
+ mod.__file__ = file
mod.__version__ = getattr(oldmod, '__version__', '0')
- for name in ('__path__', '__loader__'):
- if hasattr(oldmod, name):
- setattr(mod, name, getattr(oldmod, name))
+ if hasattr(oldmod, '__loader__'):
+ mod.__loader__ = oldmod.__loader__
+ if hasattr(oldmod, '__path__'):
+ mod.__path__ = [os.path.abspath(p) for p in oldmod.__path__]
+
sys.modules[pkgname] = mod
def importobj(modpath, attrname):
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,12 @@
+[tox]
+envlist=py27,py26,py25,py24,py31
+
+[tox:hudson]
+sdistsrc={distshare}/apipkg-*
+
+[testenv]
+commands=
+ py.test --junitxml={envlogdir}/junit-{envname}.xml []
+deps=
+ {distshare}/py-*
+
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,9 @@
+1.0.0b7
+----------------------------------------
+
+- make apipkg memorize the absolute path where a package starts
+ importing so that subsequent chdir + imports won't break.
+
1.0.0b6
----------------------------------------
More information about the pytest-commit
mailing list