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