Commit adef573c authored by Arnaud Fontaine's avatar Arnaud Fontaine

No need to bind lastRequestPystones as everything is in seconds now and can be

later converted to pystones by calling browser.timer.pystonesPerSecond() on a
Browser instance.

With the previous commit, it allows to have shorter and nicer method names.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@46002 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b7e22773
...@@ -50,8 +50,8 @@ def measurementMetaClass(prefix): ...@@ -50,8 +50,8 @@ def measurementMetaClass(prefix):
class MeasurementMetaClass(type): class MeasurementMetaClass(type):
""" """
Meta class to automatically wrap methods whose prefix starts with Meta class to automatically wrap methods whose prefix starts with
C{prefix}, and also to define C{lastRequestSeconds} and C{prefix}, and also to define C{lastRequestSeconds} on other classes
C{lastRequestPystones} on other classes besides of Browser. besides of Browser.
""" """
def __new__(metacls, name, bases, dictionary): def __new__(metacls, name, bases, dictionary):
def timeInSecondDecorator(method): def timeInSecondDecorator(method):
...@@ -92,20 +92,15 @@ def measurementMetaClass(prefix): ...@@ -92,20 +92,15 @@ def measurementMetaClass(prefix):
if callable(attribute): if callable(attribute):
applyMeasure(attribute) applyMeasure(attribute)
# lastRequestSeconds and lastRequestPystones properties are only # lastRequestSeconds properties are only defined on classes inheriting
# defined on classes inheriting from zope.testbrowser.browser.Browser, # from zope.testbrowser.browser.Browser, so create these properties for
# so create these properties for all other classes too # all other classes too
if 'Browser' not in bases[0].__name__: if 'Browser' not in bases[0].__name__:
time_method = lambda self: self.browser.lastRequestSeconds time_method = lambda self: self.browser.lastRequestSeconds
time_method.func_name = 'lastRequestSeconds' time_method.func_name = 'lastRequestSeconds'
time_method.__doc__ = Browser.lastRequestSeconds.__doc__ time_method.__doc__ = Browser.lastRequestSeconds.__doc__
dictionary['lastRequestSeconds'] = property(time_method) dictionary['lastRequestSeconds'] = property(time_method)
time_method = lambda self: self.browser.lastRequestPystones
time_method.func_name = 'lastRequestPystones'
time_method.__doc__ = Browser.lastRequestPystones.__doc__
dictionary['lastRequestPystones'] = property(time_method)
return super(MeasurementMetaClass, return super(MeasurementMetaClass,
metacls).__new__(metacls, name, bases, dictionary) metacls).__new__(metacls, name, bases, dictionary)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment