Skip to content

Commit 9a90708

Browse files
committed
tests: migrate to Python3 for the tests
Adjust the test suite to be compatible with Python 3 and require python 3 for running the tests as python 2 has been EOL'ed.
1 parent 02aa0cf commit 9a90708

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ if(ENABLE_TESTING)
8585
find_program(LIT_COMMAND NAMES llvm-lit lit.py lit)
8686
endif()
8787

88-
find_package(Python2 COMPONENTS Interpreter REQUIRED)
88+
find_package(Python3 COMPONENTS Interpreter REQUIRED)
8989

9090
add_custom_target(check-xctest
9191
COMMAND
@@ -96,7 +96,7 @@ if(ENABLE_TESTING)
9696
LIBDISPATCH_BUILD_DIR=${XCTEST_PATH_TO_LIBDISPATCH_BUILD}
9797
LIBDISPATCH_OVERLAY_DIR=${XCTEST_PATH_TO_LIBDISPATCH_BUILD}/src/swift
9898
SWIFT_EXEC=${CMAKE_Swift_COMPILER}
99-
$<TARGET_FILE:Python2::Interpreter> ${LIT_COMMAND} -sv ${CMAKE_SOURCE_DIR}/Tests/Functional
99+
$<TARGET_FILE:Python3::Interpreter> ${LIT_COMMAND} -sv ${CMAKE_SOURCE_DIR}/Tests/Functional
100100
COMMENT
101101
"Running XCTest functional test suite"
102102
DEPENDS

Tests/Functional/xctest_checker/tests/test_compare.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ def test_too_few_expected_raises_and_first_line_in_error(self):
3636
with self.assertRaises(XCTestCheckerError) as cm:
3737
compare.compare(open(actual, 'r'), expected, check_prefix='c: ')
3838

39-
self.assertIn('{}:{}'.format(expected, 1), cm.exception.message)
39+
self.assertIn('{}:{}'.format(expected, 1), str(cm.exception))
4040

4141
def test_too_many_expected_raises_and_excess_check_line_in_error(self):
4242
actual = _tmpfile('foo\nbar\n')
4343
expected = _tmpfile('c: foo\nc: bar\nc: baz\n')
4444
with self.assertRaises(XCTestCheckerError) as cm:
4545
compare.compare(open(actual, 'r'), expected, check_prefix='c: ')
4646

47-
self.assertIn('{}:{}'.format(expected, 3), cm.exception.message)
47+
self.assertIn('{}:{}'.format(expected, 3), str(cm.exception))
4848

4949
def test_match_does_not_raise(self):
5050
actual = _tmpfile('foo\nbar\nbaz\n')
@@ -62,7 +62,7 @@ def test_check_prefix_twice_in_the_same_line_raises_with_line(self):
6262
with self.assertRaises(XCTestCheckerError) as cm:
6363
compare.compare(open(actual, 'r'), expected, check_prefix='c: ')
6464

65-
self.assertIn('{}:{}'.format(expected, 2), cm.exception.message)
65+
self.assertIn('{}:{}'.format(expected, 2), str(cm.exception))
6666

6767
def test_check_prefix_in_run_line_ignored(self):
6868
actual = _tmpfile('flim\n')
@@ -75,7 +75,7 @@ def test_includes_file_name_and_line_of_expected_in_error(self):
7575
with self.assertRaises(XCTestCheckerError) as cm:
7676
compare.compare(open(actual, 'r'), expected, check_prefix='c: ')
7777

78-
self.assertIn("{}:{}:".format(expected, 2), cm.exception.message)
78+
self.assertIn("{}:{}:".format(expected, 2), str(cm.exception))
7979

8080
def test_matching_ignores_leading_and_trailing_whitespace(self):
8181
actual = _tmpfile('foo\nbar\nbaz\n')

Tests/Functional/xctest_checker/xctest_checker/compare.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010

1111
import re
12+
try:
13+
from itertools import zip_longest
14+
except ImportError:
15+
from itertools import izip_longest as zip_longest
1216

1317
from .error import XCTestCheckerError
1418
from .line import replace_offsets
@@ -63,8 +67,7 @@ def compare(actual, expected, check_prefix):
6367
file, raises an AssertionError. Also raises an AssertionError if the number
6468
of lines in the two files differ.
6569
"""
66-
for actual_line, expected_line_and_number in map(
67-
None,
70+
for actual_line, expected_line_and_number in zip_longest(
6871
_actual_lines(actual),
6972
_expected_lines_and_line_numbers(expected, check_prefix)):
7073

0 commit comments

Comments
 (0)