--- test/test.py | 20 +++++++++++--------- test/test_contrib_shells.py | 13 ++++++------- 2 files changed, 17 insertions(+), 16 deletions(-) --- a/test/test.py +++ b/test/test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/python3.10 import argparse import contextlib import os @@ -19,6 +19,8 @@ TEST_DIR = os.path.abspath(os.path.dirna BASE_DIR = os.path.dirname(TEST_DIR) sys.path.insert(0, BASE_DIR) +py_ver = "%s.%s" % sys.version_info[:2] + from argparse import SUPPRESS, ArgumentParser # noqa: E402 import argcomplete # noqa: E402 @@ -1254,7 +1256,7 @@ class TestBashZshBase(TestShellBase): init_cmd = None # 'dummy' argument unused; checks multi-command registration works # by passing 'prog' as the second argument. - install_cmd = 'eval "$(register-python-argcomplete dummy prog)"' + install_cmd = 'eval "$(register-python-argcomplete-{} dummy prog)"'.format(py_ver) def setUp(self): sh = self.repl_provider() @@ -1271,7 +1273,7 @@ class TestBashZshBase(TestShellBase): self.assertEqual(output, "") # Register a dummy completion with an external argcomplete script # to ensure this doesn't overwrite our previous registration. - output = sh.run_command('eval "$(register-python-argcomplete dummy --external-argcomplete-script dummy)"') + output = sh.run_command('eval "$(register-python-argcomplete dummy-{} --external-argcomplete-script dummy)"'.format(py_ver)) self.assertEqual(output, "") self.sh = sh @@ -1330,7 +1332,7 @@ class TestZsh(TestBashZshBase, unittest. class TestBashZshGlobalBase(TestBashZshBase): - install_cmd = 'eval "$(activate-global-python-argcomplete --dest=-)"' + install_cmd = 'eval "$(activate-global-python-argcomplete-{} --dest=-)"'.format(py_ver) def test_redirection_completion(self): with TempDir(prefix="test_dir_py", dir="."): @@ -1343,15 +1345,15 @@ class TestBashZshGlobalBase(TestBashZshB def test_python_completion(self): self.sh.run_command("cd " + TEST_DIR) - self.assertEqual(self.sh.run_command("python3 ./prog basic f\t"), "foo\r\n") + self.assertEqual(self.sh.run_command("python{} ./prog basic f\t".format(py_ver)), "foo\r\n") def test_python_filename_completion(self): self.sh.run_command("cd " + TEST_DIR) - self.assertEqual(self.sh.run_command("python3 ./pro\tbasic f\t"), "foo\r\n") + self.assertEqual(self.sh.run_command("python{} ./pro\tbasic f\t".format(py_ver)), "foo\r\n") def test_python_stuck(self): self.sh.run_command("cd " + TEST_DIR) - self.sh.run_command("python3 ./stuck no\t-input") + self.sh.run_command("python{} ./stuck no\t-input".format(py_ver)) def test_python_not_executable(self): """Test completing a script that cannot be run directly.""" @@ -1363,7 +1365,7 @@ class TestBashZshGlobalBase(TestBashZshB # Ensure prog is no longer able to be run as "./prog". self.assertIn("<<126>>", self.sh.run_command('./prog; echo "<<$?>>"')) # Ensure completion still functions when run via python. - self.assertEqual(self.sh.run_command("python3 ./prog basic f\t"), "foo\r\n") + self.assertEqual(self.sh.run_command("python{} ./prog basic f\t".format(py_ver)), "foo\r\n") def test_python_module(self): """Test completing a module run with python -m.""" @@ -1373,7 +1375,7 @@ class TestBashZshGlobalBase(TestBashZshB open("package/__init__.py", "w").close() shutil.copy(prog, "package/prog.py") self.sh.run_command("cd " + os.getcwd()) - self.assertEqual(self.sh.run_command("python3 -m package.prog basic f\t"), "foo\r\n") + self.assertEqual(self.sh.run_command("python{} -m package.prog basic f\t".format(py_ver)), "foo\r\n") def _test_console_script(self, package=False, wheel=False): with TempDir(prefix="test_dir_py", dir="."): --- a/test/test_contrib_shells.py +++ b/test/test_contrib_shells.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/python3.10 import os import os.path import unittest @@ -6,8 +6,7 @@ import unittest import pexpect import pexpect.replwrap -from .test import BASE_DIR, TEST_DIR, Shell, TestShellBase - +from .test import BASE_DIR, TEST_DIR, Shell, TestShellBase, py_ver @unittest.skip("tcsh is not supported. Enable this test manually if needed.") class TestTcsh(TestShellBase, unittest.TestCase): @@ -28,12 +27,12 @@ class TestTcsh(TestShellBase, unittest.T sh.run_command("setenv PYTHONPATH {0}".format(BASE_DIR)) # 'dummy' argument unused; checks multi-command registration works # by passing 'prog' as the second argument. - output = sh.run_command("eval `register-python-argcomplete --shell tcsh dummy prog`") + output = sh.run_command("eval `register-python-argcomplete-{} --shell tcsh dummy prog`".format(py_ver)) self.assertEqual(output, "") # Register a dummy completion with an external argcomplete script # to ensure this doesn't overwrite our previous registration. output = sh.run_command( - "eval `register-python-argcomplete --shell tcsh dummy --external-argcomplete-script dummy`" + "eval `register-python-argcomplete-{} --shell tcsh dummy --external-argcomplete-script dummy`.format(py_ver)" ) self.assertEqual(output, "") self.sh = sh @@ -62,12 +61,12 @@ class TestFish(TestShellBase, unittest.T sh.run_command("set -x PYTHONPATH {0}".format(BASE_DIR)) # 'dummy' argument unused; checks multi-command registration works # by passing 'prog' as the second argument. - output = sh.run_command("register-python-argcomplete --shell fish dummy prog | source") + output = sh.run_command("register-python-argcomplete-{} --shell fish dummy prog | source".format(py_ver)) self.assertEqual(output, "") # Register a dummy completion with an external argcomplete script # to ensure this doesn't overwrite our previous registration. output = sh.run_command( - "register-python-argcomplete --shell fish dummy --external-argcomplete-script dummy | source" + "register-python-argcomplete-{} --shell fish dummy --external-argcomplete-script dummy | source".format(py_ver) ) self.assertEqual(output, "") self.sh = sh