[Erp5-report] r34721 nicolas - /erp5/trunk/utils/erp5mechanize/ERP5Mechanize.py

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Apr 22 11:58:11 CEST 2010


Author: nicolas
Date: Thu Apr 22 11:58:10 2010
New Revision: 34721

URL: http://svn.erp5.org?rev=34721&view=rev
Log:
Cosmetic change only
  - cleanup white spaces
  - wordwrap to 80 chars.

Modified:
    erp5/trunk/utils/erp5mechanize/ERP5Mechanize.py

Modified: erp5/trunk/utils/erp5mechanize/ERP5Mechanize.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5mechanize/ERP5Mechanize.py?rev=34721&r1=34720&r2=34721&view=diff
==============================================================================
--- erp5/trunk/utils/erp5mechanize/ERP5Mechanize.py [utf8] (original)
+++ erp5/trunk/utils/erp5mechanize/ERP5Mechanize.py [utf8] Thu Apr 22 11:58:10 2010
@@ -80,12 +80,15 @@
 
   def getPortalStatusMessage(self):
     """
-      Parses the last received page and returns the value of the portal_status_message, or None if not present.
+      Parses the last received page and returns the value
+      of the portal_status_message, or None if not present.
     """
     from xml.dom.minidom import parseString
     document = parseString(self.getHtml().get_data())
     for element in document.getElementsByTagName(u'div'):
-      if element.attributes.get(u'id') is not None and element.attributes.get(u'id').value == u'transition_message': # XXX: Hardcoded class name
+      if element.attributes.get(u'id') is not None and\
+         element.attributes.get(u'id').value == u'transition_message':
+        # XXX: Hardcoded class name
         for child in element.childNodes:
           if child.nodeType == child.TEXT_NODE:
             return child.wholeText
@@ -93,16 +96,19 @@
 
   def getFormulatorFieldValue(self, field_label):
     """
-      Returns the raw html content of the formulator field present in last loaded page.
+      Returns the raw html content of the formulator field
+      present in last loaded page.
       Returns None id the field is not found.
     """
     from xml.dom.minidom import parseString
     document = parseString(self.getHtml().get_data())
     for element in document.getElementsByTagName(u'div'):
-      if element.attributes.get(u'class') is not None and 'field' in element.attributes.get(u'class').value:
-        if len(element.getElementsByTagName('label')) == 1 and \
-           field_label in element.getElementsByTagName('label')[0].firstChild.wholeText and \
-           len(element.getElementsByTagName('div')) == 1: # field_label in ... might get false positives.
+      if element.attributes.get(u'class') is not None and 'field'\
+                                     in element.attributes.get(u'class').value:
+        if len(element.getElementsByTagName('label')) == 1 and field_label in \
+           element.getElementsByTagName('label')[0].firstChild.wholeText and \
+           len(element.getElementsByTagName('div')) == 1:
+          # field_label in ... might get false positives.
           return element.getElementsByTagName('div')[0].firstChild.wholeText
     return None
 
@@ -113,7 +119,7 @@
     def predicate(form):
       return form.attrs['id'] == 'main_form'
     self.browser.select_form(predicate=predicate)
-  
+
   def fillField(self, name, value):
     self.selectMainForm()
     self.browser[name] = value
@@ -128,8 +134,8 @@
 
   def checkCheckbox(self, name, index=0, state=True):
     """
-      Check (or uncheck, according to "state" parameter value) a checkbox, given
-      by name. If there are multiple checkbox with the same name, you can
+      Check (or uncheck, according to "state" parameter value) a checkbox,
+      given by name. If there are multiple checkbox with the same name, you can
       specify the one to check by its index.
     """
     self.selectMainForm()
@@ -181,7 +187,9 @@
     self.fillField('__ac_name', name)
     self.fillField('__ac_password', password)
     t = self.timeSubmit()
-    if 'Logged In as' not in self.last_page.get_data(): # XXX: Could use information sent back as headers - but would bind us to a specific authentication scheme.
+    if 'Logged In as' not in self.last_page.get_data():
+      # XXX: Could use information sent back as headers
+      # - but would bind us to a specific authentication scheme.
       raise LoginError
     return t
 
@@ -197,11 +205,12 @@
     """
     self.selectMainForm()
     found = 0
-    item_names = dict([(item.name.split('/')[-1], item.name) for item in self.browser.find_control(name=menu_name).items])
+    item_names = dict([(item.name.split('/')[-1], item.name) for\
+                      item in self.browser.find_control(name=menu_name).items])
     if value in item_names:
       self.fillField(menu_name, [item_names[value]])
     else:
-      raise ItemNotFoundError, 'insufficient items with name \'%s\'' % (value, )
+      raise ItemNotFoundError, 'insufficient items with name \'%r\'' % (value, )
     request = self.browser.click(name=submit_name)
     return self.timeOpen(request)
 
@@ -251,12 +260,15 @@
     """
       Pass the given workflow action.
       The transition dialog is passed.
-      The returned time takes juste the actual workflow transition in account, not the transition dialog display time.
+      The returned time takes juste the actual workflow transition in account,
+      not the transition dialog display time.
     """
     try:
-      self.doMenu('%s?workflow_action=%s' % (script_id, value), 'select_action', 'Base_doAction:method')
+      self.doMenu('%s?workflow_action=%s' % (script_id, value), 
+                  'select_action', 'Base_doAction:method')
     except ItemNotFoundError:
-      self.doMenu('%s?field_my_workflow_action=%s' % (script_id, value), 'select_action', 'Base_doAction:method')
+      self.doMenu('%s?field_my_workflow_action=%s' % (script_id, value),
+                  'select_action', 'Base_doAction:method')
     return self.doAction(submit_name='Base_callDialogMethod:method')
 
   def doJumpMenu(self, value):
@@ -269,7 +281,8 @@
     """
       Go directly to object (by entering the url) using given path.
       Path is relative to site base url.
-      There are no restriction on the type of object we get on : module, person, ZMI view... whatever.
+      There are no restriction on the type of object
+      we get on : module, person, ZMI view... whatever.
     """
     return self.timeOpen('%s/%s' % (self.base_url, path))
 
@@ -424,7 +437,7 @@
       Execute the dialog update action.
     """
     return self.doAction(submit_name='Base_showUpdateDialog:method')
-  
+
   def gotoTab(self, value):
     """
       Go to tab whose target form name is equal to given value.
@@ -441,50 +454,59 @@
     from xml.dom.minidom import parseString
     document = parseString(self.getHtml().get_data())
     for element in document.getElementsByTagName(u'div'):
-      if element.attributes.get(u'class') is not None and element.attributes.get(u'class').value == u'ListContent': # XXX: Hardcoded class name
+      if element.attributes.get(u'class') is not None and\
+         element.attributes.get(u'class').value == u'ListContent':
+        # XXX: Hardcoded class name
         return element
     return None
 
   def fillListboxField(self, line_number, column_number, value):
     """
-      Fills the editable field located at given coordinates (starts at indice 0) in listbox with given value.
+      Fills the editable field located at given coordinates
+      (starts at indice 0) in listbox with given value.
       Raises an exception if there is no editable field at given position.
 
       XXX: what if there is more than one field in a cell ?
     """
-    self.fillField(str(self._getListbox().getElementsByTagName(u'tr')[line_number]\
-                                         .getElementsByTagName(u'td')[column_number]\
-                                         .getElementsByTagName(u'input')[0].attributes[u'name'].value)
+    self.fillField(str(self._getListbox()\
+                  .getElementsByTagName(u'tr')[line_number]\
+                  .getElementsByTagName(u'td')[column_number]\
+                  .getElementsByTagName(u'input')[0].attributes[u'name'].value)
                    , value)
 
   def match(self, node, value, strict=False):
     """
       Returns True if value matches a substring of node.
     """
-    if (node.nodeType == node.TEXT_NODE) and ((strict and (value == node.wholeText)) or (value in node.wholeText)):
+    if (node.nodeType == node.TEXT_NODE) and\
+         ((strict and (value == node.wholeText)) or (value in node.wholeText)):
       return True
     else:
       for child in node.childNodes:
         if self.match(child, value, strict):
           return True
     return False
-    
+
   def getListboxLine(self, column_number, value, strict=False):
     """
-      Returns the position number of the first line containing given text in given column, None if not found.
+      Returns the position number of the first line containing
+      given text in given column, None if not found.
     """
     line_list = self._getListbox().getElementsByTagName(u'tr')
     for line_pos in xrange(len(line_list)):
-      for child in line_list[line_pos].getElementsByTagName(u'td')[column_number].childNodes:
+      for child in line_list[line_pos].getElementsByTagName(u'td')\
+                                                   [column_number].childNodes:
         if self.match(child, value, strict):
           return line_pos
     return None
 
   def getListboxColumn(self, line_number, value, strict=False):
     """
-      Returns the position number of the first column containing given text at given line, None if not found.
-    """
-    column_list = self._getListbox().getElementsByTagName(u'tr')[line_number].getElementsByTagName(u'td')
+      Returns the position number of the first column
+      containing given text at given line, None if not found.
+    """
+    column_list = self._getListbox().getElementsByTagName(u'tr')\
+                                      [line_number].getElementsByTagName(u'td')
     for cell_pos in xrange(len(column_list)):
       for child in column_list[cell_pos].childNodes:
         if self.match(child, value, strict):
@@ -497,12 +519,15 @@
 
       XXX: what if there is more than one link ?
     """
-    return self.timeOpen(str(self._getListbox().getElementsByTagName(u'tr')[line_number]\
-                                               .getElementsByTagName(u'td')[column_number]\
-                                               .getElementsByTagName(u'a')[0].attributes[u'href'].value))
+    return self.timeOpen(str(self._getListbox()\
+                     .getElementsByTagName(u'tr')[line_number]\
+                     .getElementsByTagName(u'td')[column_number]\
+                     .getElementsByTagName(u'a')[0].attributes[u'href'].value))
+
   def doListboxAction(self):
     """
-      Validate listbox: this triggers the update of the selection with listbox search fields and checkboxes.
+      Validate listbox: this triggers the update of the selection
+      with listbox search fields and checkboxes.
     """
     return self.timeSubmit(submit='Base_doSelect:method')
 
@@ -515,7 +540,8 @@
      And optionally :
       -test begin timestamp
       -test end timestamp
-     Those last two values allow to measure the time spent handling the request before & after sending it.
+     Those last two values allow to measure the time spent
+     handling the request before & after sending it.
   """
 
   def __init__(self, id, start, stop, test_start=None, test_stop=None):
@@ -571,7 +597,9 @@
     return self.test_stop - self.test_start
 
   def getOverhead(self):
-    """ Return the test overhead duration (ie. test time spent outside of request time) """
+    """ Return the test overhead duration
+     (ie. test time spent outside of request time)
+    """
     return self.getTestDuration() - self.getDuration()
 
 def timeExecution(id, function, args=[], kw={}):
@@ -604,7 +632,8 @@
   """
   sys.stderr.write('-- %s %s --\n' % (url, name))
   if len(result):
-    sys.stderr.write('Id of last successfull step : %s\n' % (repr(result[-1].getId()), ))
+    last_step_id = result[-1].getId()
+    sys.stderr.write('Id of last successfull step : %r\n' % (last_step_id,))
   else:
     sys.stderr.write('No step was successfull.')
   traceback.print_exc()




More information about the Erp5-report mailing list