Skip to content

Commit d404af0

Browse files
committed
add python 3 support to tests
1 parent 13206d6 commit d404af0

File tree

8 files changed

+18
-14
lines changed

8 files changed

+18
-14
lines changed

googletest/test/gtest_env_var_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747

4848
def AssertEq(expected, actual):
4949
if expected != actual:
50-
print 'Expected: %s' % (expected,)
51-
print ' Actual: %s' % (actual,)
50+
print('Expected: %s' % (expected,))
51+
print(' Actual: %s' % (actual,))
5252
raise AssertionError
5353

5454

googletest/test/gtest_filter_unittest.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@
4444

4545
import os
4646
import re
47-
import sets
47+
try:
48+
from sets import Set as set # For Python 2.3 compatibility
49+
except ImportError:
50+
pass
4851
import sys
4952

5053
import gtest_test_utils
@@ -58,7 +61,7 @@
5861
# exception is thrown if the input is anything other than 'True' nor 'False'.
5962
os.environ['EMPTY_VAR'] = ''
6063
child = gtest_test_utils.Subprocess(
61-
[sys.executable, '-c', 'import os; print \'EMPTY_VAR\' in os.environ'])
64+
[sys.executable, '-c', 'import os; print(\'EMPTY_VAR\' in os.environ)'])
6265
CAN_PASS_EMPTY_ENV = eval(child.output)
6366

6467

@@ -71,7 +74,7 @@
7174
os.environ['UNSET_VAR'] = 'X'
7275
del os.environ['UNSET_VAR']
7376
child = gtest_test_utils.Subprocess(
74-
[sys.executable, '-c', 'import os; print \'UNSET_VAR\' not in os.environ'])
77+
[sys.executable, '-c', 'import os; print(\'UNSET_VAR\' not in os.environ)'])
7578
CAN_UNSET_ENV = eval(child.output)
7679

7780

@@ -243,14 +246,14 @@ def AssertPartitionIsValid(self, set_var, list_of_sets):
243246
for slice_var in list_of_sets:
244247
full_partition.extend(slice_var)
245248
self.assertEqual(len(set_var), len(full_partition))
246-
self.assertEqual(sets.Set(set_var), sets.Set(full_partition))
249+
self.assertEqual(set(set_var), set(full_partition))
247250

248251
def AdjustForParameterizedTests(self, tests_to_run):
249252
"""Adjust tests_to_run in case value parameterized tests are disabled."""
250253

251254
global param_tests_present
252255
if not param_tests_present:
253-
return list(sets.Set(tests_to_run) - sets.Set(PARAM_TESTS))
256+
return list(set(tests_to_run) - set(PARAM_TESTS))
254257
else:
255258
return tests_to_run
256259

googletest/test/gtest_output_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def RemoveUnsupportedTests(self, test_output):
279279
def testOutput(self):
280280
output = GetOutputOfAllCommands()
281281

282-
golden_file = open(GOLDEN_PATH, 'rb')
282+
golden_file = open(GOLDEN_PATH, 'r')
283283
# A mis-configured source control system can cause \r appear in EOL
284284
# sequences when we read the golden file irrespective of an operating
285285
# system used. Therefore, we need to strip those \r's from newlines

googletest/test/gtest_test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def GetTestExecutablePath(executable_name, build_dir=None):
178178
'Unable to find the test binary "%s". Please make sure to provide\n'
179179
'a path to the binary via the --build_dir flag or the BUILD_DIR\n'
180180
'environment variable.' % path)
181-
print >> sys.stderr, message
181+
sys.stdout.write(message)
182182
sys.exit(1)
183183

184184
return path

googletest/test/gtest_throw_on_failure_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def SetEnvVar(env_var, value):
7070
def Run(command):
7171
"""Runs a command; returns True/False if its exit code is/isn't 0."""
7272

73-
print 'Running "%s". . .' % ' '.join(command)
73+
print('Running "%s". . .' % ' '.join(command))
7474
p = gtest_test_utils.Subprocess(command)
7575
return p.exited and p.exit_code == 0
7676

googletest/test/gtest_uninitialized_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def Assert(condition):
4646

4747
def AssertEq(expected, actual):
4848
if expected != actual:
49-
print 'Expected: %s' % (expected,)
50-
print ' Actual: %s' % (actual,)
49+
print('Expected: %s' % (expected,))
50+
print(' Actual: %s' % (actual,))
5151
raise AssertionError
5252

5353

googletest/test/gtest_xml_output_unittest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ def testDefaultOutputFile(self):
209209
'gtest_no_test_unittest')
210210
try:
211211
os.remove(output_file)
212-
except OSError, e:
212+
except OSError:
213+
e = sys.exc_info()[1]
213214
if e.errno != errno.ENOENT:
214215
raise
215216

googletest/test/gtest_xml_test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def AssertEquivalentNodes(self, expected_node, actual_node):
101101
self.assertEquals(
102102
len(expected_children), len(actual_children),
103103
'number of child elements differ in element ' + actual_node.tagName)
104-
for child_id, child in expected_children.iteritems():
104+
for child_id, child in expected_children.items():
105105
self.assert_(child_id in actual_children,
106106
'<%s> is not in <%s> (in element %s)' %
107107
(child_id, actual_children, actual_node.tagName))

0 commit comments

Comments
 (0)