Skip to content

tests: migrate to Python3 for the tests #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ if(ENABLE_TESTING)
find_program(LIT_COMMAND NAMES llvm-lit lit.py lit)
endif()

find_package(Python2 COMPONENTS Interpreter REQUIRED)
find_package(Python3 COMPONENTS Interpreter REQUIRED)

add_custom_target(check-xctest
COMMAND
Expand All @@ -96,7 +96,7 @@ if(ENABLE_TESTING)
LIBDISPATCH_BUILD_DIR=${XCTEST_PATH_TO_LIBDISPATCH_BUILD}
LIBDISPATCH_OVERLAY_DIR=${XCTEST_PATH_TO_LIBDISPATCH_BUILD}/src/swift
SWIFT_EXEC=${CMAKE_Swift_COMPILER}
$<TARGET_FILE:Python2::Interpreter> ${LIT_COMMAND} -sv ${CMAKE_SOURCE_DIR}/Tests/Functional
$<TARGET_FILE:Python3::Interpreter> ${LIT_COMMAND} -sv ${CMAKE_SOURCE_DIR}/Tests/Functional
COMMENT
"Running XCTest functional test suite"
DEPENDS
Expand Down
8 changes: 4 additions & 4 deletions Tests/Functional/xctest_checker/tests/test_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ def test_too_few_expected_raises_and_first_line_in_error(self):
with self.assertRaises(XCTestCheckerError) as cm:
compare.compare(open(actual, 'r'), expected, check_prefix='c: ')

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

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

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

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

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

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

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

def test_matching_ignores_leading_and_trailing_whitespace(self):
actual = _tmpfile('foo\nbar\nbaz\n')
Expand Down
7 changes: 5 additions & 2 deletions Tests/Functional/xctest_checker/xctest_checker/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

import re
try:
from itertools import zip_longest
except ImportError:
from itertools import izip_longest as zip_longest

from .error import XCTestCheckerError
from .line import replace_offsets
Expand Down Expand Up @@ -63,8 +67,7 @@ def compare(actual, expected, check_prefix):
file, raises an AssertionError. Also raises an AssertionError if the number
of lines in the two files differ.
"""
for actual_line, expected_line_and_number in map(
None,
for actual_line, expected_line_and_number in zip_longest(
_actual_lines(actual),
_expected_lines_and_line_numbers(expected, check_prefix)):

Expand Down