Fix formatting in Python files
PiperOrigin-RevId: 504890435 Change-Id: Ia9a89d0d7a07fe70c12f7f0202c8256c94d2f118
This commit is contained in:
parent
0194f90d0e
commit
403a968d3c
@ -81,6 +81,7 @@ EX_BINARY_OUTPUT = gtest_test_utils.Subprocess(
|
|||||||
|
|
||||||
# The tests.
|
# The tests.
|
||||||
if SUPPORTS_SEH_EXCEPTIONS:
|
if SUPPORTS_SEH_EXCEPTIONS:
|
||||||
|
|
||||||
class CatchSehExceptionsTest(gtest_test_utils.TestCase):
|
class CatchSehExceptionsTest(gtest_test_utils.TestCase):
|
||||||
"""Tests exception-catching behavior."""
|
"""Tests exception-catching behavior."""
|
||||||
|
|
||||||
|
@ -130,38 +130,50 @@ def CalculateTestLists():
|
|||||||
|
|
||||||
if not ALL_TESTS:
|
if not ALL_TESTS:
|
||||||
ALL_TESTS.extend(
|
ALL_TESTS.extend(
|
||||||
GetTestsForAllIterations({}, [AlsoRunDisabledTestsFlag()])[0])
|
GetTestsForAllIterations({}, [AlsoRunDisabledTestsFlag()])[0]
|
||||||
|
)
|
||||||
|
|
||||||
if not ACTIVE_TESTS:
|
if not ACTIVE_TESTS:
|
||||||
ACTIVE_TESTS.extend(GetTestsForAllIterations({}, [])[0])
|
ACTIVE_TESTS.extend(GetTestsForAllIterations({}, [])[0])
|
||||||
|
|
||||||
if not FILTERED_TESTS:
|
if not FILTERED_TESTS:
|
||||||
FILTERED_TESTS.extend(
|
FILTERED_TESTS.extend(
|
||||||
GetTestsForAllIterations({}, [FilterFlag(TEST_FILTER)])[0])
|
GetTestsForAllIterations({}, [FilterFlag(TEST_FILTER)])[0]
|
||||||
|
)
|
||||||
|
|
||||||
if not SHARDED_TESTS:
|
if not SHARDED_TESTS:
|
||||||
SHARDED_TESTS.extend(
|
SHARDED_TESTS.extend(
|
||||||
GetTestsForAllIterations({TOTAL_SHARDS_ENV_VAR: '3',
|
GetTestsForAllIterations(
|
||||||
SHARD_INDEX_ENV_VAR: '1'},
|
{TOTAL_SHARDS_ENV_VAR: '3', SHARD_INDEX_ENV_VAR: '1'}, []
|
||||||
[])[0])
|
)[0]
|
||||||
|
)
|
||||||
|
|
||||||
if not SHUFFLED_ALL_TESTS:
|
if not SHUFFLED_ALL_TESTS:
|
||||||
SHUFFLED_ALL_TESTS.extend(GetTestsForAllIterations(
|
SHUFFLED_ALL_TESTS.extend(
|
||||||
{}, [AlsoRunDisabledTestsFlag(), ShuffleFlag(), RandomSeedFlag(1)])[0])
|
GetTestsForAllIterations(
|
||||||
|
{}, [AlsoRunDisabledTestsFlag(), ShuffleFlag(), RandomSeedFlag(1)]
|
||||||
|
)[0]
|
||||||
|
)
|
||||||
|
|
||||||
if not SHUFFLED_ACTIVE_TESTS:
|
if not SHUFFLED_ACTIVE_TESTS:
|
||||||
SHUFFLED_ACTIVE_TESTS.extend(GetTestsForAllIterations(
|
SHUFFLED_ACTIVE_TESTS.extend(
|
||||||
{}, [ShuffleFlag(), RandomSeedFlag(1)])[0])
|
GetTestsForAllIterations({}, [ShuffleFlag(), RandomSeedFlag(1)])[0]
|
||||||
|
)
|
||||||
|
|
||||||
if not SHUFFLED_FILTERED_TESTS:
|
if not SHUFFLED_FILTERED_TESTS:
|
||||||
SHUFFLED_FILTERED_TESTS.extend(GetTestsForAllIterations(
|
SHUFFLED_FILTERED_TESTS.extend(
|
||||||
{}, [ShuffleFlag(), RandomSeedFlag(1), FilterFlag(TEST_FILTER)])[0])
|
GetTestsForAllIterations(
|
||||||
|
{}, [ShuffleFlag(), RandomSeedFlag(1), FilterFlag(TEST_FILTER)]
|
||||||
|
)[0]
|
||||||
|
)
|
||||||
|
|
||||||
if not SHUFFLED_SHARDED_TESTS:
|
if not SHUFFLED_SHARDED_TESTS:
|
||||||
SHUFFLED_SHARDED_TESTS.extend(
|
SHUFFLED_SHARDED_TESTS.extend(
|
||||||
GetTestsForAllIterations({TOTAL_SHARDS_ENV_VAR: '3',
|
GetTestsForAllIterations(
|
||||||
SHARD_INDEX_ENV_VAR: '1'},
|
{TOTAL_SHARDS_ENV_VAR: '3', SHARD_INDEX_ENV_VAR: '1'},
|
||||||
[ShuffleFlag(), RandomSeedFlag(1)])[0])
|
[ShuffleFlag(), RandomSeedFlag(1)],
|
||||||
|
)[0]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class GTestShuffleUnitTest(gtest_test_utils.TestCase):
|
class GTestShuffleUnitTest(gtest_test_utils.TestCase):
|
||||||
@ -208,17 +220,29 @@ class GTestShuffleUnitTest(gtest_test_utils.TestCase):
|
|||||||
|
|
||||||
def testShuffleDoesNotRepeatTest(self):
|
def testShuffleDoesNotRepeatTest(self):
|
||||||
for test in SHUFFLED_ALL_TESTS:
|
for test in SHUFFLED_ALL_TESTS:
|
||||||
self.assertEqual(1, SHUFFLED_ALL_TESTS.count(test),
|
self.assertEqual(
|
||||||
'%s appears more than once' % (test,))
|
1,
|
||||||
|
SHUFFLED_ALL_TESTS.count(test),
|
||||||
|
'%s appears more than once' % (test,),
|
||||||
|
)
|
||||||
for test in SHUFFLED_ACTIVE_TESTS:
|
for test in SHUFFLED_ACTIVE_TESTS:
|
||||||
self.assertEqual(1, SHUFFLED_ACTIVE_TESTS.count(test),
|
self.assertEqual(
|
||||||
'%s appears more than once' % (test,))
|
1,
|
||||||
|
SHUFFLED_ACTIVE_TESTS.count(test),
|
||||||
|
'%s appears more than once' % (test,),
|
||||||
|
)
|
||||||
for test in SHUFFLED_FILTERED_TESTS:
|
for test in SHUFFLED_FILTERED_TESTS:
|
||||||
self.assertEqual(1, SHUFFLED_FILTERED_TESTS.count(test),
|
self.assertEqual(
|
||||||
'%s appears more than once' % (test,))
|
1,
|
||||||
|
SHUFFLED_FILTERED_TESTS.count(test),
|
||||||
|
'%s appears more than once' % (test,),
|
||||||
|
)
|
||||||
for test in SHUFFLED_SHARDED_TESTS:
|
for test in SHUFFLED_SHARDED_TESTS:
|
||||||
self.assertEqual(1, SHUFFLED_SHARDED_TESTS.count(test),
|
self.assertEqual(
|
||||||
'%s appears more than once' % (test,))
|
1,
|
||||||
|
SHUFFLED_SHARDED_TESTS.count(test),
|
||||||
|
'%s appears more than once' % (test,),
|
||||||
|
)
|
||||||
|
|
||||||
def testShuffleDoesNotCreateNewTest(self):
|
def testShuffleDoesNotCreateNewTest(self):
|
||||||
for test in SHUFFLED_ALL_TESTS:
|
for test in SHUFFLED_ALL_TESTS:
|
||||||
@ -259,9 +283,11 @@ class GTestShuffleUnitTest(gtest_test_utils.TestCase):
|
|||||||
[test_case, _] = test.split('.')
|
[test_case, _] = test.split('.')
|
||||||
if test_cases and test_cases[-1] != test_case:
|
if test_cases and test_cases[-1] != test_case:
|
||||||
test_cases.append(test_case)
|
test_cases.append(test_case)
|
||||||
self.assertEqual(1, test_cases.count(test_case),
|
self.assertEqual(
|
||||||
'Test case %s is not grouped together in %s' %
|
1,
|
||||||
(test_case, tests))
|
test_cases.count(test_case),
|
||||||
|
'Test case %s is not grouped together in %s' % (test_case, tests),
|
||||||
|
)
|
||||||
|
|
||||||
def testShuffleDoesNotInterleaveTestCases(self):
|
def testShuffleDoesNotInterleaveTestCases(self):
|
||||||
self._VerifyTestCasesDoNotInterleave(SHUFFLED_ALL_TESTS)
|
self._VerifyTestCasesDoNotInterleave(SHUFFLED_ALL_TESTS)
|
||||||
@ -278,7 +304,9 @@ class GTestShuffleUnitTest(gtest_test_utils.TestCase):
|
|||||||
# pylint: disable-next=unbalanced-tuple-unpacking
|
# pylint: disable-next=unbalanced-tuple-unpacking
|
||||||
[tests_in_iteration1, tests_in_iteration2, tests_in_iteration3] = (
|
[tests_in_iteration1, tests_in_iteration2, tests_in_iteration3] = (
|
||||||
GetTestsForAllIterations(
|
GetTestsForAllIterations(
|
||||||
{}, [ShuffleFlag(), RandomSeedFlag(1), RepeatFlag(3)]))
|
{}, [ShuffleFlag(), RandomSeedFlag(1), RepeatFlag(3)]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# Make sure running the tests with random seed 1 gets the same
|
# Make sure running the tests with random seed 1 gets the same
|
||||||
# order as in iteration 1 above.
|
# order as in iteration 1 above.
|
||||||
@ -309,7 +337,9 @@ class GTestShuffleUnitTest(gtest_test_utils.TestCase):
|
|||||||
# pylint: disable-next=unbalanced-tuple-unpacking
|
# pylint: disable-next=unbalanced-tuple-unpacking
|
||||||
[tests_in_iteration1, tests_in_iteration2, tests_in_iteration3] = (
|
[tests_in_iteration1, tests_in_iteration2, tests_in_iteration3] = (
|
||||||
GetTestsForAllIterations(
|
GetTestsForAllIterations(
|
||||||
{}, [ShuffleFlag(), RandomSeedFlag(1), RepeatFlag(3)]))
|
{}, [ShuffleFlag(), RandomSeedFlag(1), RepeatFlag(3)]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
tests_in_iteration1 != tests_in_iteration2, tests_in_iteration1
|
tests_in_iteration1 != tests_in_iteration2, tests_in_iteration1
|
||||||
@ -343,5 +373,6 @@ class GTestShuffleUnitTest(gtest_test_utils.TestCase):
|
|||||||
sorted_active_tests.sort()
|
sorted_active_tests.sort()
|
||||||
self.assertEqual(sorted_active_tests, sorted_sharded_tests)
|
self.assertEqual(sorted_active_tests, sorted_sharded_tests)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
gtest_test_utils.Main()
|
gtest_test_utils.Main()
|
||||||
|
@ -68,8 +68,10 @@ TestCase = _test_module.TestCase
|
|||||||
|
|
||||||
# Initially maps a flag to its default value. After
|
# Initially maps a flag to its default value. After
|
||||||
# _ParseAndStripGTestFlags() is called, maps a flag to its actual value.
|
# _ParseAndStripGTestFlags() is called, maps a flag to its actual value.
|
||||||
_flag_map = {'source_dir': os.path.dirname(sys.argv[0]),
|
_flag_map = {
|
||||||
'build_dir': os.path.dirname(sys.argv[0])}
|
'source_dir': os.path.dirname(sys.argv[0]),
|
||||||
|
'build_dir': os.path.dirname(sys.argv[0]),
|
||||||
|
}
|
||||||
_gtest_flags_are_parsed = False
|
_gtest_flags_are_parsed = False
|
||||||
|
|
||||||
|
|
||||||
@ -91,7 +93,7 @@ def _ParseAndStripGTestFlags(argv):
|
|||||||
while i < len(argv):
|
while i < len(argv):
|
||||||
prefix = '--' + flag + '='
|
prefix = '--' + flag + '='
|
||||||
if argv[i].startswith(prefix):
|
if argv[i].startswith(prefix):
|
||||||
_flag_map[flag] = argv[i][len(prefix):]
|
_flag_map[flag] = argv[i][len(prefix) :]
|
||||||
del argv[i]
|
del argv[i]
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
@ -147,15 +149,16 @@ def GetTestExecutablePath(executable_name, build_dir=None):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
executable_name: name of the test binary that the test script runs.
|
executable_name: name of the test binary that the test script runs.
|
||||||
build_dir: directory where to look for executables, by default
|
build_dir: directory where to look for executables, by default the
|
||||||
the result of GetBuildDir().
|
result of GetBuildDir().
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The absolute path of the test binary.
|
The absolute path of the test binary.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
path = os.path.abspath(os.path.join(build_dir or GetBuildDir(),
|
path = os.path.abspath(
|
||||||
executable_name))
|
os.path.join(build_dir or GetBuildDir(), executable_name)
|
||||||
|
)
|
||||||
if (IS_WINDOWS or IS_CYGWIN or IS_OS2) and not path.endswith('.exe'):
|
if (IS_WINDOWS or IS_CYGWIN or IS_OS2) and not path.endswith('.exe'):
|
||||||
path += '.exe'
|
path += '.exe'
|
||||||
|
|
||||||
@ -163,7 +166,8 @@ def GetTestExecutablePath(executable_name, build_dir=None):
|
|||||||
message = (
|
message = (
|
||||||
'Unable to find the test binary "%s". Please make sure to provide\n'
|
'Unable to find the test binary "%s". Please make sure to provide\n'
|
||||||
'a path to the binary via the --build_dir flag or the BUILD_DIR\n'
|
'a path to the binary via the --build_dir flag or the BUILD_DIR\n'
|
||||||
'environment variable.' % path)
|
'environment variable.' % path
|
||||||
|
)
|
||||||
print(message, file=sys.stderr)
|
print(message, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
@ -191,6 +195,7 @@ def GetExitStatus(exit_code):
|
|||||||
|
|
||||||
|
|
||||||
class Subprocess:
|
class Subprocess:
|
||||||
|
|
||||||
def __init__(self, command, working_dir=None, capture_stderr=True, env=None):
|
def __init__(self, command, working_dir=None, capture_stderr=True, env=None):
|
||||||
"""Changes into a specified directory, if provided, and executes a command.
|
"""Changes into a specified directory, if provided, and executes a command.
|
||||||
|
|
||||||
@ -200,7 +205,7 @@ class Subprocess:
|
|||||||
command: The command to run, in the form of sys.argv.
|
command: The command to run, in the form of sys.argv.
|
||||||
working_dir: The directory to change into.
|
working_dir: The directory to change into.
|
||||||
capture_stderr: Determines whether to capture stderr in the output member
|
capture_stderr: Determines whether to capture stderr in the output member
|
||||||
or to discard it.
|
or to discard it.
|
||||||
env: Dictionary with environment to pass to the subprocess.
|
env: Dictionary with environment to pass to the subprocess.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@ -220,9 +225,14 @@ class Subprocess:
|
|||||||
else:
|
else:
|
||||||
stderr = subprocess.PIPE
|
stderr = subprocess.PIPE
|
||||||
|
|
||||||
p = subprocess.Popen(command,
|
p = subprocess.Popen(
|
||||||
stdout=subprocess.PIPE, stderr=stderr,
|
command,
|
||||||
cwd=working_dir, universal_newlines=True, env=env)
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=stderr,
|
||||||
|
cwd=working_dir,
|
||||||
|
universal_newlines=True,
|
||||||
|
env=env,
|
||||||
|
)
|
||||||
# communicate returns a tuple with the file object for the child's
|
# communicate returns a tuple with the file object for the child's
|
||||||
# output.
|
# output.
|
||||||
self.output = p.communicate()[0]
|
self.output = p.communicate()[0]
|
||||||
|
@ -233,18 +233,21 @@ Expected equality of these values:
|
|||||||
|
|
||||||
GTEST_PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath(GTEST_PROGRAM_NAME)
|
GTEST_PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath(GTEST_PROGRAM_NAME)
|
||||||
|
|
||||||
SUPPORTS_TYPED_TESTS = 'TypedTest' in gtest_test_utils.Subprocess(
|
SUPPORTS_TYPED_TESTS = (
|
||||||
[GTEST_PROGRAM_PATH, GTEST_LIST_TESTS_FLAG], capture_stderr=False).output
|
'TypedTest'
|
||||||
|
in gtest_test_utils.Subprocess(
|
||||||
|
[GTEST_PROGRAM_PATH, GTEST_LIST_TESTS_FLAG], capture_stderr=False
|
||||||
|
).output
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
||||||
"""
|
"""Unit test for Google Test's XML output functionality."""
|
||||||
Unit test for Google Test's XML output functionality.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# This test currently breaks on platforms that do not support typed and
|
# This test currently breaks on platforms that do not support typed and
|
||||||
# type-parameterized tests, so we don't run it under them.
|
# type-parameterized tests, so we don't run it under them.
|
||||||
if SUPPORTS_TYPED_TESTS:
|
if SUPPORTS_TYPED_TESTS:
|
||||||
|
|
||||||
def testNonEmptyXmlOutput(self):
|
def testNonEmptyXmlOutput(self):
|
||||||
"""Generates non-empty XML and verifies it matches the expected output.
|
"""Generates non-empty XML and verifies it matches the expected output.
|
||||||
|
|
||||||
@ -274,12 +277,16 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
|||||||
# parse the expected datetime manually.
|
# parse the expected datetime manually.
|
||||||
match = re.match(r'(\d+)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)', date_time_str)
|
match = re.match(r'(\d+)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)', date_time_str)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
re.match,
|
re.match, 'XML datettime string %s has incorrect format' % date_time_str
|
||||||
'XML datettime string %s has incorrect format' % date_time_str)
|
)
|
||||||
date_time_from_xml = datetime.datetime(
|
date_time_from_xml = datetime.datetime(
|
||||||
year=int(match.group(1)), month=int(match.group(2)),
|
year=int(match.group(1)),
|
||||||
day=int(match.group(3)), hour=int(match.group(4)),
|
month=int(match.group(2)),
|
||||||
minute=int(match.group(5)), second=int(match.group(6)))
|
day=int(match.group(3)),
|
||||||
|
hour=int(match.group(4)),
|
||||||
|
minute=int(match.group(5)),
|
||||||
|
second=int(match.group(6)),
|
||||||
|
)
|
||||||
|
|
||||||
time_delta = abs(datetime.datetime.now() - date_time_from_xml)
|
time_delta = abs(datetime.datetime.now() - date_time_from_xml)
|
||||||
# timestamp value should be near the current local time
|
# timestamp value should be near the current local time
|
||||||
@ -292,10 +299,12 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
|||||||
Confirms that Google Test produces an XML output file with the expected
|
Confirms that Google Test produces an XML output file with the expected
|
||||||
default name if no name is explicitly specified.
|
default name if no name is explicitly specified.
|
||||||
"""
|
"""
|
||||||
output_file = os.path.join(gtest_test_utils.GetTempDir(),
|
output_file = os.path.join(
|
||||||
GTEST_DEFAULT_OUTPUT_FILE)
|
gtest_test_utils.GetTempDir(), GTEST_DEFAULT_OUTPUT_FILE
|
||||||
|
)
|
||||||
gtest_prog_path = gtest_test_utils.GetTestExecutablePath(
|
gtest_prog_path = gtest_test_utils.GetTestExecutablePath(
|
||||||
'gtest_no_test_unittest')
|
'gtest_no_test_unittest'
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
os.remove(output_file)
|
os.remove(output_file)
|
||||||
except OSError:
|
except OSError:
|
||||||
@ -305,7 +314,8 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
|||||||
|
|
||||||
p = gtest_test_utils.Subprocess(
|
p = gtest_test_utils.Subprocess(
|
||||||
[gtest_prog_path, '%s=xml' % GTEST_OUTPUT_FLAG],
|
[gtest_prog_path, '%s=xml' % GTEST_OUTPUT_FLAG],
|
||||||
working_dir=gtest_test_utils.GetTempDir())
|
working_dir=gtest_test_utils.GetTempDir(),
|
||||||
|
)
|
||||||
self.assertTrue(p.exited)
|
self.assertTrue(p.exited)
|
||||||
self.assertEqual(0, p.exit_code)
|
self.assertEqual(0, p.exit_code)
|
||||||
self.assertTrue(os.path.isfile(output_file))
|
self.assertTrue(os.path.isfile(output_file))
|
||||||
@ -317,20 +327,24 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
|||||||
shut down before RUN_ALL_TESTS is invoked.
|
shut down before RUN_ALL_TESTS is invoked.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
xml_path = os.path.join(gtest_test_utils.GetTempDir(),
|
xml_path = os.path.join(
|
||||||
GTEST_PROGRAM_NAME + 'out.xml')
|
gtest_test_utils.GetTempDir(), GTEST_PROGRAM_NAME + 'out.xml'
|
||||||
|
)
|
||||||
if os.path.isfile(xml_path):
|
if os.path.isfile(xml_path):
|
||||||
os.remove(xml_path)
|
os.remove(xml_path)
|
||||||
|
|
||||||
command = [GTEST_PROGRAM_PATH,
|
command = [
|
||||||
'%s=xml:%s' % (GTEST_OUTPUT_FLAG, xml_path),
|
GTEST_PROGRAM_PATH,
|
||||||
'--shut_down_xml']
|
'%s=xml:%s' % (GTEST_OUTPUT_FLAG, xml_path),
|
||||||
|
'--shut_down_xml',
|
||||||
|
]
|
||||||
p = gtest_test_utils.Subprocess(command)
|
p = gtest_test_utils.Subprocess(command)
|
||||||
if p.terminated_by_signal:
|
if p.terminated_by_signal:
|
||||||
# p.signal is available only if p.terminated_by_signal is True.
|
# p.signal is available only if p.terminated_by_signal is True.
|
||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
p.terminated_by_signal,
|
p.terminated_by_signal,
|
||||||
'%s was killed by signal %d' % (GTEST_PROGRAM_NAME, p.signal))
|
'%s was killed by signal %d' % (GTEST_PROGRAM_NAME, p.signal),
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.assertTrue(p.exited)
|
self.assertTrue(p.exited)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@ -349,8 +363,12 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
|||||||
non-selected tests do not show up in the XML output.
|
non-selected tests do not show up in the XML output.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self._TestXmlOutput(GTEST_PROGRAM_NAME, EXPECTED_FILTERED_TEST_XML, 0,
|
self._TestXmlOutput(
|
||||||
extra_args=['%s=SuccessfulTest.*' % GTEST_FILTER_FLAG])
|
GTEST_PROGRAM_NAME,
|
||||||
|
EXPECTED_FILTERED_TEST_XML,
|
||||||
|
0,
|
||||||
|
extra_args=['%s=SuccessfulTest.*' % GTEST_FILTER_FLAG],
|
||||||
|
)
|
||||||
|
|
||||||
def testShardedTestXmlOutput(self):
|
def testShardedTestXmlOutput(self):
|
||||||
"""Verifies XML output when run using multiple shards.
|
"""Verifies XML output when run using multiple shards.
|
||||||
@ -363,8 +381,8 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
|||||||
GTEST_PROGRAM_NAME,
|
GTEST_PROGRAM_NAME,
|
||||||
EXPECTED_SHARDED_TEST_XML,
|
EXPECTED_SHARDED_TEST_XML,
|
||||||
0,
|
0,
|
||||||
extra_env={SHARD_INDEX_ENV_VAR: '0',
|
extra_env={SHARD_INDEX_ENV_VAR: '0', TOTAL_SHARDS_ENV_VAR: '10'},
|
||||||
TOTAL_SHARDS_ENV_VAR: '10'})
|
)
|
||||||
|
|
||||||
def _GetXmlOutput(
|
def _GetXmlOutput(
|
||||||
self, gtest_prog_name, extra_args, extra_env, expected_exit_code
|
self, gtest_prog_name, extra_args, extra_env, expected_exit_code
|
||||||
@ -379,12 +397,15 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
|||||||
extra_env: Optional environment variables to set.
|
extra_env: Optional environment variables to set.
|
||||||
expected_exit_code: Expected exit code from running gtest_prog_name.
|
expected_exit_code: Expected exit code from running gtest_prog_name.
|
||||||
"""
|
"""
|
||||||
xml_path = os.path.join(gtest_test_utils.GetTempDir(),
|
xml_path = os.path.join(
|
||||||
gtest_prog_name + 'out.xml')
|
gtest_test_utils.GetTempDir(), gtest_prog_name + 'out.xml'
|
||||||
|
)
|
||||||
gtest_prog_path = gtest_test_utils.GetTestExecutablePath(gtest_prog_name)
|
gtest_prog_path = gtest_test_utils.GetTestExecutablePath(gtest_prog_name)
|
||||||
|
|
||||||
command = ([gtest_prog_path, '%s=xml:%s' % (GTEST_OUTPUT_FLAG, xml_path)] +
|
command = [
|
||||||
extra_args)
|
gtest_prog_path,
|
||||||
|
'%s=xml:%s' % (GTEST_OUTPUT_FLAG, xml_path),
|
||||||
|
] + extra_args
|
||||||
environ_copy = os.environ.copy()
|
environ_copy = os.environ.copy()
|
||||||
if extra_env:
|
if extra_env:
|
||||||
environ_copy.update(extra_env)
|
environ_copy.update(extra_env)
|
||||||
@ -406,8 +427,14 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
|||||||
actual = minidom.parse(xml_path)
|
actual = minidom.parse(xml_path)
|
||||||
return actual
|
return actual
|
||||||
|
|
||||||
def _TestXmlOutput(self, gtest_prog_name, expected_xml,
|
def _TestXmlOutput(
|
||||||
expected_exit_code, extra_args=None, extra_env=None):
|
self,
|
||||||
|
gtest_prog_name,
|
||||||
|
expected_xml,
|
||||||
|
expected_exit_code,
|
||||||
|
extra_args=None,
|
||||||
|
extra_env=None,
|
||||||
|
):
|
||||||
"""Asserts that the XML document matches.
|
"""Asserts that the XML document matches.
|
||||||
|
|
||||||
Asserts that the XML document generated by running the program
|
Asserts that the XML document generated by running the program
|
||||||
@ -423,12 +450,12 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
|||||||
extra_env: Optional environment variables to set.
|
extra_env: Optional environment variables to set.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
actual = self._GetXmlOutput(gtest_prog_name, extra_args or [],
|
actual = self._GetXmlOutput(
|
||||||
extra_env or {}, expected_exit_code)
|
gtest_prog_name, extra_args or [], extra_env or {}, expected_exit_code
|
||||||
|
)
|
||||||
expected = minidom.parseString(expected_xml)
|
expected = minidom.parseString(expected_xml)
|
||||||
self.NormalizeXml(actual.documentElement)
|
self.NormalizeXml(actual.documentElement)
|
||||||
self.AssertEquivalentNodes(expected.documentElement,
|
self.AssertEquivalentNodes(expected.documentElement, actual.documentElement)
|
||||||
actual.documentElement)
|
|
||||||
expected.unlink()
|
expected.unlink()
|
||||||
actual.unlink()
|
actual.unlink()
|
||||||
|
|
||||||
|
@ -35,10 +35,9 @@ from googletest.test import gtest_test_utils
|
|||||||
|
|
||||||
GTEST_DEFAULT_OUTPUT_FILE = 'test_detail.xml'
|
GTEST_DEFAULT_OUTPUT_FILE = 'test_detail.xml'
|
||||||
|
|
||||||
|
|
||||||
class GTestXMLTestCase(gtest_test_utils.TestCase):
|
class GTestXMLTestCase(gtest_test_utils.TestCase):
|
||||||
"""
|
"""Base class for tests of Google Test's XML output functionality."""
|
||||||
Base class for tests of Google Test's XML output functionality.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def AssertEquivalentNodes(self, expected_node, actual_node):
|
def AssertEquivalentNodes(self, expected_node, actual_node):
|
||||||
"""Asserts that actual_node is equivalent to expected_node.
|
"""Asserts that actual_node is equivalent to expected_node.
|
||||||
@ -165,15 +164,19 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
|
|||||||
'Encountered unknown element <%s>' % child.tagName,
|
'Encountered unknown element <%s>' % child.tagName,
|
||||||
)
|
)
|
||||||
child_id = child.getAttribute(
|
child_id = child.getAttribute(
|
||||||
self.identifying_attribute[child.tagName])
|
self.identifying_attribute[child.tagName]
|
||||||
|
)
|
||||||
self.assertNotIn(child_id, children)
|
self.assertNotIn(child_id, children)
|
||||||
children[child_id] = child
|
children[child_id] = child
|
||||||
elif child.nodeType in [Node.TEXT_NODE, Node.CDATA_SECTION_NODE]:
|
elif child.nodeType in [Node.TEXT_NODE, Node.CDATA_SECTION_NODE]:
|
||||||
if 'detail' not in children:
|
if 'detail' not in children:
|
||||||
if (child.nodeType == Node.CDATA_SECTION_NODE or
|
if (
|
||||||
not child.nodeValue.isspace()):
|
child.nodeType == Node.CDATA_SECTION_NODE
|
||||||
|
or not child.nodeValue.isspace()
|
||||||
|
):
|
||||||
children['detail'] = child.ownerDocument.createCDATASection(
|
children['detail'] = child.ownerDocument.createCDATASection(
|
||||||
child.nodeValue)
|
child.nodeValue
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
children['detail'].nodeValue += child.nodeValue
|
children['detail'].nodeValue += child.nodeValue
|
||||||
else:
|
else:
|
||||||
@ -210,8 +213,9 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
|
|||||||
source_file.value = re.sub(r'^.*[/\\](.*)', '\\1', source_file.value)
|
source_file.value = re.sub(r'^.*[/\\](.*)', '\\1', source_file.value)
|
||||||
if element.tagName in ('testsuites', 'testsuite', 'testcase'):
|
if element.tagName in ('testsuites', 'testsuite', 'testcase'):
|
||||||
timestamp = element.getAttributeNode('timestamp')
|
timestamp = element.getAttributeNode('timestamp')
|
||||||
timestamp.value = re.sub(r'^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d\d\d$',
|
timestamp.value = re.sub(
|
||||||
'*', timestamp.value)
|
r'^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d\d\d$', '*', timestamp.value
|
||||||
|
)
|
||||||
if element.tagName in ('testsuites', 'testsuite', 'testcase'):
|
if element.tagName in ('testsuites', 'testsuite', 'testcase'):
|
||||||
time = element.getAttributeNode('time')
|
time = element.getAttributeNode('time')
|
||||||
time.value = re.sub(r'^\d+(\.\d+)?$', '*', time.value)
|
time.value = re.sub(r'^\d+(\.\d+)?$', '*', time.value)
|
||||||
@ -228,8 +232,9 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
|
|||||||
# Replaces the source line information with a normalized form.
|
# Replaces the source line information with a normalized form.
|
||||||
cdata = re.sub(source_line_pat, '\\1*\n', child.nodeValue)
|
cdata = re.sub(source_line_pat, '\\1*\n', child.nodeValue)
|
||||||
# Removes the actual stack trace.
|
# Removes the actual stack trace.
|
||||||
child.nodeValue = re.sub(r'Stack trace:\n(.|\n)*',
|
child.nodeValue = re.sub(
|
||||||
'Stack trace:\n*', cdata)
|
r'Stack trace:\n(.|\n)*', 'Stack trace:\n*', cdata
|
||||||
|
)
|
||||||
for child in element.childNodes:
|
for child in element.childNodes:
|
||||||
if child.nodeType == Node.ELEMENT_NODE:
|
if child.nodeType == Node.ELEMENT_NODE:
|
||||||
self.NormalizeXml(child)
|
self.NormalizeXml(child)
|
||||||
|
Loading…
Reference in New Issue
Block a user