Commit 72ad7afb authored by Julien Muchembled's avatar Julien Muchembled

TestXHTML: Handle general error/warning reported by validator (ie. when there is no line/column).

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27834 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent fc73b0d5
...@@ -187,20 +187,21 @@ class W3Validator(object): ...@@ -187,20 +187,21 @@ class W3Validator(object):
parses the validation results, returns a list of tuples: parses the validation results, returns a list of tuples:
line_number, col_number, error description line_number, col_number, error description
""" """
error_list=[] result_list_list = []
warning_list=[]
xml_doc = minidom.parseString(result) xml_doc = minidom.parseString(result)
for error in xml_doc.getElementsByTagName('m:error'): for severity in 'm:error', 'm:warning':
error_line = error.getElementsByTagName('m:line')[0].firstChild.nodeValue result_list = []
error_col = error.getElementsByTagName('m:col')[0].firstChild.nodeValue for error in xml_doc.getElementsByTagName(severity):
error_message = error.getElementsByTagName('m:message')[0].firstChild.nodeValue result = []
error_list.append((error_line,error_col,error_message)) for name in 'm:line', 'm:col', 'm:message':
for warning in xml_doc.getElementsByTagName('m:warning'): element_list = error.getElementsByTagName(name)
warning_line = warning.getElementsByTagName('m:line')[0].firstChild.nodeValue if element_list:
warning_col = warning.getElementsByTagName('m:col')[0].firstChild.nodeValue result.append(element_list[0].firstChild.nodeValue)
warning_message = warning.getElementsByTagName('m:message')[0].firstChild.nodeValue else:
warning_list.append((warning_line, warning_col, warning_message)) result.append(None)
return error_list, warning_list result_list.append(tuple(result))
result_list_list.append(result_list)
return result_list_list
def getErrorAndWarningList(self, page_source): def getErrorAndWarningList(self, page_source):
''' '''
...@@ -270,29 +271,27 @@ def validate_xhtml(validator, source, view_name, bt_name): ...@@ -270,29 +271,27 @@ def validate_xhtml(validator, source, view_name, bt_name):
validator object, and there is some warning on the page, the function validator object, and there is some warning on the page, the function
return False, even if there is no error. return False, even if there is no error.
''' '''
# display some information when test faild to facilitate debugging # display some information when test faild to facilitate debugging
message = [] message = ['Using %s validator to parse the view "%s" (from %s bt)'
message.append('Using %s validator to parse the view "%s" (from %s bt) with warning %sdisplayed :' %\ ' with warning%sdisplayed :'
(validator.name, view_name, bt_name, % (validator.name, view_name, bt_name,
validator.show_warnings and ' ' or 'NOT ')) validator.show_warnings and ' ' or 'NOT ')]
error_list, warning_list = validator.getErrorAndWarningList(source) result_list_list = validator.getErrorAndWarningList(source)
if error_list: severity_list = ['Error']
# build error message if validator.show_warnings:
for error in error_list: severity_list.append('Warning')
message.append('Error: line %s column %s : %s' % error)
if warning_list and validator.show_warnings: for i, severity in enumerate(severity_list):
# build error message for line, column, msg in result_list_list[i]:
for warning in warning_list: if line is None and column is None:
message.append('Warning: line %s column %s : %s' % warning) message.append('%s: %s' % (severity, msg))
else:
message.append('%s: line %s column %s : %s' %
(severity, line, column, msg))
message = '\n'.join(message) return len(message) == 1, '\n'.join(message)
if validator.show_warnings:
return ((not (len(error_list) or len(warning_list))), message)
return ((not len(error_list)), message)
def makeTestMethod(validator, module_id, portal_type, view_name, bt_name): def makeTestMethod(validator, module_id, portal_type, view_name, bt_name):
......
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