mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-27 18:51:41 +02:00
More test fixes
This commit is contained in:
@@ -12,7 +12,6 @@ from contextlib import suppress
|
|||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
|
|
||||||
from kittens.ssh.utils import get_connection_data
|
from kittens.ssh.utils import get_connection_data
|
||||||
from kittens.transfer.utils import set_paths
|
|
||||||
from kitty.constants import is_macos, kitten_exe, runtime_dir
|
from kitty.constants import is_macos, kitten_exe, runtime_dir
|
||||||
from kitty.fast_data_types import CURSOR_BEAM, shm_unlink
|
from kitty.fast_data_types import CURSOR_BEAM, shm_unlink
|
||||||
from kitty.utils import SSHConnectionData
|
from kitty.utils import SSHConnectionData
|
||||||
@@ -71,7 +70,7 @@ print(' '.join(map(str, buf)))'''), lines=13, cols=77)
|
|||||||
f.write(simple_data)
|
f.write(simple_data)
|
||||||
|
|
||||||
for sh in self.all_possible_sh:
|
for sh in self.all_possible_sh:
|
||||||
with self.subTest(sh=sh), tempfile.TemporaryDirectory() as remote_home, tempfile.TemporaryDirectory() as local_home, set_paths(home=local_home):
|
with self.subTest(sh=sh), tempfile.TemporaryDirectory() as remote_home, tempfile.TemporaryDirectory() as local_home:
|
||||||
tuple(map(touch, 'simple-file g.1 g.2'.split()))
|
tuple(map(touch, 'simple-file g.1 g.2'.split()))
|
||||||
os.makedirs(f'{local_home}/d1/d2/d3')
|
os.makedirs(f'{local_home}/d1/d2/d3')
|
||||||
touch('d1/d2/x')
|
touch('d1/d2/x')
|
||||||
@@ -83,13 +82,13 @@ print(' '.join(map(str, buf)))'''), lines=13, cols=77)
|
|||||||
conf = '''\
|
conf = '''\
|
||||||
copy simple-file
|
copy simple-file
|
||||||
copy s1
|
copy s1
|
||||||
copy --symlink-strategy=keep-name s2
|
copy --symlink-strategy=keep-path s2
|
||||||
copy --dest=a/sfa simple-file
|
copy --dest=a/sfa simple-file
|
||||||
copy --glob g.*
|
copy --glob g.*
|
||||||
copy --exclude */w.* d1
|
copy --exclude */w.* d1
|
||||||
'''
|
'''
|
||||||
self.check_bootstrap(
|
self.check_bootstrap(
|
||||||
sh, remote_home, test_script='env; exit 0', SHELL_INTEGRATION_VALUE='', conf=conf
|
sh, remote_home, test_script='env; exit 0', SHELL_INTEGRATION_VALUE='', conf=conf, home=local_home,
|
||||||
)
|
)
|
||||||
tname = '.terminfo'
|
tname = '.terminfo'
|
||||||
if os.path.exists('/usr/share/misc/terminfo.cdb'):
|
if os.path.exists('/usr/share/misc/terminfo.cdb'):
|
||||||
@@ -212,7 +211,7 @@ env COLORTERM
|
|||||||
self.assertEqual(pty.screen.cursor.shape, 0)
|
self.assertEqual(pty.screen.cursor.shape, 0)
|
||||||
self.assertNotIn(b'\x1b]133;', pty.received_bytes)
|
self.assertNotIn(b'\x1b]133;', pty.received_bytes)
|
||||||
|
|
||||||
def check_bootstrap(self, sh, home_dir, login_shell='', SHELL_INTEGRATION_VALUE='enabled', test_script='', pre_data='', conf='', launcher='sh'):
|
def check_bootstrap(self, sh, home_dir, login_shell='', SHELL_INTEGRATION_VALUE='enabled', test_script='', pre_data='', conf='', launcher='sh', home=''):
|
||||||
if login_shell:
|
if login_shell:
|
||||||
conf += f'\nlogin_shell {login_shell}'
|
conf += f'\nlogin_shell {login_shell}'
|
||||||
if 'python' in sh:
|
if 'python' in sh:
|
||||||
@@ -223,7 +222,10 @@ env COLORTERM
|
|||||||
test_script = f'echo "UNTAR_DONE"; {test_script}'
|
test_script = f'echo "UNTAR_DONE"; {test_script}'
|
||||||
conf += '\nshell_integration ' + SHELL_INTEGRATION_VALUE or 'disabled'
|
conf += '\nshell_integration ' + SHELL_INTEGRATION_VALUE or 'disabled'
|
||||||
conf += '\ninterpreter ' + sh
|
conf += '\ninterpreter ' + sh
|
||||||
cp = subprocess.run([kitten_exe(), '__pytest__', 'ssh', test_script], stdout=subprocess.PIPE, input=conf.encode('utf-8'))
|
env = os.environ.copy()
|
||||||
|
if home:
|
||||||
|
env['HOME'] = home
|
||||||
|
cp = subprocess.run([kitten_exe(), '__pytest__', 'ssh', test_script], env=env, stdout=subprocess.PIPE, input=conf.encode('utf-8'))
|
||||||
self.assertEqual(cp.returncode, 0)
|
self.assertEqual(cp.returncode, 0)
|
||||||
self.rdata = json.loads(cp.stdout)
|
self.rdata = json.loads(cp.stdout)
|
||||||
del cp
|
del cp
|
||||||
|
|||||||
@@ -371,7 +371,7 @@ func (self *ConfigSet) line_handler(key, val string) error {
|
|||||||
return c.Parse(key, val)
|
return c.Parse(key, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
func load_config(hostname_to_match string, username_to_match string, overrides []string, paths ...string) (*Config, error) {
|
func load_config(hostname_to_match string, username_to_match string, overrides []string, paths ...string) (*Config, []config.ConfigLine, error) {
|
||||||
ans := &ConfigSet{all_configs: []*Config{NewConfig()}}
|
ans := &ConfigSet{all_configs: []*Config{NewConfig()}}
|
||||||
p := config.ConfigParser{LineHandler: ans.line_handler}
|
p := config.ConfigParser{LineHandler: ans.line_handler}
|
||||||
if len(paths) == 0 {
|
if len(paths) == 0 {
|
||||||
@@ -380,13 +380,13 @@ func load_config(hostname_to_match string, username_to_match string, overrides [
|
|||||||
paths = utils.Filter(paths, func(x string) bool { return x != "" })
|
paths = utils.Filter(paths, func(x string) bool { return x != "" })
|
||||||
err := p.ParseFiles(paths...)
|
err := p.ParseFiles(paths...)
|
||||||
if err != nil && !errors.Is(err, fs.ErrNotExist) {
|
if err != nil && !errors.Is(err, fs.ErrNotExist) {
|
||||||
return nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
if len(overrides) > 0 {
|
if len(overrides) > 0 {
|
||||||
err = p.ParseOverrides(overrides...)
|
err = p.ParseOverrides(overrides...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return config_for_hostname(hostname_to_match, username_to_match, ans), nil
|
return config_for_hostname(hostname_to_match, username_to_match, ans), p.BadLines(), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -532,10 +532,15 @@ func run_ssh(ssh_args, server_args, found_extra_args []string) (rc int, err erro
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 1, err
|
return 1, err
|
||||||
}
|
}
|
||||||
host_opts, err := load_config(hostname_for_match, uname, overrides)
|
host_opts, bad_lines, err := load_config(hostname_for_match, uname, overrides)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 1, err
|
return 1, err
|
||||||
}
|
}
|
||||||
|
if len(bad_lines) > 0 {
|
||||||
|
for _, x := range bad_lines {
|
||||||
|
fmt.Fprintf(os.Stderr, "Ignoring bad config line: %s:%d with error: %s", filepath.Base(x.Src_file), x.Line_number, x.Err)
|
||||||
|
}
|
||||||
|
}
|
||||||
if host_opts.Share_connections {
|
if host_opts.Share_connections {
|
||||||
kpid, err := strconv.Atoi(os.Getenv("KITTY_PID"))
|
kpid, err := strconv.Atoi(os.Getenv("KITTY_PID"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -646,8 +651,11 @@ func test_integration_with_python(args []string) (rc int, err error) {
|
|||||||
username: "testuser", hostname_for_match: "host.test", request_data: true,
|
username: "testuser", hostname_for_match: "host.test", request_data: true,
|
||||||
test_script: args[0], echo_on: true,
|
test_script: args[0], echo_on: true,
|
||||||
}
|
}
|
||||||
opts, err := load_config(cd.hostname_for_match, cd.username, nil, f.Name())
|
opts, bad_lines, err := load_config(cd.hostname_for_match, cd.username, nil, f.Name())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
if len(bad_lines) > 0 {
|
||||||
|
return 1, fmt.Errorf("Bad config lines: %s with error: %s", bad_lines[0].Line, bad_lines[0].Err)
|
||||||
|
}
|
||||||
cd.host_opts = opts
|
cd.host_opts = opts
|
||||||
err = get_remote_command(cd)
|
err = get_remote_command(cd)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user