[testlib] simple helper method to register temporary appobjects (hooks for instance) with a context manager
--- a/devtools/testlib.py Wed Mar 31 12:21:39 2010 +0200
+++ b/devtools/testlib.py Wed Mar 31 12:26:07 2010 +0200
@@ -12,6 +12,7 @@
import re
from urllib import unquote
from math import log
+from contextlib import contextmanager
import simplejson
@@ -354,6 +355,15 @@
def entity(self, rql, args=None, eidkey=None, req=None):
return self.execute(rql, args, eidkey, req=req).get_entity(0, 0)
+ @contextmanager
+ def temporary_appobjects(self, *appobjects):
+ self.vreg._loadedmods.setdefault(self.__module__, {})
+ for obj in appobjects:
+ self.vreg.register(obj)
+ yield
+ for obj in appobjects:
+ self.vreg.unregister(obj)
+
# vregistry inspection utilities ###########################################
def pviews(self, req, rset):