Commits

Ralf Schmitt committed fb8c163

copy __doc__ from the original module and make sure __doc__ in exportdefs still works.

Comments (0)

Files changed (2)

         d['__loader__'] = oldmod.__loader__
     if hasattr(oldmod, '__path__'):
         d['__path__'] = [os.path.abspath(p) for p in oldmod.__path__]
+    if hasattr(oldmod, '__doc__'):
+        d['__doc__'] = oldmod.__doc__
     d.update(attr)
     oldmod.__dict__.update(d)
     mod = ApiModule(pkgname, exportdefs, implprefix=pkgname, attr=d)
     mod.__version__ = 10
     mod.__file__ = "hello.py"
     mod.__loader__ = "loader"
+    mod.__doc__ = "this is the documentation"
     monkeypatch.setitem(sys.modules, 'hello', mod)
     apipkg.initpkg('hello', {})
     newmod = sys.modules['hello']
     assert newmod.__file__ == py.path.local(mod.__file__)
     assert newmod.__version__ == mod.__version__
     assert newmod.__loader__ == mod.__loader__
+    assert newmod.__doc__ == mod.__doc__
+
+def test_initpkg_not_overwrite_exportdefs(monkeypatch):
+    mod = type(sys)('hello')
+    mod.__doc__ = "this is the documentation"
+    monkeypatch.setitem(sys.modules, 'hello', mod)
+    apipkg.initpkg('hello', {"__doc__": "sys:__doc__"})
+    newmod = sys.modules['hello']
+    assert newmod != mod
+    assert newmod.__doc__ == sys.__doc__
 
 def test_initpkg_not_transfers_not_existing_attrs(monkeypatch):
     mod = type(sys)('hello')