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

Public Member Functions

def testNonEmptyXmlOutput (self)
 
def testNoTestXmlOutput (self)
 
def testTimestampValue (self)
 
def testDefaultOutputFile (self)
 
def testSuppressedXmlOutput (self)
 
def testFilteredTestXmlOutput (self)
 
def testShardedTestXmlOutput (self)
 
- Public Member Functions inherited from gtest_xml_test_utils.GTestXMLTestCase
def AssertEquivalentNodes (self, expected_node, actual_node)
 
def NormalizeXml (self, element)
 

Additional Inherited Members

- Static Public Attributes inherited from gtest_xml_test_utils.GTestXMLTestCase
dictionary identifying_attribute
 

Detailed Description

Unit test for Google Test's XML output functionality.

Definition at line 240 of file gtest_xml_output_unittest.py.

Member Function Documentation

◆ testDefaultOutputFile()

def gtest_xml_output_unittest.GTestXMLOutputUnitTest.testDefaultOutputFile (   self)
Confirms that Google Test produces an XML output file with the expected
default name if no name is explicitly specified.

Definition at line 289 of file gtest_xml_output_unittest.py.

289 def testDefaultOutputFile(self):
290 """
291 Confirms that Google Test produces an XML output file with the expected
292 default name if no name is explicitly specified.
293 """
294 output_file = os.path.join(gtest_test_utils.GetTempDir(),
295 GTEST_DEFAULT_OUTPUT_FILE)
297 'gtest_no_test_unittest')
298 try:
299 os.remove(output_file)
300 except OSError:
301 e = sys.exc_info()[1]
302 if e.errno != errno.ENOENT:
303 raise
304
306 [gtest_prog_path, '%s=xml' % GTEST_OUTPUT_FLAG],
307 working_dir=gtest_test_utils.GetTempDir())
308 self.assert_(p.exited)
309 self.assertEquals(0, p.exit_code)
310 self.assert_(os.path.isfile(output_file))
311
def GetTestExecutablePath(executable_name, build_dir=None)

◆ testFilteredTestXmlOutput()

def gtest_xml_output_unittest.GTestXMLOutputUnitTest.testFilteredTestXmlOutput (   self)
Verifies XML output when a filter is applied.

Runs a test program that executes only some tests and verifies that
non-selected tests do not show up in the XML output.

Definition at line 341 of file gtest_xml_output_unittest.py.

341 def testFilteredTestXmlOutput(self):
342 """Verifies XML output when a filter is applied.
343
344 Runs a test program that executes only some tests and verifies that
345 non-selected tests do not show up in the XML output.
346 """
347
348 self._TestXmlOutput(GTEST_PROGRAM_NAME, EXPECTED_FILTERED_TEST_XML, 0,
349 extra_args=['%s=SuccessfulTest.*' % GTEST_FILTER_FLAG])
350

◆ testNonEmptyXmlOutput()

def gtest_xml_output_unittest.GTestXMLOutputUnitTest.testNonEmptyXmlOutput (   self)
Runs a test program that generates a non-empty XML output, and
tests that the XML output is expected.

Definition at line 248 of file gtest_xml_output_unittest.py.

248 def testNonEmptyXmlOutput(self):
249 """
250 Runs a test program that generates a non-empty XML output, and
251 tests that the XML output is expected.
252 """
253 self._TestXmlOutput(GTEST_PROGRAM_NAME, EXPECTED_NON_EMPTY_XML, 1)
254

◆ testNoTestXmlOutput()

def gtest_xml_output_unittest.GTestXMLOutputUnitTest.testNoTestXmlOutput (   self)
Verifies XML output for a Google Test binary without actual tests.

Runs a test program that generates an XML output for a binary without tests,
and tests that the XML output is expected.

Definition at line 255 of file gtest_xml_output_unittest.py.

255 def testNoTestXmlOutput(self):
256 """Verifies XML output for a Google Test binary without actual tests.
257
258 Runs a test program that generates an XML output for a binary without tests,
259 and tests that the XML output is expected.
260 """
261
262 self._TestXmlOutput('gtest_no_test_unittest', EXPECTED_NO_TEST_XML, 0)
263

◆ testShardedTestXmlOutput()

def gtest_xml_output_unittest.GTestXMLOutputUnitTest.testShardedTestXmlOutput (   self)
Verifies XML output when run using multiple shards.

Runs a test program that executes only one shard and verifies that tests
from other shards do not show up in the XML output.

Definition at line 351 of file gtest_xml_output_unittest.py.

351 def testShardedTestXmlOutput(self):
352 """Verifies XML output when run using multiple shards.
353
354 Runs a test program that executes only one shard and verifies that tests
355 from other shards do not show up in the XML output.
356 """
357
358 self._TestXmlOutput(
359 GTEST_PROGRAM_NAME,
360 EXPECTED_SHARDED_TEST_XML,
361 0,
362 extra_env={SHARD_INDEX_ENV_VAR: '0',
363 TOTAL_SHARDS_ENV_VAR: '10'})
364

◆ testSuppressedXmlOutput()

def gtest_xml_output_unittest.GTestXMLOutputUnitTest.testSuppressedXmlOutput (   self)
Tests that no XML file is generated if the default XML listener is
shut down before RUN_ALL_TESTS is invoked.

Definition at line 312 of file gtest_xml_output_unittest.py.

312 def testSuppressedXmlOutput(self):
313 """
314 Tests that no XML file is generated if the default XML listener is
315 shut down before RUN_ALL_TESTS is invoked.
316 """
317
318 xml_path = os.path.join(gtest_test_utils.GetTempDir(),
319 GTEST_PROGRAM_NAME + 'out.xml')
320 if os.path.isfile(xml_path):
321 os.remove(xml_path)
322
323 command = [GTEST_PROGRAM_PATH,
324 '%s=xml:%s' % (GTEST_OUTPUT_FLAG, xml_path),
325 '--shut_down_xml']
326 p = gtest_test_utils.Subprocess(command)
327 if p.terminated_by_signal:
328 # p.signal is available only if p.terminated_by_signal is True.
329 self.assertFalse(
330 p.terminated_by_signal,
331 '%s was killed by signal %d' % (GTEST_PROGRAM_NAME, p.signal))
332 else:
333 self.assert_(p.exited)
334 self.assertEquals(1, p.exit_code,
335 "'%s' exited with code %s, which doesn't match "
336 'the expected exit code %s.'
337 % (command, p.exit_code, 1))
338
339 self.assert_(not os.path.isfile(xml_path))
340

◆ testTimestampValue()

def gtest_xml_output_unittest.GTestXMLOutputUnitTest.testTimestampValue (   self)
Checks whether the timestamp attribute in the XML output is valid.

Runs a test program that generates an empty XML output, and checks if
the timestamp attribute in the testsuites tag is valid.

Definition at line 264 of file gtest_xml_output_unittest.py.

264 def testTimestampValue(self):
265 """Checks whether the timestamp attribute in the XML output is valid.
266
267 Runs a test program that generates an empty XML output, and checks if
268 the timestamp attribute in the testsuites tag is valid.
269 """
270 actual = self._GetXmlOutput('gtest_no_test_unittest', [], {}, 0)
271 date_time_str = actual.documentElement.getAttributeNode('timestamp').value
272 # datetime.strptime() is only available in Python 2.5+ so we have to
273 # parse the expected datetime manually.
274 match = re.match(r'(\d+)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)', date_time_str)
275 self.assertTrue(
276 re.match,
277 'XML datettime string %s has incorrect format' % date_time_str)
278 date_time_from_xml = datetime.datetime(
279 year=int(match.group(1)), month=int(match.group(2)),
280 day=int(match.group(3)), hour=int(match.group(4)),
281 minute=int(match.group(5)), second=int(match.group(6)))
282
283 time_delta = abs(datetime.datetime.now() - date_time_from_xml)
284 # timestamp value should be near the current local time
285 self.assertTrue(time_delta < datetime.timedelta(seconds=600),
286 'time_delta is %s' % time_delta)
287 actual.unlink()
288

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