[Pytest-commit] commit/apipkg: 2 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon Aug 4 13:06:22 CEST 2014


2 new commits in apipkg:

https://bitbucket.org/hpk42/apipkg/commits/6fb824ce1795/
Changeset:   6fb824ce1795
User:        hpk42
Date:        2014-08-04 13:04:01
Summary:     alias modules pointing to unimportable modules will return None for
all their attributes instead of raising ImportError.  This addresses
python3.4 where any call to getframeinfo() can choke on sys.modules
contents if pytest is not installed (because py.test.* imports it).
Affected #:  3 files

diff -r df47d01210a750c2732e733e3deb60e57d098538 -r 6fb824ce17958a7f793645d70778fb6ff33a04cc CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,6 +3,10 @@
 
 - fix issue2 - adapt tests on Jython
 - handle jython __pkgpath__ missabstraction when running python from jar files
+- alias modules pointing to unimportable modules will return None for
+  all their attributes instead of raising ImportError.  This addresses
+  python3.4 where any call to getframeinfo() can choke on sys.modules
+  contents if pytest is not installed (because py.test.* imports it).
 
 1.2
 ----------------------------------------

diff -r df47d01210a750c2732e733e3deb60e57d098538 -r 6fb824ce17958a7f793645d70778fb6ff33a04cc apipkg.py
--- a/apipkg.py
+++ b/apipkg.py
@@ -17,6 +17,7 @@
     that will leave paths from jython jars alone
     """
     if path.startswith('__pyclasspath__'):
+
         return path
     else:
         return os.path.abspath(path)
@@ -41,7 +42,7 @@
     if hasattr(oldmod, "__dict__"):
         oldmod.__dict__.update(d)
     mod = ApiModule(pkgname, exportdefs, implprefix=pkgname, attr=d)
-    sys.modules[pkgname]  = mod
+    sys.modules[pkgname] = mod
 
 def importobj(modpath, attrname):
     module = __import__(modpath, None, None, ['__doc__'])
@@ -72,11 +73,11 @@
         self.__implprefix__ = implprefix or name
         if attr:
             for name, val in attr.items():
-                #print "setting", self.__name__, name, val
+                # print "setting", self.__name__, name, val
                 setattr(self, name, val)
         for name, importspec in importspec.items():
             if isinstance(importspec, dict):
-                subname = '%s.%s'%(self.__name__, name)
+                subname = '%s.%s' % (self.__name__, name)
                 apimod = ApiModule(subname, importspec, implprefix)
                 sys.modules[subname] = apimod
                 setattr(self, name, apimod)
@@ -88,7 +89,7 @@
                     modpath = implprefix + modpath
 
                 if not attrname:
-                    subname = '%s.%s'%(self.__name__, name)
+                    subname = '%s.%s' % (self.__name__, name)
                     apimod = AliasModule(subname, modpath)
                     sys.modules[subname] = apimod
                     if '.' not in name:
@@ -108,7 +109,7 @@
 
     def __makeattr(self, name):
         """lazily compute value for name or raise AttributeError if unknown."""
-        #print "makeattr", self.__name__, name
+        # print "makeattr", self.__name__, name
         target = None
         if '__onfirstaccess__' in self.__map__:
             target = self.__map__.pop('__onfirstaccess__')
@@ -126,7 +127,7 @@
             try:
                 del self.__map__[name]
             except KeyError:
-                pass # in a recursive-import situation a double-del can happen
+                pass  # in a recursive-import situation a double-del can happen
             return result
 
     __getattr__ = __makeattr
@@ -166,7 +167,10 @@
             return '<AliasModule %r for %r>' % (modname, x)
 
         def __getattribute__(self, name):
-            return getattr(getmod(), name)
+            try:
+                return getattr(getmod(), name)
+            except ImportError:
+                return None
 
         def __setattr__(self, name, value):
             setattr(getmod(), name, value)

diff -r df47d01210a750c2732e733e3deb60e57d098538 -r 6fb824ce17958a7f793645d70778fb6ff33a04cc test_apipkg.py
--- a/test_apipkg.py
+++ b/test_apipkg.py
@@ -423,6 +423,13 @@
     r = repr(am)
     assert "<AliasModule 'mymod' for 'pprint.PrettyPrinter'>" == r
     assert am.format
+    assert not hasattr(am, "lqkje")
+
+def test_aliasmodule_aliases_unimportable():
+    am = apipkg.AliasModule("mymod", "qlwkejqlwe", 'main')
+    r = repr(am)
+    assert "<AliasModule 'mymod' for 'qlwkejqlwe.main'>" == r
+    assert am.qwe is None
 
 def test_aliasmodule_unicode():
     am = apipkg.AliasModule(py.builtin._totext("mymod"), "pprint")


https://bitbucket.org/hpk42/apipkg/commits/64935a1665d6/
Changeset:   64935a1665d6
User:        hpk42
Date:        2014-08-04 13:04:15
Summary:     fix test wrt py34, modernize tox.ini
Affected #:  2 files

diff -r 6fb824ce17958a7f793645d70778fb6ff33a04cc -r 64935a1665d63883c751da5693039a304c1f7909 test_apipkg.py
--- a/test_apipkg.py
+++ b/test_apipkg.py
@@ -245,12 +245,12 @@
 def test_initpkg_not_transfers_not_existing_attrs(monkeypatch):
     mod = ModuleType('hello')
     mod.__file__ = "hello.py"
+    assert not hasattr(mod, '__path__')
     monkeypatch.setitem(sys.modules, 'hello', mod)
     apipkg.initpkg('hello', {})
     newmod = sys.modules['hello']
     assert newmod != mod
     assert newmod.__file__ == py.path.local(mod.__file__)
-    assert not hasattr(newmod, '__loader__')
     assert not hasattr(newmod, '__path__')
 
 

diff -r 6fb824ce17958a7f793645d70778fb6ff33a04cc -r 64935a1665d63883c751da5693039a304c1f7909 tox.ini
--- a/tox.ini
+++ b/tox.ini
@@ -1,12 +1,12 @@
 [tox]
-envlist=py27,py26,py25,py24,py31,py32,jython
+envlist=py27,py26,py33,py34,jython
 
 [tox:hudson]
 sdistsrc={distshare}/apipkg-*
 
 [testenv]
-commands=py.test --junitxml={envlogdir}/junit-{envname}.xml []
+commands=py.test []
 deps=pytest
 
 [testenv:jython]
-commands=py.test-jython --junitxml={envlogdir}/junit-{envname}.xml []
+commands=py.test-jython []

Repository URL: https://bitbucket.org/hpk42/apipkg/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the pytest-commit mailing list