tesseract v5.3.3.20231005
gtest_xml_test_utils.GTestXMLTestCase Class Reference
Inheritance diagram for gtest_xml_test_utils.GTestXMLTestCase:
gtest_xml_outfiles_test.GTestXMLOutFilesTest gtest_xml_output_unittest.GTestXMLOutputUnitTest

Public Member Functions

def AssertEquivalentNodes (self, expected_node, actual_node)
 
def NormalizeXml (self, element)
 

Static Public Attributes

dictionary identifying_attribute
 

Detailed Description

Base class for tests of Google Test's XML output functionality.

Definition at line 38 of file gtest_xml_test_utils.py.

Member Function Documentation

◆ AssertEquivalentNodes()

def gtest_xml_test_utils.GTestXMLTestCase.AssertEquivalentNodes (   self,
  expected_node,
  actual_node 
)
Asserts that actual_node (a DOM node object) is equivalent to
expected_node (another DOM node object), in that either both of
them are CDATA nodes and have the same value, or both are DOM
elements and actual_node meets all of the following conditions:

*  It has the same tag name as expected_node.
*  It has the same set of attributes as expected_node, each with
   the same value as the corresponding attribute of expected_node.
   Exceptions are any attribute named "time", which needs only be
   convertible to a floating-point number and any attribute named
   "type_param" which only has to be non-empty.
*  It has an equivalent set of child nodes (including elements and
   CDATA sections) as expected_node.  Note that we ignore the
   order of the children as they are not guaranteed to be in any
   particular order.

Definition at line 44 of file gtest_xml_test_utils.py.

44 def AssertEquivalentNodes(self, expected_node, actual_node):
45 """
46 Asserts that actual_node (a DOM node object) is equivalent to
47 expected_node (another DOM node object), in that either both of
48 them are CDATA nodes and have the same value, or both are DOM
49 elements and actual_node meets all of the following conditions:
50
51 * It has the same tag name as expected_node.
52 * It has the same set of attributes as expected_node, each with
53 the same value as the corresponding attribute of expected_node.
54 Exceptions are any attribute named "time", which needs only be
55 convertible to a floating-point number and any attribute named
56 "type_param" which only has to be non-empty.
57 * It has an equivalent set of child nodes (including elements and
58 CDATA sections) as expected_node. Note that we ignore the
59 order of the children as they are not guaranteed to be in any
60 particular order.
61 """
62
63 if expected_node.nodeType == Node.CDATA_SECTION_NODE:
64 self.assertEquals(Node.CDATA_SECTION_NODE, actual_node.nodeType)
65 self.assertEquals(expected_node.nodeValue, actual_node.nodeValue)
66 return
67
68 self.assertEquals(Node.ELEMENT_NODE, actual_node.nodeType)
69 self.assertEquals(Node.ELEMENT_NODE, expected_node.nodeType)
70 self.assertEquals(expected_node.tagName, actual_node.tagName)
71
72 expected_attributes = expected_node.attributes
73 actual_attributes = actual_node.attributes
74 self.assertEquals(
75 expected_attributes.length, actual_attributes.length,
76 'attribute numbers differ in element %s:\nExpected: %r\nActual: %r' % (
77 actual_node.tagName, expected_attributes.keys(),
78 actual_attributes.keys()))
79 for i in range(expected_attributes.length):
80 expected_attr = expected_attributes.item(i)
81 actual_attr = actual_attributes.get(expected_attr.name)
82 self.assert_(
83 actual_attr is not None,
84 'expected attribute %s not found in element %s' %
85 (expected_attr.name, actual_node.tagName))
86 self.assertEquals(
87 expected_attr.value, actual_attr.value,
88 ' values of attribute %s in element %s differ: %s vs %s' %
89 (expected_attr.name, actual_node.tagName,
90 expected_attr.value, actual_attr.value))
91
92 expected_children = self._GetChildren(expected_node)
93 actual_children = self._GetChildren(actual_node)
94 self.assertEquals(
95 len(expected_children), len(actual_children),
96 'number of child elements differ in element ' + actual_node.tagName)
97 for child_id, child in expected_children.items():
98 self.assert_(child_id in actual_children,
99 '<%s> is not in <%s> (in element %s)' %
100 (child_id, actual_children, actual_node.tagName))
101 self.AssertEquivalentNodes(child, actual_children[child_id])
102

◆ NormalizeXml()

def gtest_xml_test_utils.GTestXMLTestCase.NormalizeXml (   self,
  element 
)
Normalizes Google Test's XML output to eliminate references to transient
information that may change from run to run.

*  The "time" attribute of <testsuites>, <testsuite> and <testcase>
   elements is replaced with a single asterisk, if it contains
   only digit characters.
*  The "timestamp" attribute of <testsuites> elements is replaced with a
   single asterisk, if it contains a valid ISO8601 datetime value.
*  The "type_param" attribute of <testcase> elements is replaced with a
   single asterisk (if it sn non-empty) as it is the type name returned
   by the compiler and is platform dependent.
*  The line info reported in the first line of the "message"
   attribute and CDATA section of <failure> elements is replaced with the
   file's basename and a single asterisk for the line number.
*  The directory names in file paths are removed.
*  The stack traces are removed.

Definition at line 153 of file gtest_xml_test_utils.py.

153 def NormalizeXml(self, element):
154 """
155 Normalizes Google Test's XML output to eliminate references to transient
156 information that may change from run to run.
157
158 * The "time" attribute of <testsuites>, <testsuite> and <testcase>
159 elements is replaced with a single asterisk, if it contains
160 only digit characters.
161 * The "timestamp" attribute of <testsuites> elements is replaced with a
162 single asterisk, if it contains a valid ISO8601 datetime value.
163 * The "type_param" attribute of <testcase> elements is replaced with a
164 single asterisk (if it sn non-empty) as it is the type name returned
165 by the compiler and is platform dependent.
166 * The line info reported in the first line of the "message"
167 attribute and CDATA section of <failure> elements is replaced with the
168 file's basename and a single asterisk for the line number.
169 * The directory names in file paths are removed.
170 * The stack traces are removed.
171 """
172
173 if element.tagName in ('testsuites', 'testsuite', 'testcase'):
174 timestamp = element.getAttributeNode('timestamp')
175 timestamp.value = re.sub(r'^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d\d\d$',
176 '*', timestamp.value)
177 if element.tagName in ('testsuites', 'testsuite', 'testcase'):
178 time = element.getAttributeNode('time')
179 time.value = re.sub(r'^\d+(\.\d+)?$', '*', time.value)
180 type_param = element.getAttributeNode('type_param')
181 if type_param and type_param.value:
182 type_param.value = '*'
183 elif element.tagName == 'failure' or element.tagName == 'skipped':
184 source_line_pat = r'^.*[/\\](.*:)\d+\n'
185 # Replaces the source line information with a normalized form.
186 message = element.getAttributeNode('message')
187 message.value = re.sub(source_line_pat, '\\1*\n', message.value)
188 for child in element.childNodes:
189 if child.nodeType == Node.CDATA_SECTION_NODE:
190 # Replaces the source line information with a normalized form.
191 cdata = re.sub(source_line_pat, '\\1*\n', child.nodeValue)
192 # Removes the actual stack trace.
193 child.nodeValue = re.sub(r'Stack trace:\n(.|\n)*',
194 'Stack trace:\n*', cdata)
195 for child in element.childNodes:
196 if child.nodeType == Node.ELEMENT_NODE:
197 self.NormalizeXml(child)

Member Data Documentation

◆ identifying_attribute

dictionary gtest_xml_test_utils.GTestXMLTestCase.identifying_attribute
static
Initial value:
= {
'testsuites': 'name',
'testsuite': 'name',
'testcase': 'name',
'failure': 'message',
'skipped': 'message',
'property': 'name',
}

Definition at line 103 of file gtest_xml_test_utils.py.


The documentation for this class was generated from the following file: