devtools/testlib.py
branchstable
changeset 5102 04c84959cd85
parent 5055 14906474c55d
child 5121 a63d7886fcf5
child 5128 e5d300d75519
equal deleted inserted replaced
5101:0d01acee1f0a 5102:04c84959cd85
    10 import os
    10 import os
    11 import sys
    11 import sys
    12 import re
    12 import re
    13 from urllib import unquote
    13 from urllib import unquote
    14 from math import log
    14 from math import log
       
    15 from contextlib import contextmanager
    15 
    16 
    16 import simplejson
    17 import simplejson
    17 
    18 
    18 import yams.schema
    19 import yams.schema
    19 
    20 
   351 
   352 
   352     # other utilities #########################################################
   353     # other utilities #########################################################
   353 
   354 
   354     def entity(self, rql, args=None, eidkey=None, req=None):
   355     def entity(self, rql, args=None, eidkey=None, req=None):
   355         return self.execute(rql, args, eidkey, req=req).get_entity(0, 0)
   356         return self.execute(rql, args, eidkey, req=req).get_entity(0, 0)
       
   357 
       
   358     @contextmanager
       
   359     def temporary_appobjects(self, *appobjects):
       
   360         self.vreg._loadedmods.setdefault(self.__module__, {})
       
   361         for obj in appobjects:
       
   362             self.vreg.register(obj)
       
   363         yield
       
   364         for obj in appobjects:
       
   365             self.vreg.unregister(obj)
   356 
   366 
   357     # vregistry inspection utilities ###########################################
   367     # vregistry inspection utilities ###########################################
   358 
   368 
   359     def pviews(self, req, rset):
   369     def pviews(self, req, rset):
   360         return sorted((a.__regid__, a.__class__)
   370         return sorted((a.__regid__, a.__class__)