[py-svn] r37579 - in py/trunk/py: apigen apigen/testing apigen/tracer test/rsession

guido at codespeak.net guido at codespeak.net
Tue Jan 30 11:34:11 CET 2007


Author: guido
Date: Tue Jan 30 11:34:08 2007
New Revision: 37579

Modified:
   py/trunk/py/apigen/apigen.py
   py/trunk/py/apigen/testing/test_apigen_functional.py
   py/trunk/py/apigen/tracer/docstorage.py
   py/trunk/py/test/rsession/rsession.py
Log:
Made that the package name can be set when using from_dict() to fill a
DocStorage.


Modified: py/trunk/py/apigen/apigen.py
==============================================================================
--- py/trunk/py/apigen/apigen.py	(original)
+++ py/trunk/py/apigen/apigen.py	Tue Jan 30 11:34:08 2007
@@ -15,7 +15,7 @@
 def get_documentable_items(pkgdir):
     sys.path.insert(0, str(pkgdir.dirpath()))
     rootmod = __import__(pkgdir.basename)
-    return pkg_to_dict(rootmod)
+    return 'py', pkg_to_dict(rootmod)
 
 def build(pkgdir, dsa):
     l = linker.Linker()

Modified: py/trunk/py/apigen/testing/test_apigen_functional.py
==============================================================================
--- py/trunk/py/apigen/testing/test_apigen_functional.py	(original)
+++ py/trunk/py/apigen/testing/test_apigen_functional.py	Tue Jan 30 11:34:08 2007
@@ -82,7 +82,9 @@
 
 def test_get_documentable_items():
     fs_root, package_name = setup_fs_project('test_get_documentable_items')
-    documentable = apigen.get_documentable_items(fs_root.join(package_name))
+    pkgname, documentable = apigen.get_documentable_items(
+                                                fs_root.join(package_name))
+    assert pkgname == 'py'
     assert sorted(documentable.keys()) ==  [
         'main.SomeTestClass', 'main.SomeTestSubClass', 'main.func',
         'main.sub.func', 'somenamespace.baz', 'somenamespace.foo']

Modified: py/trunk/py/apigen/tracer/docstorage.py
==============================================================================
--- py/trunk/py/apigen/tracer/docstorage.py	(original)
+++ py/trunk/py/apigen/tracer/docstorage.py	Tue Jan 30 11:34:08 2007
@@ -56,6 +56,9 @@
 class DocStorage(object):
     """ Class storing info about API
     """
+    def __init__(self):
+        self.module_name = None
+
     def consider_call(self, frame, caller_frame, upward_cut_frame=None):
         assert isinstance(frame, py.code.Frame)
         desc = self.find_desc(frame.code, frame.raw.f_locals)
@@ -102,7 +105,8 @@
         for key, desc in self.descs.iteritems():
             self.desc_cache[desc] = desc
     
-    def from_dict(self, _dict, keep_frames = False):
+    def from_dict(self, _dict, keep_frames=False, module_name=None):
+        self.module_name = module_name
         self.descs = {}
         for key, val in _dict.iteritems():
             to_key, to_val = self.make_desc(key, val)
@@ -155,7 +159,7 @@
 
     def from_pkg(self, module, keep_frames=False):
         self.module = module
-        self.from_dict(pkg_to_dict(module), keep_frames)
+        self.from_dict(pkg_to_dict(module), keep_frames, module.__name__)
         # XXX
         return self
 
@@ -260,7 +264,9 @@
         return sorted([i.__name__ for i in self.ds.descs[name].exceptions.keys()])
 
     def get_module_name(self):
-        if hasattr(self.ds, 'module'):
+        if self.ds.module_name is not None:
+            return self.ds.module_name
+        elif hasattr(self.ds, 'module'):
             return self.ds.module.__name__
         return "Unknown module"
     

Modified: py/trunk/py/test/rsession/rsession.py
==============================================================================
--- py/trunk/py/test/rsession/rsession.py	(original)
+++ py/trunk/py/test/rsession/rsession.py	Tue Jan 30 11:34:08 2007
@@ -270,32 +270,14 @@
     def init_runner(self):
         if self.config.option.apigen:
             from py.__.apigen.tracer.tracer import Tracer, DocStorage
-            module = py
-            try:
-                pkgdir = self.getpkgdir(self.config.args[0])
-                apigen = py.path.local(self.config.option.apigen).pyimport()
-                items = apigen.get_documentable_items(pkgdir)
-                if isinstance(items, dict):
-                    self.docstorage = DocStorage().from_dict(items)
-                else:
-                    self.docstorage = DocStorage().from_pkg(items)
-            except ImportError:
-                import traceback
-                exc, e, tb = sys.exc_info()
-                print '%s - %s' % (exc, e)
-                print ''.join(traceback.format_tb(tb))
-                del tb
-                print '-' * 79
-                raise ImportError("Provided script cannot be imported")
-            except (ValueError, AttributeError):
-                import traceback
-                exc, e, tb = sys.exc_info()
-                print '%s - %s' % (exc, e)
-                print ''.join(traceback.format_tb(tb))
-                del tb
-                print '-' * 79
+            pkgdir = self.getpkgdir(self.config.args[0])
+            apigen = py.path.local(self.config.option.apigen).pyimport()
+            if not hasattr(apigen, 'get_documentable_items'):
                 raise NotImplementedError("Provided script does not seem "
                                           "to contain get_documentable_items")
+            pkgname, items = apigen.get_documentable_items(pkgdir)
+            self.docstorage = DocStorage().from_dict(items,
+                                                     module_name=pkgname)
             self.tracer = Tracer(self.docstorage)
             return apigen_runner
         else:



More information about the pytest-commit mailing list