Replace deprecated python calls

assert_ -> assertTrue/assertFalse/assertIn/assertNotIn
assertEquals -> assertEqual

PiperOrigin-RevId: 502654909
Change-Id: I25d30095a83c3806606cb80d676b3c979495e6bd
This commit is contained in:
Tom Hughes 2023-01-17 12:15:50 -08:00 committed by Copybara-Service
parent bba28fa8b2
commit bdb3b0a493
15 changed files with 271 additions and 185 deletions

View File

@ -88,7 +88,7 @@ check your formatting.
If you plan to contribute a patch, you need to build Google Test, Google Mock, If you plan to contribute a patch, you need to build Google Test, Google Mock,
and their own tests from a git checkout, which has further requirements: and their own tests from a git checkout, which has further requirements:
* [Python](https://www.python.org/) v2.3 or newer (for running some of the * [Python](https://www.python.org/) v3.6 or newer (for running some of the
tests and re-generating certain source files from templates) tests and re-generating certain source files from templates)
* [CMake](https://cmake.org/) v2.8.12 or newer * [CMake](https://cmake.org/) v2.8.12 or newer

View File

@ -62,12 +62,12 @@ class GMockLeakTest(gmock_test_utils.TestCase):
env=environ).exit_code) env=environ).exit_code)
def testDoesNotCatchLeakedMockWhenDisabled(self): def testDoesNotCatchLeakedMockWhenDisabled(self):
self.assertEquals( self.assertEqual(
0, 0,
gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL + gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL +
['--gmock_catch_leaked_mocks=0'], ['--gmock_catch_leaked_mocks=0'],
env=environ).exit_code) env=environ).exit_code)
self.assertEquals( self.assertEqual(
0, 0,
gmock_test_utils.Subprocess(TEST_WITH_ON_CALL + gmock_test_utils.Subprocess(TEST_WITH_ON_CALL +
['--gmock_catch_leaked_mocks=0'], ['--gmock_catch_leaked_mocks=0'],

View File

@ -135,7 +135,7 @@ class GTestBreakOnFailureUnitTest(gtest_test_utils.TestCase):
msg = ('when %s%s, an assertion failure in "%s" %s cause a seg-fault.' % msg = ('when %s%s, an assertion failure in "%s" %s cause a seg-fault.' %
(BREAK_ON_FAILURE_ENV_VAR, env_var_value_msg, ' '.join(command), (BREAK_ON_FAILURE_ENV_VAR, env_var_value_msg, ' '.join(command),
should_or_not)) should_or_not))
self.assert_(has_seg_fault == expect_seg_fault, msg) self.assertTrue(has_seg_fault == expect_seg_fault, msg)
def testDefaultBehavior(self): def testDefaultBehavior(self):
"""Tests the behavior of the default mode.""" """Tests the behavior of the default mode."""

View File

@ -81,24 +81,37 @@ if SUPPORTS_SEH_EXCEPTIONS:
class CatchSehExceptionsTest(gtest_test_utils.TestCase): class CatchSehExceptionsTest(gtest_test_utils.TestCase):
"""Tests exception-catching behavior.""" """Tests exception-catching behavior."""
def TestSehExceptions(self, test_output): def TestSehExceptions(self, test_output):
self.assert_('SEH exception with code 0x2a thrown ' self.assertIn(
'in the test fixture\'s constructor' (
in test_output) 'SEH exception with code 0x2a thrown '
self.assert_('SEH exception with code 0x2a thrown ' "in the test fixture's constructor"
'in the test fixture\'s destructor' ),
in test_output) test_output,
self.assert_('SEH exception with code 0x2a thrown in SetUpTestSuite()' )
in test_output) self.assertIn(
self.assert_('SEH exception with code 0x2a thrown in TearDownTestSuite()' (
in test_output) 'SEH exception with code 0x2a thrown '
self.assert_('SEH exception with code 0x2a thrown in SetUp()' "in the test fixture's destructor"
in test_output) ),
self.assert_('SEH exception with code 0x2a thrown in TearDown()' test_output,
in test_output) )
self.assert_('SEH exception with code 0x2a thrown in the test body' self.assertIn(
in test_output) 'SEH exception with code 0x2a thrown in SetUpTestSuite()', test_output
)
self.assertIn(
'SEH exception with code 0x2a thrown in TearDownTestSuite()',
test_output,
)
self.assertIn(
'SEH exception with code 0x2a thrown in SetUp()', test_output
)
self.assertIn(
'SEH exception with code 0x2a thrown in TearDown()', test_output
)
self.assertIn(
'SEH exception with code 0x2a thrown in the test body', test_output
)
def testCatchesSehExceptionsWithCxxExceptionsEnabled(self): def testCatchesSehExceptionsWithCxxExceptionsEnabled(self):
self.TestSehExceptions(EX_BINARY_OUTPUT) self.TestSehExceptions(EX_BINARY_OUTPUT)
@ -122,10 +135,14 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase):
'"Standard C++ exception" thrown ' '"Standard C++ exception" thrown '
'in the test fixture\'s constructor' in EX_BINARY_OUTPUT, 'in the test fixture\'s constructor' in EX_BINARY_OUTPUT,
EX_BINARY_OUTPUT) EX_BINARY_OUTPUT)
self.assert_('unexpected' not in EX_BINARY_OUTPUT, self.assertTrue(
'This failure belongs in this test only if ' 'unexpected' not in EX_BINARY_OUTPUT,
'"CxxExceptionInConstructorTest" (no quotes) ' (
'appears on the same line as words "called unexpectedly"') 'This failure belongs in this test only if '
'"CxxExceptionInConstructorTest" (no quotes) '
'appears on the same line as words "called unexpectedly"'
),
)
if ('CxxExceptionInDestructorTest.ThrowsExceptionInDestructor' in if ('CxxExceptionInDestructorTest.ThrowsExceptionInDestructor' in
EX_BINARY_OUTPUT): EX_BINARY_OUTPUT):
@ -181,10 +198,14 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase):
self.assertTrue( self.assertTrue(
'CxxExceptionInSetUpTest::TearDown() ' 'CxxExceptionInSetUpTest::TearDown() '
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT) 'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
self.assert_('unexpected' not in EX_BINARY_OUTPUT, self.assertTrue(
'This failure belongs in this test only if ' 'unexpected' not in EX_BINARY_OUTPUT,
'"CxxExceptionInSetUpTest" (no quotes) ' (
'appears on the same line as words "called unexpectedly"') 'This failure belongs in this test only if '
'"CxxExceptionInSetUpTest" (no quotes) '
'appears on the same line as words "called unexpectedly"'
),
)
def testCatchesCxxExceptionsInTearDown(self): def testCatchesCxxExceptionsInTearDown(self):
self.assertTrue( self.assertTrue(
@ -227,9 +248,11 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase):
FITLER_OUT_SEH_TESTS_FLAG], FITLER_OUT_SEH_TESTS_FLAG],
env=environ).output env=environ).output
self.assert_('Unhandled C++ exception terminating the program' self.assertIn(
in uncaught_exceptions_ex_binary_output) 'Unhandled C++ exception terminating the program',
self.assert_('unexpected' not in uncaught_exceptions_ex_binary_output) uncaught_exceptions_ex_binary_output,
)
self.assertNotIn('unexpected', uncaught_exceptions_ex_binary_output)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -69,59 +69,59 @@ class GTestColorTest(gtest_test_utils.TestCase):
"""Tests the case when there's neither GTEST_COLOR nor --gtest_color.""" """Tests the case when there's neither GTEST_COLOR nor --gtest_color."""
if not IS_WINDOWS: if not IS_WINDOWS:
self.assert_(not UsesColor('dumb', None, None)) self.assertTrue(not UsesColor('dumb', None, None))
self.assert_(not UsesColor('emacs', None, None)) self.assertTrue(not UsesColor('emacs', None, None))
self.assert_(not UsesColor('xterm-mono', None, None)) self.assertTrue(not UsesColor('xterm-mono', None, None))
self.assert_(not UsesColor('unknown', None, None)) self.assertTrue(not UsesColor('unknown', None, None))
self.assert_(not UsesColor(None, None, None)) self.assertTrue(not UsesColor(None, None, None))
self.assert_(UsesColor('linux', None, None)) self.assertTrue(UsesColor('linux', None, None))
self.assert_(UsesColor('cygwin', None, None)) self.assertTrue(UsesColor('cygwin', None, None))
self.assert_(UsesColor('xterm', None, None)) self.assertTrue(UsesColor('xterm', None, None))
self.assert_(UsesColor('xterm-color', None, None)) self.assertTrue(UsesColor('xterm-color', None, None))
self.assert_(UsesColor('xterm-kitty', None, None)) self.assertTrue(UsesColor('xterm-kitty', None, None))
self.assert_(UsesColor('xterm-256color', None, None)) self.assertTrue(UsesColor('xterm-256color', None, None))
def testFlagOnly(self): def testFlagOnly(self):
"""Tests the case when there's --gtest_color but not GTEST_COLOR.""" """Tests the case when there's --gtest_color but not GTEST_COLOR."""
self.assert_(not UsesColor('dumb', None, 'no')) self.assertTrue(not UsesColor('dumb', None, 'no'))
self.assert_(not UsesColor('xterm-color', None, 'no')) self.assertTrue(not UsesColor('xterm-color', None, 'no'))
if not IS_WINDOWS: if not IS_WINDOWS:
self.assert_(not UsesColor('emacs', None, 'auto')) self.assertTrue(not UsesColor('emacs', None, 'auto'))
self.assert_(UsesColor('xterm', None, 'auto')) self.assertTrue(UsesColor('xterm', None, 'auto'))
self.assert_(UsesColor('dumb', None, 'yes')) self.assertTrue(UsesColor('dumb', None, 'yes'))
self.assert_(UsesColor('xterm', None, 'yes')) self.assertTrue(UsesColor('xterm', None, 'yes'))
def testEnvVarOnly(self): def testEnvVarOnly(self):
"""Tests the case when there's GTEST_COLOR but not --gtest_color.""" """Tests the case when there's GTEST_COLOR but not --gtest_color."""
self.assert_(not UsesColor('dumb', 'no', None)) self.assertTrue(not UsesColor('dumb', 'no', None))
self.assert_(not UsesColor('xterm-color', 'no', None)) self.assertTrue(not UsesColor('xterm-color', 'no', None))
if not IS_WINDOWS: if not IS_WINDOWS:
self.assert_(not UsesColor('dumb', 'auto', None)) self.assertTrue(not UsesColor('dumb', 'auto', None))
self.assert_(UsesColor('xterm-color', 'auto', None)) self.assertTrue(UsesColor('xterm-color', 'auto', None))
self.assert_(UsesColor('dumb', 'yes', None)) self.assertTrue(UsesColor('dumb', 'yes', None))
self.assert_(UsesColor('xterm-color', 'yes', None)) self.assertTrue(UsesColor('xterm-color', 'yes', None))
def testEnvVarAndFlag(self): def testEnvVarAndFlag(self):
"""Tests the case when there are both GTEST_COLOR and --gtest_color.""" """Tests the case when there are both GTEST_COLOR and --gtest_color."""
self.assert_(not UsesColor('xterm-color', 'no', 'no')) self.assertTrue(not UsesColor('xterm-color', 'no', 'no'))
self.assert_(UsesColor('dumb', 'no', 'yes')) self.assertTrue(UsesColor('dumb', 'no', 'yes'))
self.assert_(UsesColor('xterm-color', 'no', 'auto')) self.assertTrue(UsesColor('xterm-color', 'no', 'auto'))
def testAliasesOfYesAndNo(self): def testAliasesOfYesAndNo(self):
"""Tests using aliases in specifying --gtest_color.""" """Tests using aliases in specifying --gtest_color."""
self.assert_(UsesColor('dumb', None, 'true')) self.assertTrue(UsesColor('dumb', None, 'true'))
self.assert_(UsesColor('dumb', None, 'YES')) self.assertTrue(UsesColor('dumb', None, 'YES'))
self.assert_(UsesColor('dumb', None, 'T')) self.assertTrue(UsesColor('dumb', None, 'T'))
self.assert_(UsesColor('dumb', None, '1')) self.assertTrue(UsesColor('dumb', None, '1'))
self.assert_(not UsesColor('xterm', None, 'f')) self.assertTrue(not UsesColor('xterm', None, 'f'))
self.assert_(not UsesColor('xterm', None, 'false')) self.assertTrue(not UsesColor('xterm', None, 'false'))
self.assert_(not UsesColor('xterm', None, '0')) self.assertTrue(not UsesColor('xterm', None, '0'))
self.assert_(not UsesColor('xterm', None, 'unknown')) self.assertTrue(not UsesColor('xterm', None, 'unknown'))
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -250,10 +250,10 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
"""Asserts that two sets are equal.""" """Asserts that two sets are equal."""
for elem in lhs: for elem in lhs:
self.assert_(elem in rhs, '%s in %s' % (elem, rhs)) self.assertTrue(elem in rhs, '%s in %s' % (elem, rhs))
for elem in rhs: for elem in rhs:
self.assert_(elem in lhs, '%s in %s' % (elem, lhs)) self.assertTrue(elem in lhs, '%s in %s' % (elem, lhs))
def AssertPartitionIsValid(self, set_var, list_of_sets): def AssertPartitionIsValid(self, set_var, list_of_sets):
"""Asserts that list_of_sets is a valid partition of set_var.""" """Asserts that list_of_sets is a valid partition of set_var."""
@ -595,13 +595,13 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
shard_status_file = os.path.join(gtest_test_utils.GetTempDir(), shard_status_file = os.path.join(gtest_test_utils.GetTempDir(),
'shard_status_file') 'shard_status_file')
self.assert_(not os.path.exists(shard_status_file)) self.assertTrue(not os.path.exists(shard_status_file))
extra_env = {SHARD_STATUS_FILE_ENV_VAR: shard_status_file} extra_env = {SHARD_STATUS_FILE_ENV_VAR: shard_status_file}
try: try:
InvokeWithModifiedEnv(extra_env, RunAndReturnOutput) InvokeWithModifiedEnv(extra_env, RunAndReturnOutput)
finally: finally:
self.assert_(os.path.exists(shard_status_file)) self.assertTrue(os.path.exists(shard_status_file))
os.remove(shard_status_file) os.remove(shard_status_file)
def testShardStatusFileIsCreatedWithListTests(self): def testShardStatusFileIsCreatedWithListTests(self):
@ -609,7 +609,7 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
shard_status_file = os.path.join(gtest_test_utils.GetTempDir(), shard_status_file = os.path.join(gtest_test_utils.GetTempDir(),
'shard_status_file2') 'shard_status_file2')
self.assert_(not os.path.exists(shard_status_file)) self.assertTrue(not os.path.exists(shard_status_file))
extra_env = {SHARD_STATUS_FILE_ENV_VAR: shard_status_file} extra_env = {SHARD_STATUS_FILE_ENV_VAR: shard_status_file}
try: try:
@ -619,12 +619,16 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
finally: finally:
# This assertion ensures that Google Test enumerated the tests as # This assertion ensures that Google Test enumerated the tests as
# opposed to running them. # opposed to running them.
self.assert_('[==========]' not in output, self.assertTrue(
'Unexpected output during test enumeration.\n' '[==========]' not in output,
'Please ensure that LIST_TESTS_FLAG is assigned the\n' (
'correct flag value for listing Google Test tests.') 'Unexpected output during test enumeration.\n'
'Please ensure that LIST_TESTS_FLAG is assigned the\n'
'correct flag value for listing Google Test tests.'
),
)
self.assert_(os.path.exists(shard_status_file)) self.assertTrue(os.path.exists(shard_status_file))
os.remove(shard_status_file) os.remove(shard_status_file)
def testDisabledBanner(self): def testDisabledBanner(self):

View File

@ -171,15 +171,17 @@ class GTestJsonOutFilesTest(gtest_test_utils.TestCase):
command = [gtest_prog_path, '--gtest_output=json:%s' % self.output_dir_] command = [gtest_prog_path, '--gtest_output=json:%s' % self.output_dir_]
p = gtest_test_utils.Subprocess(command, p = gtest_test_utils.Subprocess(command,
working_dir=gtest_test_utils.GetTempDir()) working_dir=gtest_test_utils.GetTempDir())
self.assert_(p.exited) self.assertTrue(p.exited)
self.assertEquals(0, p.exit_code) self.assertEqual(0, p.exit_code)
output_file_name1 = test_name + '.json' output_file_name1 = test_name + '.json'
output_file1 = os.path.join(self.output_dir_, output_file_name1) output_file1 = os.path.join(self.output_dir_, output_file_name1)
output_file_name2 = 'lt-' + output_file_name1 output_file_name2 = 'lt-' + output_file_name1
output_file2 = os.path.join(self.output_dir_, output_file_name2) output_file2 = os.path.join(self.output_dir_, output_file_name2)
self.assert_(os.path.isfile(output_file1) or os.path.isfile(output_file2), self.assertTrue(
output_file1) os.path.isfile(output_file1) or os.path.isfile(output_file2),
output_file1,
)
if os.path.isfile(output_file1): if os.path.isfile(output_file1):
with open(output_file1) as f: with open(output_file1) as f:

View File

@ -806,9 +806,9 @@ class GTestJsonOutputUnitTest(gtest_test_utils.TestCase):
p = gtest_test_utils.Subprocess( p = gtest_test_utils.Subprocess(
[gtest_prog_path, '%s=json' % GTEST_OUTPUT_FLAG], [gtest_prog_path, '%s=json' % GTEST_OUTPUT_FLAG],
working_dir=gtest_test_utils.GetTempDir()) working_dir=gtest_test_utils.GetTempDir())
self.assert_(p.exited) self.assertTrue(p.exited)
self.assertEquals(0, p.exit_code) self.assertEqual(0, p.exit_code)
self.assert_(os.path.isfile(output_file)) self.assertTrue(os.path.isfile(output_file))
def testSuppressedJsonOutput(self): def testSuppressedJsonOutput(self):
"""Verifies that no JSON output is generated. """Verifies that no JSON output is generated.
@ -832,13 +832,15 @@ class GTestJsonOutputUnitTest(gtest_test_utils.TestCase):
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.assert_(p.exited) self.assertTrue(p.exited)
self.assertEquals(1, p.exit_code, self.assertEqual(
"'%s' exited with code %s, which doesn't match " 1,
'the expected exit code %s.' p.exit_code,
% (command, p.exit_code, 1)) "'%s' exited with code %s, which doesn't match "
'the expected exit code %s.' % (command, p.exit_code, 1),
)
self.assert_(not os.path.isfile(json_path)) self.assertTrue(not os.path.isfile(json_path))
def testFilteredTestJsonOutput(self): def testFilteredTestJsonOutput(self):
"""Verifies JSON output when a filter is applied. """Verifies JSON output when a filter is applied.
@ -870,14 +872,18 @@ class GTestJsonOutputUnitTest(gtest_test_utils.TestCase):
) )
p = gtest_test_utils.Subprocess(command) p = gtest_test_utils.Subprocess(command)
if p.terminated_by_signal: if p.terminated_by_signal:
self.assert_(False, self.assertTrue(
'%s was killed by signal %d' % (gtest_prog_name, p.signal)) False, '%s was killed by signal %d' % (gtest_prog_name, p.signal)
)
else: else:
self.assert_(p.exited) self.assertTrue(p.exited)
self.assertEquals(expected_exit_code, p.exit_code, self.assertEqual(
"'%s' exited with code %s, which doesn't match " expected_exit_code,
'the expected exit code %s.' p.exit_code,
% (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),
)
with open(json_path) as f: with open(json_path) as f:
actual = json.load(f) actual = json.load(f)
return actual return actual

View File

@ -156,17 +156,24 @@ class GTestListTestsUnitTest(gtest_test_utils.TestCase):
output = Run(args) output = Run(args)
if expected_output_re: if expected_output_re:
self.assert_( self.assertTrue(
expected_output_re.match(output), expected_output_re.match(output),
('when %s is %s, the output of "%s" is "%s",\n' 'when %s is %s, the output of "%s" is "%s",\n'
'which does not match regex "%s"' % 'which does not match regex "%s"'
(LIST_TESTS_FLAG, flag_expression, ' '.join(args), output, % (
expected_output_re.pattern))) LIST_TESTS_FLAG,
flag_expression,
' '.join(args),
output,
expected_output_re.pattern,
),
)
else: else:
self.assert_( self.assertTrue(
not EXPECTED_OUTPUT_NO_FILTER_RE.match(output), not EXPECTED_OUTPUT_NO_FILTER_RE.match(output),
('when %s is %s, the output of "%s" is "%s"'% 'when %s is %s, the output of "%s" is "%s"'
(LIST_TESTS_FLAG, flag_expression, ' '.join(args), output))) % (LIST_TESTS_FLAG, flag_expression, ' '.join(args), output),
)
def testDefaultBehavior(self): def testDefaultBehavior(self):
"""Tests the behavior of the default mode.""" """Tests the behavior of the default mode."""

View File

@ -177,25 +177,34 @@ class GTestShuffleUnitTest(gtest_test_utils.TestCase):
self.assertEqual(len(SHARDED_TESTS), len(SHUFFLED_SHARDED_TESTS)) self.assertEqual(len(SHARDED_TESTS), len(SHUFFLED_SHARDED_TESTS))
def testShuffleChangesTestOrder(self): def testShuffleChangesTestOrder(self):
self.assert_(SHUFFLED_ALL_TESTS != ALL_TESTS, SHUFFLED_ALL_TESTS) self.assertTrue(SHUFFLED_ALL_TESTS != ALL_TESTS, SHUFFLED_ALL_TESTS)
self.assert_(SHUFFLED_ACTIVE_TESTS != ACTIVE_TESTS, SHUFFLED_ACTIVE_TESTS) self.assertTrue(
self.assert_(SHUFFLED_FILTERED_TESTS != FILTERED_TESTS, SHUFFLED_ACTIVE_TESTS != ACTIVE_TESTS, SHUFFLED_ACTIVE_TESTS
SHUFFLED_FILTERED_TESTS) )
self.assert_(SHUFFLED_SHARDED_TESTS != SHARDED_TESTS, self.assertTrue(
SHUFFLED_SHARDED_TESTS) SHUFFLED_FILTERED_TESTS != FILTERED_TESTS, SHUFFLED_FILTERED_TESTS
)
self.assertTrue(
SHUFFLED_SHARDED_TESTS != SHARDED_TESTS, SHUFFLED_SHARDED_TESTS
)
def testShuffleChangesTestCaseOrder(self): def testShuffleChangesTestCaseOrder(self):
self.assert_(GetTestCases(SHUFFLED_ALL_TESTS) != GetTestCases(ALL_TESTS), self.assertTrue(
GetTestCases(SHUFFLED_ALL_TESTS)) GetTestCases(SHUFFLED_ALL_TESTS) != GetTestCases(ALL_TESTS),
self.assert_( GetTestCases(SHUFFLED_ALL_TESTS),
)
self.assertTrue(
GetTestCases(SHUFFLED_ACTIVE_TESTS) != GetTestCases(ACTIVE_TESTS), GetTestCases(SHUFFLED_ACTIVE_TESTS) != GetTestCases(ACTIVE_TESTS),
GetTestCases(SHUFFLED_ACTIVE_TESTS)) GetTestCases(SHUFFLED_ACTIVE_TESTS),
self.assert_( )
self.assertTrue(
GetTestCases(SHUFFLED_FILTERED_TESTS) != GetTestCases(FILTERED_TESTS), GetTestCases(SHUFFLED_FILTERED_TESTS) != GetTestCases(FILTERED_TESTS),
GetTestCases(SHUFFLED_FILTERED_TESTS)) GetTestCases(SHUFFLED_FILTERED_TESTS),
self.assert_( )
self.assertTrue(
GetTestCases(SHUFFLED_SHARDED_TESTS) != GetTestCases(SHARDED_TESTS), GetTestCases(SHUFFLED_SHARDED_TESTS) != GetTestCases(SHARDED_TESTS),
GetTestCases(SHUFFLED_SHARDED_TESTS)) GetTestCases(SHUFFLED_SHARDED_TESTS),
)
def testShuffleDoesNotRepeatTest(self): def testShuffleDoesNotRepeatTest(self):
for test in SHUFFLED_ALL_TESTS: for test in SHUFFLED_ALL_TESTS:
@ -213,30 +222,34 @@ class GTestShuffleUnitTest(gtest_test_utils.TestCase):
def testShuffleDoesNotCreateNewTest(self): def testShuffleDoesNotCreateNewTest(self):
for test in SHUFFLED_ALL_TESTS: for test in SHUFFLED_ALL_TESTS:
self.assert_(test in ALL_TESTS, '%s is an invalid test' % (test,)) self.assertTrue(test in ALL_TESTS, '%s is an invalid test' % (test,))
for test in SHUFFLED_ACTIVE_TESTS: for test in SHUFFLED_ACTIVE_TESTS:
self.assert_(test in ACTIVE_TESTS, '%s is an invalid test' % (test,)) self.assertTrue(test in ACTIVE_TESTS, '%s is an invalid test' % (test,))
for test in SHUFFLED_FILTERED_TESTS: for test in SHUFFLED_FILTERED_TESTS:
self.assert_(test in FILTERED_TESTS, '%s is an invalid test' % (test,)) self.assertTrue(test in FILTERED_TESTS, '%s is an invalid test' % (test,))
for test in SHUFFLED_SHARDED_TESTS: for test in SHUFFLED_SHARDED_TESTS:
self.assert_(test in SHARDED_TESTS, '%s is an invalid test' % (test,)) self.assertTrue(test in SHARDED_TESTS, '%s is an invalid test' % (test,))
def testShuffleIncludesAllTests(self): def testShuffleIncludesAllTests(self):
for test in ALL_TESTS: for test in ALL_TESTS:
self.assert_(test in SHUFFLED_ALL_TESTS, '%s is missing' % (test,)) self.assertTrue(test in SHUFFLED_ALL_TESTS, '%s is missing' % (test,))
for test in ACTIVE_TESTS: for test in ACTIVE_TESTS:
self.assert_(test in SHUFFLED_ACTIVE_TESTS, '%s is missing' % (test,)) self.assertTrue(test in SHUFFLED_ACTIVE_TESTS, '%s is missing' % (test,))
for test in FILTERED_TESTS: for test in FILTERED_TESTS:
self.assert_(test in SHUFFLED_FILTERED_TESTS, '%s is missing' % (test,)) self.assertTrue(
test in SHUFFLED_FILTERED_TESTS, '%s is missing' % (test,)
)
for test in SHARDED_TESTS: for test in SHARDED_TESTS:
self.assert_(test in SHUFFLED_SHARDED_TESTS, '%s is missing' % (test,)) self.assertTrue(test in SHUFFLED_SHARDED_TESTS, '%s is missing' % (test,))
def testShuffleLeavesDeathTestsAtFront(self): def testShuffleLeavesDeathTestsAtFront(self):
non_death_test_found = False non_death_test_found = False
for test in SHUFFLED_ACTIVE_TESTS: for test in SHUFFLED_ACTIVE_TESTS:
if 'DeathTest.' in test: if 'DeathTest.' in test:
self.assert_(not non_death_test_found, self.assertTrue(
'%s appears after a non-death test' % (test,)) not non_death_test_found,
'%s appears after a non-death test' % (test,),
)
else: else:
non_death_test_found = True non_death_test_found = True
@ -293,12 +306,15 @@ class GTestShuffleUnitTest(gtest_test_utils.TestCase):
GetTestsForAllIterations( GetTestsForAllIterations(
{}, [ShuffleFlag(), RandomSeedFlag(1), RepeatFlag(3)])) {}, [ShuffleFlag(), RandomSeedFlag(1), RepeatFlag(3)]))
self.assert_(tests_in_iteration1 != tests_in_iteration2, self.assertTrue(
tests_in_iteration1) tests_in_iteration1 != tests_in_iteration2, tests_in_iteration1
self.assert_(tests_in_iteration1 != tests_in_iteration3, )
tests_in_iteration1) self.assertTrue(
self.assert_(tests_in_iteration2 != tests_in_iteration3, tests_in_iteration1 != tests_in_iteration3, tests_in_iteration1
tests_in_iteration2) )
self.assertTrue(
tests_in_iteration2 != tests_in_iteration3, tests_in_iteration2
)
def testShuffleShardedTestsPreservesPartition(self): def testShuffleShardedTestsPreservesPartition(self):
# If we run M tests on N shards, the same M tests should be run in # If we run M tests on N shards, the same M tests should be run in

View File

@ -120,7 +120,7 @@ class ThrowOnFailureTest(gtest_test_utils.TestCase):
'exit code.' % 'exit code.' %
(THROW_ON_FAILURE, env_var_value_msg, ' '.join(command), (THROW_ON_FAILURE, env_var_value_msg, ' '.join(command),
should_or_not)) should_or_not))
self.assert_(failed == should_fail, msg) self.assertTrue(failed == should_fail, msg)
def testDefaultBehavior(self): def testDefaultBehavior(self):
"""Tests the behavior of the default mode.""" """Tests the behavior of the default mode."""

View File

@ -52,7 +52,7 @@ class GTestTestFilterTest(gtest_test_utils.TestCase):
subprocess_env[TESTBRIDGE_NAME] = '*.TestThatSucceeds' subprocess_env[TESTBRIDGE_NAME] = '*.TestThatSucceeds'
p = gtest_test_utils.Subprocess(COMMAND, env=subprocess_env) p = gtest_test_utils.Subprocess(COMMAND, env=subprocess_env)
self.assertEquals(0, p.exit_code) self.assertEqual(0, p.exit_code)
Assert('filter = *.TestThatSucceeds' in p.output) Assert('filter = *.TestThatSucceeds' in p.output)
Assert('[ OK ] TestFilterTest.TestThatSucceeds' in p.output) Assert('[ OK ] TestFilterTest.TestThatSucceeds' in p.output)

View File

@ -108,15 +108,17 @@ class GTestXMLOutFilesTest(gtest_xml_test_utils.GTestXMLTestCase):
command = [gtest_prog_path, "--gtest_output=xml:%s" % self.output_dir_] command = [gtest_prog_path, "--gtest_output=xml:%s" % self.output_dir_]
p = gtest_test_utils.Subprocess(command, p = gtest_test_utils.Subprocess(command,
working_dir=gtest_test_utils.GetTempDir()) working_dir=gtest_test_utils.GetTempDir())
self.assert_(p.exited) self.assertTrue(p.exited)
self.assertEquals(0, p.exit_code) self.assertEqual(0, p.exit_code)
output_file_name1 = test_name + ".xml" output_file_name1 = test_name + ".xml"
output_file1 = os.path.join(self.output_dir_, output_file_name1) output_file1 = os.path.join(self.output_dir_, output_file_name1)
output_file_name2 = 'lt-' + output_file_name1 output_file_name2 = 'lt-' + output_file_name1
output_file2 = os.path.join(self.output_dir_, output_file_name2) output_file2 = os.path.join(self.output_dir_, output_file_name2)
self.assert_(os.path.isfile(output_file1) or os.path.isfile(output_file2), self.assertTrue(
output_file1) os.path.isfile(output_file1) or os.path.isfile(output_file2),
output_file1,
)
expected = minidom.parseString(expected_xml) expected = minidom.parseString(expected_xml)
if os.path.isfile(output_file1): if os.path.isfile(output_file1):

View File

@ -305,9 +305,9 @@ 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.assert_(p.exited) self.assertTrue(p.exited)
self.assertEquals(0, p.exit_code) self.assertEqual(0, p.exit_code)
self.assert_(os.path.isfile(output_file)) self.assertTrue(os.path.isfile(output_file))
def testSuppressedXmlOutput(self): def testSuppressedXmlOutput(self):
""" """
@ -330,13 +330,15 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
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.assert_(p.exited) self.assertTrue(p.exited)
self.assertEquals(1, p.exit_code, self.assertEqual(
"'%s' exited with code %s, which doesn't match " 1,
'the expected exit code %s.' p.exit_code,
% (command, p.exit_code, 1)) "'%s' exited with code %s, which doesn't match "
'the expected exit code %s.' % (command, p.exit_code, 1),
)
self.assert_(not os.path.isfile(xml_path)) self.assertFalse(os.path.isfile(xml_path))
def testFilteredTestXmlOutput(self): def testFilteredTestXmlOutput(self):
"""Verifies XML output when a filter is applied. """Verifies XML output when a filter is applied.
@ -380,14 +382,18 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
p = gtest_test_utils.Subprocess(command, env=environ_copy) p = gtest_test_utils.Subprocess(command, env=environ_copy)
if p.terminated_by_signal: if p.terminated_by_signal:
self.assert_(False, self.assertTrue(
'%s was killed by signal %d' % (gtest_prog_name, p.signal)) False, '%s was killed by signal %d' % (gtest_prog_name, p.signal)
)
else: else:
self.assert_(p.exited) self.assertTrue(p.exited)
self.assertEquals(expected_exit_code, p.exit_code, self.assertEqual(
"'%s' exited with code %s, which doesn't match " expected_exit_code,
'the expected exit code %s.' p.exit_code,
% (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) actual = minidom.parse(xml_path)
return actual return actual

View File

@ -61,43 +61,59 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
""" """
if expected_node.nodeType == Node.CDATA_SECTION_NODE: if expected_node.nodeType == Node.CDATA_SECTION_NODE:
self.assertEquals(Node.CDATA_SECTION_NODE, actual_node.nodeType) self.assertEqual(Node.CDATA_SECTION_NODE, actual_node.nodeType)
self.assertEquals(expected_node.nodeValue, actual_node.nodeValue) self.assertEqual(expected_node.nodeValue, actual_node.nodeValue)
return return
self.assertEquals(Node.ELEMENT_NODE, actual_node.nodeType) self.assertEqual(Node.ELEMENT_NODE, actual_node.nodeType)
self.assertEquals(Node.ELEMENT_NODE, expected_node.nodeType) self.assertEqual(Node.ELEMENT_NODE, expected_node.nodeType)
self.assertEquals(expected_node.tagName, actual_node.tagName) self.assertEqual(expected_node.tagName, actual_node.tagName)
expected_attributes = expected_node.attributes expected_attributes = expected_node.attributes
actual_attributes = actual_node.attributes actual_attributes = actual_node.attributes
self.assertEquals( self.assertEqual(
expected_attributes.length, actual_attributes.length, expected_attributes.length,
'attribute numbers differ in element %s:\nExpected: %r\nActual: %r' % ( actual_attributes.length,
actual_node.tagName, expected_attributes.keys(), 'attribute numbers differ in element %s:\nExpected: %r\nActual: %r'
actual_attributes.keys())) % (
actual_node.tagName,
expected_attributes.keys(),
actual_attributes.keys(),
),
)
for i in range(expected_attributes.length): for i in range(expected_attributes.length):
expected_attr = expected_attributes.item(i) expected_attr = expected_attributes.item(i)
actual_attr = actual_attributes.get(expected_attr.name) actual_attr = actual_attributes.get(expected_attr.name)
self.assert_( self.assertTrue(
actual_attr is not None, actual_attr is not None,
'expected attribute %s not found in element %s' % 'expected attribute %s not found in element %s'
(expected_attr.name, actual_node.tagName)) % (expected_attr.name, actual_node.tagName),
self.assertEquals( )
expected_attr.value, actual_attr.value, self.assertEqual(
' values of attribute %s in element %s differ: %s vs %s' % expected_attr.value,
(expected_attr.name, actual_node.tagName, actual_attr.value,
expected_attr.value, actual_attr.value)) ' values of attribute %s in element %s differ: %s vs %s'
% (
expected_attr.name,
actual_node.tagName,
expected_attr.value,
actual_attr.value,
),
)
expected_children = self._GetChildren(expected_node) expected_children = self._GetChildren(expected_node)
actual_children = self._GetChildren(actual_node) actual_children = self._GetChildren(actual_node)
self.assertEquals( self.assertEqual(
len(expected_children), len(actual_children), len(expected_children),
'number of child elements differ in element ' + actual_node.tagName) len(actual_children),
'number of child elements differ in element ' + actual_node.tagName,
)
for child_id, child in expected_children.items(): for child_id, child in expected_children.items():
self.assert_(child_id in actual_children, self.assertTrue(
'<%s> is not in <%s> (in element %s)' % child_id in actual_children,
(child_id, actual_children, actual_node.tagName)) '<%s> is not in <%s> (in element %s)'
% (child_id, actual_children, actual_node.tagName),
)
self.AssertEquivalentNodes(child, actual_children[child_id]) self.AssertEquivalentNodes(child, actual_children[child_id])
identifying_attribute = { identifying_attribute = {
@ -128,15 +144,19 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
for child in element.childNodes: for child in element.childNodes:
if child.nodeType == Node.ELEMENT_NODE: if child.nodeType == Node.ELEMENT_NODE:
if child.tagName == 'properties': if child.tagName == 'properties':
self.assert_(child.parentNode is not None, self.assertTrue(
'Encountered <properties> element without a parent') child.parentNode is not None,
'Encountered <properties> element without a parent',
)
child_id = child.parentNode.getAttribute('name') + '-properties' child_id = child.parentNode.getAttribute('name') + '-properties'
else: else:
self.assert_(child.tagName in self.identifying_attribute, self.assertTrue(
'Encountered unknown element <%s>' % child.tagName) child.tagName in self.identifying_attribute,
'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.assert_(child_id not in 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: