Remove tests requiring Python 2 support.
This is in preparation for disabling Python 2 functionality. There is more code
and tests related to Python 2 support, but these are the ones that fail when
`--incompatible_python_disable_py2=true`.
This also revealed that rejecting Python 2 settings for `py_runtime` and
`py_runtime_pair` will have to wait until after the flag flip. This is because
the auto-detecting toolchains define some py2 toolchains, so in order to make
tests pass, those have to be removed, but doing so would break Python 2 support
prior to the flag flip. The other rules still reject them, though, which is
plenty sufficient.
Work towards #15684
PiperOrigin-RevId: 504086890
Change-Id: Ib39e3b32076072f5510418241cd0ca4765e6ab44
diff --git a/tools/python/pywrapper_test.py b/tools/python/pywrapper_test.py
index 07732a6..14fd0d7 100644
--- a/tools/python/pywrapper_test.py
+++ b/tools/python/pywrapper_test.py
@@ -25,25 +25,19 @@
class MockPythonLines(object):
- NORMAL = textwrap.dedent(r"""\
- if [ "$1" = "-V" ]; then
- echo "Mock Python 2.xyz!"
- else
- echo "I am mock Python!"
- fi
- """).split("\n")
-
- FAIL = textwrap.dedent(r"""\
- echo "Mock failure!"
- exit 1
- """).split("\n")
-
- WRONG_VERSION = textwrap.dedent(r"""\
+ NORMAL = textwrap.dedent(
+ r"""\
if [ "$1" = "-V" ]; then
echo "Mock Python 3.xyz!"
else
echo "I am mock Python!"
fi
+ """
+ ).split("\n")
+
+ FAIL = textwrap.dedent(r"""\
+ echo "Mock failure!"
+ exit 1
""").split("\n")
VERSION_ERROR = textwrap.dedent(r"""\
@@ -104,10 +98,12 @@
super(PywrapperTest, self).setUp()
# Locate scripts under test.
- self.wrapper_path = \
- self.locate_runfile("io_bazel/tools/python/py2wrapper.sh")
- self.nonstrict_wrapper_path = \
- self.locate_runfile("io_bazel/tools/python/py2wrapper_nonstrict.sh")
+ self.wrapper_path = self.locate_runfile(
+ "io_bazel/tools/python/py3wrapper.sh"
+ )
+ self.nonstrict_wrapper_path = self.locate_runfile(
+ "io_bazel/tools/python/py3wrapper_nonstrict.sh"
+ )
# Setup scratch directory with all executables the script depends on.
#
@@ -160,55 +156,33 @@
self.assertRegexpMatches(
err, message, msg="stderr did not contain expected string")
- def test_finds_python2(self):
- self.ScratchFile("dir/python2", MockPythonLines.NORMAL, executable=True)
- returncode, out, err = self.run_wrapper("test_finds_python2")
- self.assert_wrapper_success(returncode, out, err)
-
def test_finds_python(self):
self.ScratchFile("dir/python", MockPythonLines.NORMAL, executable=True)
returncode, out, err = self.run_wrapper("test_finds_python")
self.assert_wrapper_success(returncode, out, err)
- def test_prefers_python2(self):
- self.ScratchFile("dir/python2", MockPythonLines.NORMAL, executable=True)
- self.ScratchFile("dir/python", MockPythonLines.FAIL, executable=True)
- returncode, out, err = self.run_wrapper("test_prefers_python2")
- self.assert_wrapper_success(returncode, out, err)
-
def test_no_interpreter_found(self):
returncode, out, err = self.run_wrapper("test_no_interpreter_found")
- self.assert_wrapper_failure(returncode, out, err,
- "Neither 'python2' nor 'python' were found")
-
- def test_wrong_version(self):
- self.ScratchFile(
- "dir/python2", MockPythonLines.WRONG_VERSION, executable=True)
- returncode, out, err = self.run_wrapper("test_wrong_version")
self.assert_wrapper_failure(
- returncode, out, err,
- "version is 'Mock Python 3.xyz!', but we need version 2")
+ returncode, out, err, "Neither 'python3' nor 'python' were found"
+ )
def test_error_getting_version(self):
self.ScratchFile(
- "dir/python2", MockPythonLines.VERSION_ERROR, executable=True)
+ "dir/python", MockPythonLines.VERSION_ERROR, executable=True
+ )
returncode, out, err = self.run_wrapper("test_error_getting_version")
self.assert_wrapper_failure(returncode, out, err,
"Could not get interpreter version")
def test_interpreter_not_executable(self):
self.ScratchFile(
- "dir/python2", MockPythonLines.VERSION_ERROR, executable=False)
+ "dir/python", MockPythonLines.VERSION_ERROR, executable=False
+ )
returncode, out, err = self.run_wrapper("test_interpreter_not_executable")
- self.assert_wrapper_failure(returncode, out, err,
- "Neither 'python2' nor 'python' were found")
-
- def test_wrong_version_ok_for_nonstrict(self):
- self.ScratchFile(
- "dir/python2", MockPythonLines.WRONG_VERSION, executable=True)
- returncode, out, err = \
- self.run_nonstrict_wrapper("test_wrong_version_ok_for_nonstrict")
- self.assert_wrapper_success(returncode, out, err)
+ self.assert_wrapper_failure(
+ returncode, out, err, "Neither 'python3' nor 'python' were found"
+ )
if __name__ == "__main__":