Index: test/gtest_xml_output_unittest.py |
=================================================================== |
--- test/gtest_xml_output_unittest.py (revision 586) |
+++ test/gtest_xml_output_unittest.py (working copy) |
@@ -36,6 +36,7 @@ |
import errno |
import os |
import sys |
+import datetime |
from xml.dom import minidom, Node |
import gtest_test_utils |
@@ -55,7 +56,7 @@ |
STACK_TRACE_TEMPLATE = '' |
EXPECTED_NON_EMPTY_XML = """<?xml version="1.0" encoding="UTF-8"?> |
-<testsuites tests="23" failures="4" disabled="2" errors="0" time="*" name="AllTests"> |
+<testsuites tests="23" failures="4" disabled="2" errors="0" time="*" datetime="*" name="AllTests"> |
<testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" errors="0" time="*"> |
<testcase name="Succeeds" status="run" time="*" classname="SuccessfulTest"/> |
</testsuite> |
@@ -128,7 +129,7 @@ |
EXPECTED_EMPTY_XML = """<?xml version="1.0" encoding="UTF-8"?> |
-<testsuites tests="0" failures="0" disabled="0" errors="0" time="*" name="AllTests"> |
+<testsuites tests="0" failures="0" disabled="0" errors="0" time="*" datetime="*" name="AllTests"> |
</testsuites>""" |
GTEST_PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath(GTEST_PROGRAM_NAME) |
@@ -159,6 +160,21 @@ |
""" |
self._TestXmlOutput('gtest_no_test_unittest', EXPECTED_EMPTY_XML, 0) |
+ |
+ def testDatetimeValue(self): |
+ """ |
+ Runs a test program that generates an empty XML output, and checks if |
+ the date time value in the test suites tag is valid |
+ """ |
+ actual = self._GetXmlOutput("gtest_no_test_unittest", 0) |
+ test_suites_tag = actual.documentElement |
+ datetime_attribute = test_suites_tag.getAttributeNode("datetime") |
+ xml_datetime = datetime.datetime.strptime(datetime_attribute.value, "%Y-%m-%dT%H:%M:%S") |
+ |
+ time_delta = xml_datetime - datetime.datetime.now() |
+ # date time value should be near the current local time |
+ self.assertLess(time_delta.total_seconds(), 60) |
+ actual.unlink() |
def testDefaultOutputFile(self): |
""" |
@@ -209,40 +225,45 @@ |
self.assert_(not os.path.isfile(xml_path)) |
- |
- def _TestXmlOutput(self, gtest_prog_name, expected_xml, expected_exit_code): |
+ def _GetXmlOutput(self, gtest_prog_name, expected_exit_code): |
""" |
- Asserts that the XML document generated by running the program |
- gtest_prog_name matches expected_xml, a string containing another |
- XML document. Furthermore, the program's exit code must be |
- expected_exit_code. |
+ Returns the xml output generated by running the program gtest_prog_name. |
+ Furthermore, the program's exit code must be expected_exit_code. |
""" |
xml_path = os.path.join(gtest_test_utils.GetTempDir(), |
- gtest_prog_name + 'out.xml') |
+ gtest_prog_name + 'out.xml') |
gtest_prog_path = gtest_test_utils.GetTestExecutablePath(gtest_prog_name) |
command = [gtest_prog_path, '%s=xml:%s' % (GTEST_OUTPUT_FLAG, xml_path)] |
p = gtest_test_utils.Subprocess(command) |
if p.terminated_by_signal: |
self.assert_(False, |
- '%s was killed by signal %d' % (gtest_prog_name, p.signal)) |
+ '%s was killed by signal %d' % (gtest_prog_name, p.signal)) |
else: |
self.assert_(p.exited) |
self.assertEquals(expected_exit_code, p.exit_code, |
- "'%s' exited with code %s, which doesn't match " |
- 'the expected exit code %s.' |
- % (command, p.exit_code, expected_exit_code)) |
- |
+ "'%s' exited with code %s, which doesn't match " |
+ 'the expected exit code %s.' |
+ % (command, p.exit_code, expected_exit_code)) |
+ actual = minidom.parse(xml_path) |
+ return actual |
+ |
+ def _TestXmlOutput(self, gtest_prog_name, expected_xml, expected_exit_code): |
+ """ |
+ Asserts that the XML document generated by running the program |
+ gtest_prog_name matches expected_xml, a string containing another |
+ XML document. Furthermore, the program's exit code must be |
+ expected_exit_code. |
+ """ |
+ |
+ actual = self._GetXmlOutput(gtest_prog_name, expected_exit_code) |
expected = minidom.parseString(expected_xml) |
- actual = minidom.parse(xml_path) |
self.NormalizeXml(actual.documentElement) |
self.AssertEquivalentNodes(expected.documentElement, |
actual.documentElement) |
expected.unlink() |
- actual .unlink() |
+ actual.unlink() |
- |
- |
if __name__ == '__main__': |
os.environ['GTEST_STACK_TRACE_DEPTH'] = '1' |
gtest_test_utils.Main() |