Split up ssh tests

This commit is contained in:
Kovid Goyal
2022-02-27 14:55:49 +05:30
parent ae6665493a
commit e06bd68379
2 changed files with 23 additions and 19 deletions

View File

@@ -5,10 +5,8 @@ import importlib
import os import os
import sys import sys
import unittest import unittest
from typing import Callable, Generator, NoReturn, Sequence, Set
from importlib.resources import contents from importlib.resources import contents
from typing import Callable, Generator, NoReturn, Sequence, Set
def itertests(suite: unittest.TestSuite) -> Generator[unittest.TestCase, None, None]: def itertests(suite: unittest.TestSuite) -> Generator[unittest.TestCase, None, None]:
@@ -88,10 +86,15 @@ def run_tests() -> None:
'name', nargs='*', default=[], 'name', nargs='*', default=[],
help='The name of the test to run, for e.g. linebuf corresponds to test_linebuf. Can be specified multiple times') help='The name of the test to run, for e.g. linebuf corresponds to test_linebuf. Can be specified multiple times')
parser.add_argument('--verbosity', default=4, type=int, help='Test verbosity') parser.add_argument('--verbosity', default=4, type=int, help='Test verbosity')
parser.add_argument('--module', default='', help='Name of a test module to restrict to. For example: ssh')
args = parser.parse_args() args = parser.parse_args()
if args.name and args.name[0] in ('type-check', 'type_check', 'mypy'): if args.name and args.name[0] in ('type-check', 'type_check', 'mypy'):
type_check() type_check()
tests = find_all_tests() tests = find_all_tests()
if args.module:
tests = filter_tests_by_module(tests, args.module)
if not tests._tests:
raise SystemExit('No test module named %s found' % args.module)
if args.name: if args.name:
tests = filter_tests_by_name(tests, *args.name) tests = filter_tests_by_name(tests, *args.name)
if not tests._tests: if not tests._tests:

View File

@@ -20,7 +20,7 @@ from . import BaseTest
from .shell_integration import bash_ok, basic_shell_env from .shell_integration import bash_ok, basic_shell_env
class SSHTest(BaseTest): class SSHKitten(BaseTest):
def test_basic_pty_operations(self): def test_basic_pty_operations(self):
pty = self.create_pty('echo hello') pty = self.create_pty('echo hello')
@@ -72,19 +72,20 @@ print(' '.join(map(str, buf)))'''), lines=13, cols=77)
def all_possible_sh(self): def all_possible_sh(self):
return tuple(sh for sh in ('dash', 'zsh', 'bash', 'posh', 'sh') if shutil.which(sh)) return tuple(sh for sh in ('dash', 'zsh', 'bash', 'posh', 'sh') if shutil.which(sh))
def test_ssh_bootstrap_script(self): def test_ssh_env_vars(self):
# test setting env vars for sh in self.all_possible_sh:
with tempfile.TemporaryDirectory() as tdir: with self.subTest(sh=sh), tempfile.TemporaryDirectory() as tdir:
pty = self.check_bootstrap( pty = self.check_bootstrap(
'dash', tdir, extra_exec='env; exit 0', SHELL_INTEGRATION_VALUE='', sh, tdir, extra_exec='env; exit 0', SHELL_INTEGRATION_VALUE='',
ssh_opts={'env': { ssh_opts={'env': {
'TSET': 'set-works', 'TSET': 'set-works',
'COLORTERM': DELETE_ENV_VAR, 'COLORTERM': DELETE_ENV_VAR,
}} }}
) )
pty.wait_till(lambda: 'TSET=set-works' in pty.screen_contents()) pty.wait_till(lambda: 'TSET=set-works' in pty.screen_contents())
self.assertNotIn('COLORTERM', pty.screen_contents()) self.assertNotIn('COLORTERM', pty.screen_contents())
# test handling of data in tty before tarfile is sent
def test_ssh_leading_data(self):
for sh in self.all_possible_sh: for sh in self.all_possible_sh:
with self.subTest(sh=sh), tempfile.TemporaryDirectory() as tdir: with self.subTest(sh=sh), tempfile.TemporaryDirectory() as tdir:
pty = self.check_bootstrap( pty = self.check_bootstrap(
@@ -92,7 +93,7 @@ print(' '.join(map(str, buf)))'''), lines=13, cols=77)
SHELL_INTEGRATION_VALUE='', pre_data='before_tarfile') SHELL_INTEGRATION_VALUE='', pre_data='before_tarfile')
self.ae(pty.screen_contents(), 'UNTAR_DONE\nld:before_tarfile') self.ae(pty.screen_contents(), 'UNTAR_DONE\nld:before_tarfile')
# test various detection methods for login_shell def test_ssh_login_shell_detection(self):
methods = [] methods = []
if shutil.which('python') or shutil.which('python3') or shutil.which('python2'): if shutil.which('python') or shutil.which('python3') or shutil.which('python2'):
methods.append('using_python') methods.append('using_python')
@@ -112,7 +113,7 @@ print(' '.join(map(str, buf)))'''), lines=13, cols=77)
pty = self.check_bootstrap(sh, tdir, extra_exec=f'{m}; echo "$login_shell"; exit 0', SHELL_INTEGRATION_VALUE='') pty = self.check_bootstrap(sh, tdir, extra_exec=f'{m}; echo "$login_shell"; exit 0', SHELL_INTEGRATION_VALUE='')
self.assertIn(expected_login_shell, pty.screen_contents()) self.assertIn(expected_login_shell, pty.screen_contents())
# check that shell integration works def test_ssh_shell_integration(self):
ok_login_shell = '' ok_login_shell = ''
for sh in self.all_possible_sh: for sh in self.all_possible_sh:
for login_shell in {'fish', 'zsh', 'bash'} & set(self.all_possible_sh): for login_shell in {'fish', 'zsh', 'bash'} & set(self.all_possible_sh):