Commit ce971638 authored by Arnaud Fontaine's avatar Arnaud Fontaine

Instead of defining timeNAMEInSecond, just wrap NAME and return the time spent

in seconds which can be later converted in pystones if necessary


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@46000 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 45c63678
...@@ -14,10 +14,10 @@ def createPerson(result, browser): ...@@ -14,10 +14,10 @@ def createPerson(result, browser):
""" """
# Go to Persons module (person_module) # Go to Persons module (person_module)
result('Go to person module', result('Go to person module',
browser.mainForm.timeSubmitSelectModuleInSecond(value='/person_module')) browser.mainForm.submitSelectModule(value='/person_module'))
# Create a new person and record the time elapsed in seconds # Create a new person and record the time elapsed in seconds
result('Add Person', browser.mainForm.timeSubmitNewInSecond()) result('Add Person', browser.mainForm.submitNew())
# Check whether it has been successfully created # Check whether it has been successfully created
assert browser.getTransitionMessage() == 'Object created.' assert browser.getTransitionMessage() == 'Object created.'
...@@ -27,26 +27,26 @@ def createPerson(result, browser): ...@@ -27,26 +27,26 @@ def createPerson(result, browser):
browser.mainForm.getControl(name='field_my_last_name').value = 'Person' browser.mainForm.getControl(name='field_my_last_name').value = 'Person'
# Submit the changes, record the time elapsed in seconds # Submit the changes, record the time elapsed in seconds
result('Save', browser.mainForm.timeSubmitSaveInSecond()) result('Save', browser.mainForm.submitSave())
# Check whether the changes have been successfully updated # Check whether the changes have been successfully updated
assert browser.getTransitionMessage() == 'Data updated.' assert browser.getTransitionMessage() == 'Data updated.'
# Add phone number # Add phone number
result('Add telephone', result('Add telephone',
browser.mainForm.timeSubmitSelectActionInSecond(value='add Telephone')) browser.mainForm.submitSelectAction(value='add Telephone'))
# Fill telephone title and number # Fill telephone title and number
browser.mainForm.getControl(name='field_my_title'). value = 'Personal' browser.mainForm.getControl(name='field_my_title'). value = 'Personal'
browser.mainForm.getControl(name='field_my_telephone_number').value = '0123456789' browser.mainForm.getControl(name='field_my_telephone_number').value = '0123456789'
# Submit the changes, record the time elapsed in seconds # Submit the changes, record the time elapsed in seconds
result('Save', browser.mainForm.timeSubmitSaveInSecond()) result('Save', browser.mainForm.submitSave())
# Check whether the changes have been successfully updated # Check whether the changes have been successfully updated
assert browser.getTransitionMessage() == 'Data updated.' assert browser.getTransitionMessage() == 'Data updated.'
# Validate it # Validate it
result('Validate', browser.mainForm.timeSubmitSelectWorkflowInSecond(value='validate_action')) result('Validate', browser.mainForm.submitSelectWorkflow(value='validate_action'))
result('Validated', browser.mainForm.timeSubmitDialogConfirmInSecond()) result('Validated', browser.mainForm.submitDialogConfirm())
assert browser.getTransitionMessage() == 'Status changed.' assert browser.getTransitionMessage() == 'Status changed.'
...@@ -49,58 +49,37 @@ def measurementMetaClass(prefix): ...@@ -49,58 +49,37 @@ def measurementMetaClass(prefix):
""" """
class MeasurementMetaClass(type): class MeasurementMetaClass(type):
""" """
Meta class to define automatically C{time*InSecond} and Meta class to automatically wrap methods whose prefix starts with
C{time*InPystone} methods automatically according to given
C{prefix}, and also to define C{lastRequestSeconds} and C{prefix}, and also to define C{lastRequestSeconds} and
C{lastRequestPystones} on other classes besides of Browser. C{lastRequestPystones} on other classes besides of Browser.
""" """
def __new__(metacls, name, bases, dictionary): def __new__(metacls, name, bases, dictionary):
def applyMeasure(method): def timeInSecondDecorator(method):
""" def wrapper(self, *args, **kwargs):
Inner function to add the C{time*InSecond} and C{time*InPystone}
methods to the dictionary of newly created class.
For example, if the method name is C{submitSave} then
C{timeSubmitSaveInSecond} and C{timeSubmitSaveInPystone} will
be added to the newly created class.
@param method: Instance method to be called
@type method: function
""" """
# Upper the first character Replaced by the wrapped method docstring
method_name_prefix = 'time' + method.func_name[0].upper() + \
method.func_name[1:]
def innerSecond(self, *args, **kwargs):
"""
Call L{%(name)s} method and return the time it took in seconds.
@param args: Positional arguments given to L{%(name)s}
@param kwargs: Keyword arguments given to L{%(name)s}
""" """
method(self, *args, **kwargs) ret = method(self, *args, **kwargs)
return self.lastRequestSeconds return (ret is None and self.lastRequestSeconds or
(ret + self.lastRequestSeconds))
innerSecond.func_name = method_name_prefix + 'InSecond' return wrapper
innerSecond.__doc__ = innerSecond.__doc__ % {'name': method.func_name}
dictionary[innerSecond.func_name] = innerSecond
def innerPystone(self, *args, **kwargs): def applyMeasure(method):
""" """
Call L{%(name)s} method and return the time it took in pystones. Inner function to wrap timed methods to automatically return the time
spent on the request
@param args: Positional arguments given to L{%(name)s} @param method: Instance method to be called
@param kwargs: Keyword arguments given to L{%(name)s} @type method: function
""" """
method(self, *args, **kwargs) wrapper_method = timeInSecondDecorator(method)
return self.lastRequestPystones wrapper_method.func_name = method.func_name
wrapper_method.__doc__ = method.__doc__
innerPystone.func_name = method_name_prefix + 'InPystone' dictionary[method.func_name] = wrapper_method
innerPystone.__doc__ = innerPystone.__doc__ % {'name': method.func_name}
dictionary[innerPystone.func_name] = innerPystone
# Create time*InSecond and time*InPystone methods only for the # Only wrap methods prefixed by the given prefix
# methods prefixed by the given prefix
for attribute_name, attribute in dictionary.items(): for attribute_name, attribute in dictionary.items():
if attribute_name.startswith(prefix) and callable(attribute): if attribute_name.startswith(prefix) and callable(attribute):
applyMeasure(attribute) applyMeasure(attribute)
...@@ -1003,7 +982,6 @@ from zope.testbrowser.browser import Link ...@@ -1003,7 +982,6 @@ from zope.testbrowser.browser import Link
class LinkWithTime(Link): class LinkWithTime(Link):
""" """
Only define to add timeClick*InSecond() and timeClick*InPystone() Only define to wrap click methods to measure the time spent
methods
""" """
__metaclass__ = measurementMetaClass(prefix='click') __metaclass__ = measurementMetaClass(prefix='click')
...@@ -21,7 +21,7 @@ def benchmarkAddPerson(iteration_counter, result_dict): ...@@ -21,7 +21,7 @@ def benchmarkAddPerson(iteration_counter, result_dict):
# Create a new person and record the time elapsed in seconds # Create a new person and record the time elapsed in seconds
result_dict.setdefault('Create', []).append( result_dict.setdefault('Create', []).append(
browser.mainForm.timeSubmitNewInSecond()) browser.mainForm.submitNew())
# Check whether it has been successfully created # Check whether it has been successfully created
assert browser.getTransitionMessage() == 'Object created.' assert browser.getTransitionMessage() == 'Object created.'
...@@ -35,7 +35,7 @@ def benchmarkAddPerson(iteration_counter, result_dict): ...@@ -35,7 +35,7 @@ def benchmarkAddPerson(iteration_counter, result_dict):
# Submit the changes, record the time elapsed in seconds # Submit the changes, record the time elapsed in seconds
result_dict.setdefault('Save', []).append( result_dict.setdefault('Save', []).append(
browser.mainForm.timeSubmitSaveInSecond()) browser.mainForm.submitSave())
# Check whether the changes have been successfully updated # Check whether the changes have been successfully updated
assert browser.getTransitionMessage() == 'Data updated.' assert browser.getTransitionMessage() == 'Data updated.'
...@@ -43,7 +43,7 @@ def benchmarkAddPerson(iteration_counter, result_dict): ...@@ -43,7 +43,7 @@ def benchmarkAddPerson(iteration_counter, result_dict):
# Validate the person and record confirmation # Validate the person and record confirmation
browser.mainForm.submitSelectWorkflow(value='validate_action') browser.mainForm.submitSelectWorkflow(value='validate_action')
result_dict.setdefault('Validate', []).append( result_dict.setdefault('Validate', []).append(
browser.mainForm.timeSubmitDialogConfirmInSecond()) browser.mainForm.submitDialogConfirm())
# Check whether it has been successfully validated # Check whether it has been successfully validated
assert browser.getTransitionMessage() == 'Status changed.' assert browser.getTransitionMessage() == 'Status changed.'
...@@ -58,7 +58,7 @@ def benchmarkAddPerson(iteration_counter, result_dict): ...@@ -58,7 +58,7 @@ def benchmarkAddPerson(iteration_counter, result_dict):
browser.mainForm.getListboxControl(2, 2).value = 'Foo%' browser.mainForm.getListboxControl(2, 2).value = 'Foo%'
result_dict.setdefault('Filter', []).append( result_dict.setdefault('Filter', []).append(
browser.mainForm.timeSubmitInSecond()) browser.mainForm.submit())
# Get the line number # Get the line number
line_number = browser.getListboxPosition("Foo%(counter)d Bar%(counter)d" % \ line_number = browser.getListboxPosition("Foo%(counter)d Bar%(counter)d" % \
......
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