devtools/testlib.py
changeset 2650 18aec79ec3a3
parent 2234 1fbcf202882d
child 2657 de974465d381
--- a/devtools/testlib.py	Mon Aug 03 09:37:13 2009 +0200
+++ b/devtools/testlib.py	Mon Aug 03 10:50:57 2009 +0200
@@ -185,7 +185,8 @@
         req = req or rset and rset.req or self.request()
         req.form['vid'] = vid
         kwargs['rset'] = rset
-        view = self.vreg.select('views', vid, req, **kwargs)
+        viewsreg = self.vreg['views']
+        view = viewsreg.select(vid, req, **kwargs)
         # set explicit test description
         if rset is not None:
             self.set_description("testing %s, mod=%s (%s)" % (
@@ -197,9 +198,9 @@
             viewfunc = view.render
         else:
             kwargs['view'] = view
-            templateview = self.vreg.select('views', template, req, **kwargs)
-            viewfunc = lambda **k: self.vreg.main_template(req, template,
-                                                           **kwargs)
+            templateview = viewsreg.select(template, req, **kwargs)
+            viewfunc = lambda **k: viewsreg.main_template(req, template,
+                                                          **kwargs)
         kwargs.pop('rset')
         return self._test_view(viewfunc, view, template, kwargs)
 
@@ -272,7 +273,8 @@
         req = rset.req
         only_once_vids = ('primary', 'secondary', 'text')
         req.data['ex'] = ValueError("whatever")
-        for vid, views in self.vreg.registry('views').items():
+        viewsvreg = self.vreg['views']
+        for vid, views in viewsvreg.items():
             if vid[0] == '_':
                 continue
             if rset.rowcount > 1 and vid in only_once_vids:
@@ -282,7 +284,7 @@
                      and not issubclass(view, NotificationView)]
             if views:
                 try:
-                    view = self.vreg.select_best(views, req, rset=rset)
+                    view = viewsvreg.select_best(views, req, rset=rset)
                     if view.linkable():
                         yield view
                     else:
@@ -295,19 +297,19 @@
     def list_actions_for(self, rset):
         """returns the list of actions that can be applied on `rset`"""
         req = rset.req
-        for action in self.vreg.possible_objects('actions', req, rset=rset):
+        for action in self.vreg['actions'].possible_objects(req, rset=rset):
             yield action
 
     def list_boxes_for(self, rset):
         """returns the list of boxes that can be applied on `rset`"""
         req = rset.req
-        for box in self.vreg.possible_objects('boxes', req, rset=rset):
+        for box in self.vreg['boxes'].possible_objects(req, rset=rset):
             yield box
 
     def list_startup_views(self):
         """returns the list of startup views"""
         req = self.request()
-        for view in self.vreg.possible_views(req, None):
+        for view in self.vreg['views'].possible_views(req, None):
             if view.category == 'startupview':
                 yield view.id
             else:
@@ -385,26 +387,25 @@
     from cubicweb.devtools.apptest import TestEnvironment
     env = testclass._env = TestEnvironment('data', configcls=testclass.configcls,
                                            requestcls=testclass.requestcls)
-    vreg = env.vreg
-    vreg._selected = {}
-    orig_select_best = vreg.__class__.select_best
-    def instr_select_best(self, *args, **kwargs):
-        selected = orig_select_best(self, *args, **kwargs)
-        try:
-            self._selected[selected.__class__] += 1
-        except KeyError:
-            self._selected[selected.__class__] = 1
-        except AttributeError:
-            pass # occurs on vreg used to restore database
-        return selected
-    vreg.__class__.select_best = instr_select_best
+    for reg in env.vreg.values():
+        reg._selected = {}
+        orig_select_best = reg.__class__.select_best
+        def instr_select_best(self, *args, **kwargs):
+            selected = orig_select_best(self, *args, **kwargs)
+            try:
+                self._selected[selected.__class__] += 1
+            except KeyError:
+                self._selected[selected.__class__] = 1
+            except AttributeError:
+                pass # occurs on reg used to restore database
+            return selected
+        reg.__class__.select_best = instr_select_best
 
 def print_untested_objects(testclass, skipregs=('hooks', 'etypes')):
-    vreg = testclass._env.vreg
-    for registry, vobjectsdict in vreg.items():
-        if registry in skipregs:
+    for regname, reg in testclass._env.vreg.iteritems():
+        if regname in skipregs:
             continue
-        for vobjects in vobjectsdict.values():
+        for vobjects in reg.itervalues():
             for vobject in vobjects:
-                if not vreg._selected.get(vobject):
-                    print 'not tested', registry, vobject
+                if not reg._selected.get(vobject):
+                    print 'not tested', regname, vobject