Commits

holger krekel committed 4baca1f

test and refine for specifying dotted alias import names

Comments (0)

Files changed (3)

 import sys
 from types import ModuleType
 
-__version__ = "1.2.dev1"
+__version__ = '1.2.dev5'
 
 def initpkg(pkgname, exportdefs, attr=dict()):
     """ initialize given package from the export definitions. """
                     subname = '%s.%s'%(self.__name__, name)
                     apimod = AliasModule(subname, modpath)
                     sys.modules[subname] = apimod
-                    setattr(self, name, apimod)
+                    if '.' not in name:
+                        setattr(self, name, apimod)
                 else:
                     self.__map__[name] = (modpath, attrname)
 
         description=
         'apipkg: namespace control and lazy-import mechanism',
         long_description = open('README.txt').read(),
-        version='1.2.dev4',
+        version='1.2.dev5',
         url='http://bitbucket.org/hpk42/apipkg',
         license='MIT License',
         platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
     proxy.doit = doit
     assert orig.doit is doit
 
+def test_aliasmodule_nested_import_with_from(tmpdir, monkeypatch):
+    import os
+    pkgdir = tmpdir.mkdir("api1")
+    pkgdir.ensure("__init__.py").write(py.std.textwrap.dedent("""
+        import apipkg
+        apipkg.initpkg(__name__, {
+            'os2': 'api2',
+            'os2.path': 'api2.path2',
+            })
+    """))
+    tmpdir.join("api2.py").write(py.std.textwrap.dedent("""
+        import os, sys
+        from os import path
+        sys.modules['api2.path2'] = path
+        x = 3
+    """))
+    monkeypatch.syspath_prepend(tmpdir)
+    from api1 import os2
+    from api1.os2.path import abspath
+    assert abspath == os.path.abspath
+    # check that api1.os2 mirrors os.*
+    assert os2.x == 3
+    import api1
+    assert 'os2.path' not in api1.__dict__
+
 
 def test_initpkg_without_old_module():
     apipkg.initpkg("initpkg_without_old_module",