|
13 | 13 | import libtmux
|
14 | 14 | from libtmux.common import has_lt_version
|
15 | 15 | from libtmux.exc import LibTmuxException
|
16 |
| -from tmuxp import cli, config |
| 16 | +from tmuxp import cli, config, exc |
17 | 17 | from tmuxp.cli import (
|
18 | 18 | command_ls,
|
19 | 19 | get_config_dir,
|
@@ -515,37 +515,92 @@ def test_shell(
|
515 | 515 | assert expected_output.format(**template_ctx) in result.output
|
516 | 516 |
|
517 | 517 |
|
| 518 | +@pytest.mark.parametrize("cli_cmd", ['shell', 'shell_plus']) |
518 | 519 | @pytest.mark.parametrize(
|
519 |
| - "cli_args,inputs,env,exception,message", |
| 520 | + "cli_args,inputs,env,template_ctx,exception,message", |
520 | 521 | [
|
521 | 522 | (
|
522 |
| - ['shell', '-L{SOCKET_NAME}', '-c', 'print(str(server.socket_name))'], |
| 523 | + ['-LDoesNotExist', '-c', 'print(str(server.socket_name))'], |
523 | 524 | [],
|
524 | 525 | {},
|
| 526 | + {}, |
525 | 527 | 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}', |
527 | 556 | ),
|
528 | 557 | ],
|
529 | 558 | )
|
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, |
532 | 572 | ):
|
533 | 573 | monkeypatch.setenv('HOME', str(tmpdir))
|
| 574 | + window_name = 'my_window' |
| 575 | + window = session.new_window(window_name=window_name) |
| 576 | + window.split_window() |
| 577 | + |
534 | 578 | 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, |
536 | 585 | )
|
| 586 | + cli_args = [cli_cmd] + [cli_arg.format(**template_ctx) for cli_arg in cli_args] |
537 | 587 |
|
538 |
| - cli_args[:] = [cli_arg.format(**template_ctx) for cli_arg in cli_args] |
539 | 588 | for k, v in env.items():
|
540 | 589 | monkeypatch.setenv(k, v.format(**template_ctx))
|
541 | 590 |
|
542 | 591 | with tmpdir.as_cwd():
|
543 | 592 | runner = CliRunner()
|
544 | 593 |
|
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( |
547 | 601 | cli.cli, cli_args, input=''.join(inputs), catch_exceptions=False
|
548 | 602 | )
|
| 603 | + assert message.format(**template_ctx) in result.output |
549 | 604 |
|
550 | 605 |
|
551 | 606 | @pytest.mark.parametrize(
|
|
0 commit comments