Skip to content

Commit bdb3b0a

Browse files
thughescopybara-github
authored andcommitted
Replace deprecated python calls
assert_ -> assertTrue/assertFalse/assertIn/assertNotIn assertEquals -> assertEqual PiperOrigin-RevId: 502654909 Change-Id: I25d30095a83c3806606cb80d676b3c979495e6bd
1 parent bba28fa commit bdb3b0a

15 files changed

+272
-186
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ check your formatting.
8888
If you plan to contribute a patch, you need to build Google Test, Google Mock,
8989
and their own tests from a git checkout, which has further requirements:
9090

91-
* [Python](https://www.python.org/) v2.3 or newer (for running some of the
91+
* [Python](https://www.python.org/) v3.6 or newer (for running some of the
9292
tests and re-generating certain source files from templates)
9393
* [CMake](https://cmake.org/) v2.8.12 or newer
9494

googlemock/test/gmock_leak_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ def testCatchesLeakedMockByDefault(self):
6262
env=environ).exit_code)
6363

6464
def testDoesNotCatchLeakedMockWhenDisabled(self):
65-
self.assertEquals(
65+
self.assertEqual(
6666
0,
6767
gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL +
6868
['--gmock_catch_leaked_mocks=0'],
6969
env=environ).exit_code)
70-
self.assertEquals(
70+
self.assertEqual(
7171
0,
7272
gmock_test_utils.Subprocess(TEST_WITH_ON_CALL +
7373
['--gmock_catch_leaked_mocks=0'],

googletest/test/googletest-break-on-failure-unittest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def RunAndVerify(self, env_var_value, flag_value, expect_seg_fault):
135135
msg = ('when %s%s, an assertion failure in "%s" %s cause a seg-fault.' %
136136
(BREAK_ON_FAILURE_ENV_VAR, env_var_value_msg, ' '.join(command),
137137
should_or_not))
138-
self.assert_(has_seg_fault == expect_seg_fault, msg)
138+
self.assertTrue(has_seg_fault == expect_seg_fault, msg)
139139

140140
def testDefaultBehavior(self):
141141
"""Tests the behavior of the default mode."""

googletest/test/googletest-catch-exceptions-test.py

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,37 @@
8181
class CatchSehExceptionsTest(gtest_test_utils.TestCase):
8282
"""Tests exception-catching behavior."""
8383

84-
8584
def TestSehExceptions(self, test_output):
86-
self.assert_('SEH exception with code 0x2a thrown '
87-
'in the test fixture\'s constructor'
88-
in test_output)
89-
self.assert_('SEH exception with code 0x2a thrown '
90-
'in the test fixture\'s destructor'
91-
in test_output)
92-
self.assert_('SEH exception with code 0x2a thrown in SetUpTestSuite()'
93-
in test_output)
94-
self.assert_('SEH exception with code 0x2a thrown in TearDownTestSuite()'
95-
in test_output)
96-
self.assert_('SEH exception with code 0x2a thrown in SetUp()'
97-
in test_output)
98-
self.assert_('SEH exception with code 0x2a thrown in TearDown()'
99-
in test_output)
100-
self.assert_('SEH exception with code 0x2a thrown in the test body'
101-
in test_output)
85+
self.assertIn(
86+
(
87+
'SEH exception with code 0x2a thrown '
88+
"in the test fixture's constructor"
89+
),
90+
test_output,
91+
)
92+
self.assertIn(
93+
(
94+
'SEH exception with code 0x2a thrown '
95+
"in the test fixture's destructor"
96+
),
97+
test_output,
98+
)
99+
self.assertIn(
100+
'SEH exception with code 0x2a thrown in SetUpTestSuite()', test_output
101+
)
102+
self.assertIn(
103+
'SEH exception with code 0x2a thrown in TearDownTestSuite()',
104+
test_output,
105+
)
106+
self.assertIn(
107+
'SEH exception with code 0x2a thrown in SetUp()', test_output
108+
)
109+
self.assertIn(
110+
'SEH exception with code 0x2a thrown in TearDown()', test_output
111+
)
112+
self.assertIn(
113+
'SEH exception with code 0x2a thrown in the test body', test_output
114+
)
102115

103116
def testCatchesSehExceptionsWithCxxExceptionsEnabled(self):
104117
self.TestSehExceptions(EX_BINARY_OUTPUT)
@@ -122,10 +135,14 @@ def testCatchesCxxExceptionsInFixtureConstructor(self):
122135
'"Standard C++ exception" thrown '
123136
'in the test fixture\'s constructor' in EX_BINARY_OUTPUT,
124137
EX_BINARY_OUTPUT)
125-
self.assert_('unexpected' not in EX_BINARY_OUTPUT,
126-
'This failure belongs in this test only if '
127-
'"CxxExceptionInConstructorTest" (no quotes) '
128-
'appears on the same line as words "called unexpectedly"')
138+
self.assertTrue(
139+
'unexpected' not in EX_BINARY_OUTPUT,
140+
(
141+
'This failure belongs in this test only if '
142+
'"CxxExceptionInConstructorTest" (no quotes) '
143+
'appears on the same line as words "called unexpectedly"'
144+
),
145+
)
129146

130147
if ('CxxExceptionInDestructorTest.ThrowsExceptionInDestructor' in
131148
EX_BINARY_OUTPUT):
@@ -181,10 +198,14 @@ def testCatchesCxxExceptionsInSetUp(self):
181198
self.assertTrue(
182199
'CxxExceptionInSetUpTest::TearDown() '
183200
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
184-
self.assert_('unexpected' not in EX_BINARY_OUTPUT,
185-
'This failure belongs in this test only if '
186-
'"CxxExceptionInSetUpTest" (no quotes) '
187-
'appears on the same line as words "called unexpectedly"')
201+
self.assertTrue(
202+
'unexpected' not in EX_BINARY_OUTPUT,
203+
(
204+
'This failure belongs in this test only if '
205+
'"CxxExceptionInSetUpTest" (no quotes) '
206+
'appears on the same line as words "called unexpectedly"'
207+
),
208+
)
188209

189210
def testCatchesCxxExceptionsInTearDown(self):
190211
self.assertTrue(
@@ -227,9 +248,11 @@ def testUnhandledCxxExceptionsAbortTheProgram(self):
227248
FITLER_OUT_SEH_TESTS_FLAG],
228249
env=environ).output
229250

230-
self.assert_('Unhandled C++ exception terminating the program'
231-
in uncaught_exceptions_ex_binary_output)
232-
self.assert_('unexpected' not in uncaught_exceptions_ex_binary_output)
251+
self.assertIn(
252+
'Unhandled C++ exception terminating the program',
253+
uncaught_exceptions_ex_binary_output,
254+
)
255+
self.assertNotIn('unexpected', uncaught_exceptions_ex_binary_output)
233256

234257

235258
if __name__ == '__main__':

googletest/test/googletest-color-test.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -69,59 +69,59 @@ def testNoEnvVarNoFlag(self):
6969
"""Tests the case when there's neither GTEST_COLOR nor --gtest_color."""
7070

7171
if not IS_WINDOWS:
72-
self.assert_(not UsesColor('dumb', None, None))
73-
self.assert_(not UsesColor('emacs', None, None))
74-
self.assert_(not UsesColor('xterm-mono', None, None))
75-
self.assert_(not UsesColor('unknown', None, None))
76-
self.assert_(not UsesColor(None, None, None))
77-
self.assert_(UsesColor('linux', None, None))
78-
self.assert_(UsesColor('cygwin', None, None))
79-
self.assert_(UsesColor('xterm', None, None))
80-
self.assert_(UsesColor('xterm-color', None, None))
81-
self.assert_(UsesColor('xterm-kitty', None, None))
82-
self.assert_(UsesColor('xterm-256color', None, None))
72+
self.assertTrue(not UsesColor('dumb', None, None))
73+
self.assertTrue(not UsesColor('emacs', None, None))
74+
self.assertTrue(not UsesColor('xterm-mono', None, None))
75+
self.assertTrue(not UsesColor('unknown', None, None))
76+
self.assertTrue(not UsesColor(None, None, None))
77+
self.assertTrue(UsesColor('linux', None, None))
78+
self.assertTrue(UsesColor('cygwin', None, None))
79+
self.assertTrue(UsesColor('xterm', None, None))
80+
self.assertTrue(UsesColor('xterm-color', None, None))
81+
self.assertTrue(UsesColor('xterm-kitty', None, None))
82+
self.assertTrue(UsesColor('xterm-256color', None, None))
8383

8484
def testFlagOnly(self):
8585
"""Tests the case when there's --gtest_color but not GTEST_COLOR."""
8686

87-
self.assert_(not UsesColor('dumb', None, 'no'))
88-
self.assert_(not UsesColor('xterm-color', None, 'no'))
87+
self.assertTrue(not UsesColor('dumb', None, 'no'))
88+
self.assertTrue(not UsesColor('xterm-color', None, 'no'))
8989
if not IS_WINDOWS:
90-
self.assert_(not UsesColor('emacs', None, 'auto'))
91-
self.assert_(UsesColor('xterm', None, 'auto'))
92-
self.assert_(UsesColor('dumb', None, 'yes'))
93-
self.assert_(UsesColor('xterm', None, 'yes'))
90+
self.assertTrue(not UsesColor('emacs', None, 'auto'))
91+
self.assertTrue(UsesColor('xterm', None, 'auto'))
92+
self.assertTrue(UsesColor('dumb', None, 'yes'))
93+
self.assertTrue(UsesColor('xterm', None, 'yes'))
9494

9595
def testEnvVarOnly(self):
9696
"""Tests the case when there's GTEST_COLOR but not --gtest_color."""
9797

98-
self.assert_(not UsesColor('dumb', 'no', None))
99-
self.assert_(not UsesColor('xterm-color', 'no', None))
98+
self.assertTrue(not UsesColor('dumb', 'no', None))
99+
self.assertTrue(not UsesColor('xterm-color', 'no', None))
100100
if not IS_WINDOWS:
101-
self.assert_(not UsesColor('dumb', 'auto', None))
102-
self.assert_(UsesColor('xterm-color', 'auto', None))
103-
self.assert_(UsesColor('dumb', 'yes', None))
104-
self.assert_(UsesColor('xterm-color', 'yes', None))
101+
self.assertTrue(not UsesColor('dumb', 'auto', None))
102+
self.assertTrue(UsesColor('xterm-color', 'auto', None))
103+
self.assertTrue(UsesColor('dumb', 'yes', None))
104+
self.assertTrue(UsesColor('xterm-color', 'yes', None))
105105

106106
def testEnvVarAndFlag(self):
107107
"""Tests the case when there are both GTEST_COLOR and --gtest_color."""
108108

109-
self.assert_(not UsesColor('xterm-color', 'no', 'no'))
110-
self.assert_(UsesColor('dumb', 'no', 'yes'))
111-
self.assert_(UsesColor('xterm-color', 'no', 'auto'))
109+
self.assertTrue(not UsesColor('xterm-color', 'no', 'no'))
110+
self.assertTrue(UsesColor('dumb', 'no', 'yes'))
111+
self.assertTrue(UsesColor('xterm-color', 'no', 'auto'))
112112

113113
def testAliasesOfYesAndNo(self):
114114
"""Tests using aliases in specifying --gtest_color."""
115115

116-
self.assert_(UsesColor('dumb', None, 'true'))
117-
self.assert_(UsesColor('dumb', None, 'YES'))
118-
self.assert_(UsesColor('dumb', None, 'T'))
119-
self.assert_(UsesColor('dumb', None, '1'))
116+
self.assertTrue(UsesColor('dumb', None, 'true'))
117+
self.assertTrue(UsesColor('dumb', None, 'YES'))
118+
self.assertTrue(UsesColor('dumb', None, 'T'))
119+
self.assertTrue(UsesColor('dumb', None, '1'))
120120

121-
self.assert_(not UsesColor('xterm', None, 'f'))
122-
self.assert_(not UsesColor('xterm', None, 'false'))
123-
self.assert_(not UsesColor('xterm', None, '0'))
124-
self.assert_(not UsesColor('xterm', None, 'unknown'))
121+
self.assertTrue(not UsesColor('xterm', None, 'f'))
122+
self.assertTrue(not UsesColor('xterm', None, 'false'))
123+
self.assertTrue(not UsesColor('xterm', None, '0'))
124+
self.assertTrue(not UsesColor('xterm', None, 'unknown'))
125125

126126

127127
if __name__ == '__main__':

googletest/test/googletest-filter-unittest.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,10 @@ def AssertSetEqual(self, lhs, rhs):
250250
"""Asserts that two sets are equal."""
251251

252252
for elem in lhs:
253-
self.assert_(elem in rhs, '%s in %s' % (elem, rhs))
253+
self.assertTrue(elem in rhs, '%s in %s' % (elem, rhs))
254254

255255
for elem in rhs:
256-
self.assert_(elem in lhs, '%s in %s' % (elem, lhs))
256+
self.assertTrue(elem in lhs, '%s in %s' % (elem, lhs))
257257

258258
def AssertPartitionIsValid(self, set_var, list_of_sets):
259259
"""Asserts that list_of_sets is a valid partition of set_var."""
@@ -595,21 +595,21 @@ def testShardStatusFileIsCreated(self):
595595

596596
shard_status_file = os.path.join(gtest_test_utils.GetTempDir(),
597597
'shard_status_file')
598-
self.assert_(not os.path.exists(shard_status_file))
598+
self.assertTrue(not os.path.exists(shard_status_file))
599599

600600
extra_env = {SHARD_STATUS_FILE_ENV_VAR: shard_status_file}
601601
try:
602602
InvokeWithModifiedEnv(extra_env, RunAndReturnOutput)
603603
finally:
604-
self.assert_(os.path.exists(shard_status_file))
604+
self.assertTrue(os.path.exists(shard_status_file))
605605
os.remove(shard_status_file)
606606

607607
def testShardStatusFileIsCreatedWithListTests(self):
608608
"""Tests that the shard file is created with the "list_tests" flag."""
609609

610610
shard_status_file = os.path.join(gtest_test_utils.GetTempDir(),
611611
'shard_status_file2')
612-
self.assert_(not os.path.exists(shard_status_file))
612+
self.assertTrue(not os.path.exists(shard_status_file))
613613

614614
extra_env = {SHARD_STATUS_FILE_ENV_VAR: shard_status_file}
615615
try:
@@ -619,12 +619,16 @@ def testShardStatusFileIsCreatedWithListTests(self):
619619
finally:
620620
# This assertion ensures that Google Test enumerated the tests as
621621
# opposed to running them.
622-
self.assert_('[==========]' not in output,
623-
'Unexpected output during test enumeration.\n'
624-
'Please ensure that LIST_TESTS_FLAG is assigned the\n'
625-
'correct flag value for listing Google Test tests.')
626-
627-
self.assert_(os.path.exists(shard_status_file))
622+
self.assertTrue(
623+
'[==========]' not in output,
624+
(
625+
'Unexpected output during test enumeration.\n'
626+
'Please ensure that LIST_TESTS_FLAG is assigned the\n'
627+
'correct flag value for listing Google Test tests.'
628+
),
629+
)
630+
631+
self.assertTrue(os.path.exists(shard_status_file))
628632
os.remove(shard_status_file)
629633

630634
def testDisabledBanner(self):

googletest/test/googletest-json-outfiles-test.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,17 @@ def _TestOutFile(self, test_name, expected):
171171
command = [gtest_prog_path, '--gtest_output=json:%s' % self.output_dir_]
172172
p = gtest_test_utils.Subprocess(command,
173173
working_dir=gtest_test_utils.GetTempDir())
174-
self.assert_(p.exited)
175-
self.assertEquals(0, p.exit_code)
174+
self.assertTrue(p.exited)
175+
self.assertEqual(0, p.exit_code)
176176

177177
output_file_name1 = test_name + '.json'
178178
output_file1 = os.path.join(self.output_dir_, output_file_name1)
179179
output_file_name2 = 'lt-' + output_file_name1
180180
output_file2 = os.path.join(self.output_dir_, output_file_name2)
181-
self.assert_(os.path.isfile(output_file1) or os.path.isfile(output_file2),
182-
output_file1)
181+
self.assertTrue(
182+
os.path.isfile(output_file1) or os.path.isfile(output_file2),
183+
output_file1,
184+
)
183185

184186
if os.path.isfile(output_file1):
185187
with open(output_file1) as f:

googletest/test/googletest-json-output-unittest.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -806,9 +806,9 @@ def testDefaultOutputFile(self):
806806
p = gtest_test_utils.Subprocess(
807807
[gtest_prog_path, '%s=json' % GTEST_OUTPUT_FLAG],
808808
working_dir=gtest_test_utils.GetTempDir())
809-
self.assert_(p.exited)
810-
self.assertEquals(0, p.exit_code)
811-
self.assert_(os.path.isfile(output_file))
809+
self.assertTrue(p.exited)
810+
self.assertEqual(0, p.exit_code)
811+
self.assertTrue(os.path.isfile(output_file))
812812

813813
def testSuppressedJsonOutput(self):
814814
"""Verifies that no JSON output is generated.
@@ -832,13 +832,15 @@ def testSuppressedJsonOutput(self):
832832
p.terminated_by_signal,
833833
'%s was killed by signal %d' % (GTEST_PROGRAM_NAME, p.signal))
834834
else:
835-
self.assert_(p.exited)
836-
self.assertEquals(1, p.exit_code,
837-
"'%s' exited with code %s, which doesn't match "
838-
'the expected exit code %s.'
839-
% (command, p.exit_code, 1))
835+
self.assertTrue(p.exited)
836+
self.assertEqual(
837+
1,
838+
p.exit_code,
839+
"'%s' exited with code %s, which doesn't match "
840+
'the expected exit code %s.' % (command, p.exit_code, 1),
841+
)
840842

841-
self.assert_(not os.path.isfile(json_path))
843+
self.assertTrue(not os.path.isfile(json_path))
842844

843845
def testFilteredTestJsonOutput(self):
844846
"""Verifies JSON output when a filter is applied.
@@ -870,14 +872,18 @@ def _GetJsonOutput(self, gtest_prog_name, extra_args, expected_exit_code):
870872
)
871873
p = gtest_test_utils.Subprocess(command)
872874
if p.terminated_by_signal:
873-
self.assert_(False,
874-
'%s was killed by signal %d' % (gtest_prog_name, p.signal))
875+
self.assertTrue(
876+
False, '%s was killed by signal %d' % (gtest_prog_name, p.signal)
877+
)
875878
else:
876-
self.assert_(p.exited)
877-
self.assertEquals(expected_exit_code, p.exit_code,
878-
"'%s' exited with code %s, which doesn't match "
879-
'the expected exit code %s.'
880-
% (command, p.exit_code, expected_exit_code))
879+
self.assertTrue(p.exited)
880+
self.assertEqual(
881+
expected_exit_code,
882+
p.exit_code,
883+
"'%s' exited with code %s, which doesn't match "
884+
'the expected exit code %s.'
885+
% (command, p.exit_code, expected_exit_code),
886+
)
881887
with open(json_path) as f:
882888
actual = json.load(f)
883889
return actual

0 commit comments

Comments
 (0)