@@ -407,18 +407,18 @@ def test_load_zsh_autotitle_warning(cli_args, tmpdir, monkeypatch):
407407 assert 'Please set' not in result .output
408408
409409
410+ @pytest .mark .parametrize ("cli_cmd" , ['shell' , 'shell_plus' ])
410411@pytest .mark .parametrize (
411412 "cli_args,inputs,env,expected_output" ,
412413 [
413414 (
414- ['shell' , ' -L{SOCKET_NAME}' , '-c' , 'print(str(server.socket_name))' ],
415+ ['-L{SOCKET_NAME}' , '-c' , 'print(str(server.socket_name))' ],
415416 [],
416417 {},
417418 '{SERVER_SOCKET_NAME}' ,
418419 ),
419420 (
420421 [
421- 'shell' ,
422422 '-L{SOCKET_NAME}' ,
423423 '{SESSION_NAME}' ,
424424 '-c' ,
@@ -430,7 +430,6 @@ def test_load_zsh_autotitle_warning(cli_args, tmpdir, monkeypatch):
430430 ),
431431 (
432432 [
433- 'shell' ,
434433 '-L{SOCKET_NAME}' ,
435434 '{SESSION_NAME}' ,
436435 '{WINDOW_NAME}' ,
@@ -443,7 +442,6 @@ def test_load_zsh_autotitle_warning(cli_args, tmpdir, monkeypatch):
443442 ),
444443 (
445444 [
446- 'shell' ,
447445 '-L{SOCKET_NAME}' ,
448446 '{SESSION_NAME}' ,
449447 '{WINDOW_NAME}' ,
@@ -456,7 +454,6 @@ def test_load_zsh_autotitle_warning(cli_args, tmpdir, monkeypatch):
456454 ),
457455 (
458456 [
459- 'shell' ,
460457 '-L{SOCKET_NAME}' ,
461458 '{SESSION_NAME}' ,
462459 '{WINDOW_NAME}' ,
@@ -469,7 +466,6 @@ def test_load_zsh_autotitle_warning(cli_args, tmpdir, monkeypatch):
469466 ),
470467 (
471468 [
472- 'shell' ,
473469 '-L{SOCKET_NAME}' ,
474470 '-c' ,
475471 'print(pane.id)' ,
@@ -481,7 +477,15 @@ def test_load_zsh_autotitle_warning(cli_args, tmpdir, monkeypatch):
481477 ],
482478)
483479def test_shell (
484- cli_args , inputs , expected_output , env , tmpdir , monkeypatch , server , session
480+ cli_cmd ,
481+ cli_args ,
482+ inputs ,
483+ expected_output ,
484+ env ,
485+ tmpdir ,
486+ monkeypatch ,
487+ server ,
488+ session ,
485489):
486490 monkeypatch .setenv ('HOME' , str (tmpdir ))
487491 window_name = 'my_window'
@@ -497,7 +501,8 @@ def test_shell(
497501 SERVER_SOCKET_NAME = server .socket_name ,
498502 )
499503
500- cli_args [:] = [cli_arg .format (** template_ctx ) for cli_arg in cli_args ]
504+ cli_args = [cli_cmd ] + [cli_arg .format (** template_ctx ) for cli_arg in cli_args ]
505+
501506 for k , v in env .items ():
502507 monkeypatch .setenv (k , v .format (** template_ctx ))
503508
@@ -510,37 +515,152 @@ def test_shell(
510515 assert expected_output .format (** template_ctx ) in result .output
511516
512517
518+ @pytest .mark .parametrize ("cli_cmd" , ['shell' , 'shell_plus' ])
513519@pytest .mark .parametrize (
514- "cli_args,inputs,env,exception, message" ,
520+ "cli_args,inputs,env,template_ctx, exception,message" ,
515521 [
516522 (
517- ['shell' , '-L{SOCKET_NAME} ' , '-c' , 'print(str(server.socket_name))' ],
523+ ['-LDoesNotExist ' , '-c' , 'print(str(server.socket_name))' ],
518524 [],
519525 {},
526+ {},
520527 LibTmuxException ,
521- 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}' ,
522556 ),
523557 ],
524558)
525- def test_shell_no_server (
526- 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 ,
527572):
528573 monkeypatch .setenv ('HOME' , str (tmpdir ))
574+ window_name = 'my_window'
575+ window = session .new_window (window_name = window_name )
576+ window .split_window ()
577+
529578 template_ctx = dict (
530- 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 ,
531585 )
586+ cli_args = [cli_cmd ] + [cli_arg .format (** template_ctx ) for cli_arg in cli_args ]
532587
533- cli_args [:] = [cli_arg .format (** template_ctx ) for cli_arg in cli_args ]
534588 for k , v in env .items ():
535589 monkeypatch .setenv (k , v .format (** template_ctx ))
536590
537591 with tmpdir .as_cwd ():
538592 runner = CliRunner ()
539593
540- with pytest .raises (exception , match = message .format (** template_ctx )):
541- 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 (
542601 cli .cli , cli_args , input = '' .join (inputs ), catch_exceptions = False
543602 )
603+ assert message .format (** template_ctx ) in result .output
604+
605+
606+ @pytest .mark .parametrize (
607+ "cli_args,inputs,env,message" ,
608+ [
609+ (
610+ [
611+ 'shell_plus' ,
612+ '-L{SOCKET_NAME}' ,
613+ ],
614+ [],
615+ {},
616+ '(InteractiveConsole)' ,
617+ ),
618+ (
619+ [
620+ 'shell_plus' ,
621+ '-L{SOCKET_NAME}' ,
622+ ],
623+ [],
624+ {'PANE_ID' : '{PANE_ID}' },
625+ '(InteractiveConsole)' ,
626+ ),
627+ ],
628+ )
629+ def test_shell_plus (
630+ cli_args ,
631+ inputs ,
632+ env ,
633+ message ,
634+ tmpdir ,
635+ monkeypatch ,
636+ server ,
637+ session ,
638+ ):
639+ monkeypatch .setenv ('HOME' , str (tmpdir ))
640+ window_name = 'my_window'
641+ window = session .new_window (window_name = window_name )
642+ window .split_window ()
643+
644+ template_ctx = dict (
645+ SOCKET_NAME = server .socket_name ,
646+ SOCKET_PATH = server .socket_path ,
647+ SESSION_NAME = session .name ,
648+ WINDOW_NAME = window_name ,
649+ PANE_ID = window .attached_pane .id ,
650+ SERVER_SOCKET_NAME = server .socket_name ,
651+ )
652+
653+ cli_args [:] = [cli_arg .format (** template_ctx ) for cli_arg in cli_args ]
654+ for k , v in env .items ():
655+ monkeypatch .setenv (k , v .format (** template_ctx ))
656+
657+ with tmpdir .as_cwd ():
658+ runner = CliRunner ()
659+
660+ result = runner .invoke (
661+ cli .cli , cli_args , input = '' .join (inputs ), catch_exceptions = True
662+ )
663+ assert message .format (** template_ctx ) in result .output
544664
545665
546666@pytest .mark .parametrize (
0 commit comments