Skip to content

Commit f2149e1

Browse files
committed
Add tests for missing session and window
1 parent e9a1b8f commit f2149e1

File tree

1 file changed

+65
-10
lines changed

1 file changed

+65
-10
lines changed

tests/test_cli.py

+65-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import libtmux
1414
from libtmux.common import has_lt_version
1515
from libtmux.exc import LibTmuxException
16-
from tmuxp import cli, config
16+
from tmuxp import cli, config, exc
1717
from tmuxp.cli import (
1818
command_ls,
1919
get_config_dir,
@@ -515,37 +515,92 @@ def test_shell(
515515
assert expected_output.format(**template_ctx) in result.output
516516

517517

518+
@pytest.mark.parametrize("cli_cmd", ['shell', 'shell_plus'])
518519
@pytest.mark.parametrize(
519-
"cli_args,inputs,env,exception,message",
520+
"cli_args,inputs,env,template_ctx,exception,message",
520521
[
521522
(
522-
['shell', '-L{SOCKET_NAME}', '-c', 'print(str(server.socket_name))'],
523+
['-LDoesNotExist', '-c', 'print(str(server.socket_name))'],
523524
[],
524525
{},
526+
{},
525527
LibTmuxException,
526-
r'.*{SOCKET_NAME}\s\(No such file or directory\).*',
528+
r'.*DoesNotExist\s\(No such file or directory\).*',
529+
),
530+
(
531+
[
532+
'-L{SOCKET_NAME}',
533+
'nonexistant_session',
534+
'-c',
535+
'print(str(server.socket_name))',
536+
],
537+
[],
538+
{},
539+
{'session_name': 'nonexistant_session'},
540+
None,
541+
'Session not found: nonexistant_session',
542+
),
543+
(
544+
[
545+
'-L{SOCKET_NAME}',
546+
'{SESSION_NAME}',
547+
'nonexistant_window',
548+
'-c',
549+
'print(str(server.socket_name))',
550+
],
551+
[],
552+
{},
553+
{'window_name': 'nonexistant_window'},
554+
None,
555+
'Window not found: {WINDOW_NAME}',
527556
),
528557
],
529558
)
530-
def test_shell_no_server(
531-
cli_args, inputs, env, exception, message, tmpdir, monkeypatch, socket_name
559+
def test_shell_target_missing(
560+
cli_cmd,
561+
cli_args,
562+
inputs,
563+
env,
564+
template_ctx,
565+
exception,
566+
message,
567+
tmpdir,
568+
monkeypatch,
569+
socket_name,
570+
server,
571+
session,
532572
):
533573
monkeypatch.setenv('HOME', str(tmpdir))
574+
window_name = 'my_window'
575+
window = session.new_window(window_name=window_name)
576+
window.split_window()
577+
534578
template_ctx = dict(
535-
SOCKET_NAME=socket_name,
579+
SOCKET_NAME=server.socket_name,
580+
SOCKET_PATH=server.socket_path,
581+
SESSION_NAME=session.name,
582+
WINDOW_NAME=template_ctx.get('window_name', window_name),
583+
PANE_ID=template_ctx.get('pane_id'),
584+
SERVER_SOCKET_NAME=server.socket_name,
536585
)
586+
cli_args = [cli_cmd] + [cli_arg.format(**template_ctx) for cli_arg in cli_args]
537587

538-
cli_args[:] = [cli_arg.format(**template_ctx) for cli_arg in cli_args]
539588
for k, v in env.items():
540589
monkeypatch.setenv(k, v.format(**template_ctx))
541590

542591
with tmpdir.as_cwd():
543592
runner = CliRunner()
544593

545-
with pytest.raises(exception, match=message.format(**template_ctx)):
546-
runner.invoke(
594+
if exception is not None:
595+
with pytest.raises(exception, match=message.format(**template_ctx)):
596+
result = runner.invoke(
597+
cli.cli, cli_args, input=''.join(inputs), catch_exceptions=False
598+
)
599+
else:
600+
result = runner.invoke(
547601
cli.cli, cli_args, input=''.join(inputs), catch_exceptions=False
548602
)
603+
assert message.format(**template_ctx) in result.output
549604

550605

551606
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)