proxygen
gtest_xml_test_utils.GTestXMLTestCase Class Reference
Inheritance diagram for gtest_xml_test_utils.GTestXMLTestCase:
gtest_xml_outfiles_test.GTestXMLOutFilesTest gtest_xml_outfiles_test.GTestXMLOutFilesTest gtest_xml_outfiles_test.GTestXMLOutFilesTest gtest_xml_output_unittest.GTestXMLOutputUnitTest gtest_xml_output_unittest.GTestXMLOutputUnitTest gtest_xml_output_unittest.GTestXMLOutputUnitTest

Public Member Functions

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

Static Public Attributes

dictionary identifying_attribute
 

Private Member Functions

def _GetChildren (self, element)
 
def _GetChildren (self, element)
 
def _GetChildren (self, element)
 

Detailed Description

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

Definition at line 45 of file gtest_xml_test_utils.py.

Member Function Documentation

def gtest_xml_test_utils.GTestXMLTestCase._GetChildren (   self,
  element 
)
private
Fetches all of the child nodes of element, a DOM Element object.
Returns them as the values of a dictionary keyed by the IDs of the
children.  For <testsuites>, <testsuite> and <testcase> elements, the ID
is the value of their "name" attribute; for <failure> elements, it is
the value of the "message" attribute; CDATA sections and non-whitespace
text nodes are concatenated into a single CDATA section with ID
"detail".  An exception is raised if any element other than the above
four is encountered, if two child elements with the same identifying
attributes are encountered, or if any other type of node is encountered.

Definition at line 117 of file gtest_xml_test_utils.py.

References EgressStateMachineFixture.fail(), IngressStateMachineFixture.fail(), wangle::LineBasedFrameDecoder.fail(), proxygen::ZlibServerFilter.fail(), folly::AsyncSocket::WriteRequest.fail(), folly::AsyncSocket.fail(), and gtest_xml_test_utils.GTestXMLTestCase.identifying_attribute.

Referenced by gtest_xml_test_utils.GTestXMLTestCase._GetChildren(), and gtest_xml_test_utils.GTestXMLTestCase.AssertEquivalentNodes().

117  def _GetChildren(self, element):
118  """
119  Fetches all of the child nodes of element, a DOM Element object.
120  Returns them as the values of a dictionary keyed by the IDs of the
121  children. For <testsuites>, <testsuite> and <testcase> elements, the ID
122  is the value of their "name" attribute; for <failure> elements, it is
123  the value of the "message" attribute; CDATA sections and non-whitespace
124  text nodes are concatenated into a single CDATA section with ID
125  "detail". An exception is raised if any element other than the above
126  four is encountered, if two child elements with the same identifying
127  attributes are encountered, or if any other type of node is encountered.
128  """
129 
130  children = {}
131  for child in element.childNodes:
132  if child.nodeType == Node.ELEMENT_NODE:
133  self.assert_(child.tagName in self.identifying_attribute,
134  'Encountered unknown element <%s>' % child.tagName)
135  childID = child.getAttribute(self.identifying_attribute[child.tagName])
136  self.assert_(childID not in children)
137  children[childID] = child
138  elif child.nodeType in [Node.TEXT_NODE, Node.CDATA_SECTION_NODE]:
139  if 'detail' not in children:
140  if (child.nodeType == Node.CDATA_SECTION_NODE or
141  not child.nodeValue.isspace()):
142  children['detail'] = child.ownerDocument.createCDATASection(
143  child.nodeValue)
144  else:
145  children['detail'].nodeValue += child.nodeValue
146  else:
147  self.fail('Encountered unexpected node type %d' % child.nodeType)
148  return children
149 
def gtest_xml_test_utils.GTestXMLTestCase._GetChildren (   self,
  element 
)
private
Fetches all of the child nodes of element, a DOM Element object.
Returns them as the values of a dictionary keyed by the IDs of the
children.  For <testsuites>, <testsuite> and <testcase> elements, the ID
is the value of their "name" attribute; for <failure> elements, it is
the value of the "message" attribute; CDATA sections and non-whitespace
text nodes are concatenated into a single CDATA section with ID
"detail".  An exception is raised if any element other than the above
four is encountered, if two child elements with the same identifying
attributes are encountered, or if any other type of node is encountered.

Definition at line 117 of file gtest_xml_test_utils.py.

References gtest_xml_test_utils.GTestXMLTestCase._GetChildren(), EgressStateMachineFixture.fail(), IngressStateMachineFixture.fail(), wangle::LineBasedFrameDecoder.fail(), proxygen::ZlibServerFilter.fail(), folly::AsyncSocket::WriteRequest.fail(), folly::AsyncSocket.fail(), and gtest_xml_test_utils.GTestXMLTestCase.identifying_attribute.

117  def _GetChildren(self, element):
118  """
119  Fetches all of the child nodes of element, a DOM Element object.
120  Returns them as the values of a dictionary keyed by the IDs of the
121  children. For <testsuites>, <testsuite> and <testcase> elements, the ID
122  is the value of their "name" attribute; for <failure> elements, it is
123  the value of the "message" attribute; CDATA sections and non-whitespace
124  text nodes are concatenated into a single CDATA section with ID
125  "detail". An exception is raised if any element other than the above
126  four is encountered, if two child elements with the same identifying
127  attributes are encountered, or if any other type of node is encountered.
128  """
129 
130  children = {}
131  for child in element.childNodes:
132  if child.nodeType == Node.ELEMENT_NODE:
133  self.assert_(child.tagName in self.identifying_attribute,
134  'Encountered unknown element <%s>' % child.tagName)
135  childID = child.getAttribute(self.identifying_attribute[child.tagName])
136  self.assert_(childID not in children)
137  children[childID] = child
138  elif child.nodeType in [Node.TEXT_NODE, Node.CDATA_SECTION_NODE]:
139  if 'detail' not in children:
140  if (child.nodeType == Node.CDATA_SECTION_NODE or
141  not child.nodeValue.isspace()):
142  children['detail'] = child.ownerDocument.createCDATASection(
143  child.nodeValue)
144  else:
145  children['detail'].nodeValue += child.nodeValue
146  else:
147  self.fail('Encountered unexpected node type %d' % child.nodeType)
148  return children
149 
def gtest_xml_test_utils.GTestXMLTestCase._GetChildren (   self,
  element 
)
private
Fetches all of the child nodes of element, a DOM Element object.
Returns them as the values of a dictionary keyed by the IDs of the
children.  For <testsuites>, <testsuite> and <testcase> elements, the ID
is the value of their "name" attribute; for <failure> elements, it is
the value of the "message" attribute; CDATA sections and non-whitespace
text nodes are concatenated into a single CDATA section with ID
"detail".  An exception is raised if any element other than the above
four is encountered, if two child elements with the same identifying
attributes are encountered, or if any other type of node is encountered.

Definition at line 117 of file gtest_xml_test_utils.py.

References gtest_xml_test_utils.GTestXMLTestCase._GetChildren(), EgressStateMachineFixture.fail(), IngressStateMachineFixture.fail(), wangle::LineBasedFrameDecoder.fail(), proxygen::ZlibServerFilter.fail(), folly::AsyncSocket::WriteRequest.fail(), folly::AsyncSocket.fail(), and gtest_xml_test_utils.GTestXMLTestCase.identifying_attribute.

117  def _GetChildren(self, element):
118  """
119  Fetches all of the child nodes of element, a DOM Element object.
120  Returns them as the values of a dictionary keyed by the IDs of the
121  children. For <testsuites>, <testsuite> and <testcase> elements, the ID
122  is the value of their "name" attribute; for <failure> elements, it is
123  the value of the "message" attribute; CDATA sections and non-whitespace
124  text nodes are concatenated into a single CDATA section with ID
125  "detail". An exception is raised if any element other than the above
126  four is encountered, if two child elements with the same identifying
127  attributes are encountered, or if any other type of node is encountered.
128  """
129 
130  children = {}
131  for child in element.childNodes:
132  if child.nodeType == Node.ELEMENT_NODE:
133  self.assert_(child.tagName in self.identifying_attribute,
134  'Encountered unknown element <%s>' % child.tagName)
135  childID = child.getAttribute(self.identifying_attribute[child.tagName])
136  self.assert_(childID not in children)
137  children[childID] = child
138  elif child.nodeType in [Node.TEXT_NODE, Node.CDATA_SECTION_NODE]:
139  if 'detail' not in children:
140  if (child.nodeType == Node.CDATA_SECTION_NODE or
141  not child.nodeValue.isspace()):
142  children['detail'] = child.ownerDocument.createCDATASection(
143  child.nodeValue)
144  else:
145  children['detail'].nodeValue += child.nodeValue
146  else:
147  self.fail('Encountered unexpected node type %d' % child.nodeType)
148  return children
149 
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 51 of file gtest_xml_test_utils.py.

References gtest_xml_test_utils.GTestXMLTestCase._GetChildren(), gtest_xml_test_utils.GTestXMLTestCase.AssertEquivalentNodes(), and folly::gen.range().

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

References gtest_xml_test_utils.GTestXMLTestCase._GetChildren(), gtest_xml_test_utils.GTestXMLTestCase.AssertEquivalentNodes(), and folly::gen.range().

Referenced by gtest_xml_outfiles_test.GTestXMLOutFilesTest._TestOutFile(), gtest_xml_output_unittest.GTestXMLOutputUnitTest._TestXmlOutput(), and gtest_xml_test_utils.GTestXMLTestCase.AssertEquivalentNodes().

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

References gtest_xml_test_utils.GTestXMLTestCase._GetChildren(), gtest_xml_test_utils.GTestXMLTestCase.AssertEquivalentNodes(), and folly::gen.range().

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

References gtest_xml_test_utils.GTestXMLTestCase.NormalizeXml().

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

References gtest_xml_test_utils.GTestXMLTestCase.NormalizeXml().

Referenced by gtest_xml_outfiles_test.GTestXMLOutFilesTest._TestOutFile(), gtest_xml_output_unittest.GTestXMLOutputUnitTest._TestXmlOutput(), and gtest_xml_test_utils.GTestXMLTestCase.NormalizeXml().

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

References gtest_xml_test_utils.GTestXMLTestCase.NormalizeXml().

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

Member Data Documentation

dictionary gtest_xml_test_utils.GTestXMLTestCase.identifying_attribute
static
Initial value:
1 = {
2  'testsuites': 'name',
3  'testsuite': 'name',
4  'testcase': 'name',
5  'failure': 'message',
6  }

Definition at line 110 of file gtest_xml_test_utils.py.

Referenced by gtest_xml_test_utils.GTestXMLTestCase._GetChildren().


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