@@ -407,18 +407,18 @@ def test_load_zsh_autotitle_warning(cli_args, tmpdir, monkeypatch):
407
407
assert 'Please set' not in result .output
408
408
409
409
410
+ @pytest .mark .parametrize ("cli_cmd" , ['shell' , 'shell_plus' ])
410
411
@pytest .mark .parametrize (
411
412
"cli_args,inputs,env,expected_output" ,
412
413
[
413
414
(
414
- ['shell' , ' -L{SOCKET_NAME}' , '-c' , 'print(str(server.socket_name))' ],
415
+ ['-L{SOCKET_NAME}' , '-c' , 'print(str(server.socket_name))' ],
415
416
[],
416
417
{},
417
418
'{SERVER_SOCKET_NAME}' ,
418
419
),
419
420
(
420
421
[
421
- 'shell' ,
422
422
'-L{SOCKET_NAME}' ,
423
423
'{SESSION_NAME}' ,
424
424
'-c' ,
@@ -430,7 +430,6 @@ def test_load_zsh_autotitle_warning(cli_args, tmpdir, monkeypatch):
430
430
),
431
431
(
432
432
[
433
- 'shell' ,
434
433
'-L{SOCKET_NAME}' ,
435
434
'{SESSION_NAME}' ,
436
435
'{WINDOW_NAME}' ,
@@ -443,7 +442,6 @@ def test_load_zsh_autotitle_warning(cli_args, tmpdir, monkeypatch):
443
442
),
444
443
(
445
444
[
446
- 'shell' ,
447
445
'-L{SOCKET_NAME}' ,
448
446
'{SESSION_NAME}' ,
449
447
'{WINDOW_NAME}' ,
@@ -456,7 +454,6 @@ def test_load_zsh_autotitle_warning(cli_args, tmpdir, monkeypatch):
456
454
),
457
455
(
458
456
[
459
- 'shell' ,
460
457
'-L{SOCKET_NAME}' ,
461
458
'{SESSION_NAME}' ,
462
459
'{WINDOW_NAME}' ,
@@ -469,7 +466,6 @@ def test_load_zsh_autotitle_warning(cli_args, tmpdir, monkeypatch):
469
466
),
470
467
(
471
468
[
472
- 'shell' ,
473
469
'-L{SOCKET_NAME}' ,
474
470
'-c' ,
475
471
'print(pane.id)' ,
@@ -481,7 +477,15 @@ def test_load_zsh_autotitle_warning(cli_args, tmpdir, monkeypatch):
481
477
],
482
478
)
483
479
def 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 ,
485
489
):
486
490
monkeypatch .setenv ('HOME' , str (tmpdir ))
487
491
window_name = 'my_window'
@@ -497,7 +501,8 @@ def test_shell(
497
501
SERVER_SOCKET_NAME = server .socket_name ,
498
502
)
499
503
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
+
501
506
for k , v in env .items ():
502
507
monkeypatch .setenv (k , v .format (** template_ctx ))
503
508
@@ -510,37 +515,152 @@ def test_shell(
510
515
assert expected_output .format (** template_ctx ) in result .output
511
516
512
517
518
+ @pytest .mark .parametrize ("cli_cmd" , ['shell' , 'shell_plus' ])
513
519
@pytest .mark .parametrize (
514
- "cli_args,inputs,env,exception, message" ,
520
+ "cli_args,inputs,env,template_ctx, exception,message" ,
515
521
[
516
522
(
517
- ['shell' , '-L{SOCKET_NAME} ' , '-c' , 'print(str(server.socket_name))' ],
523
+ ['-LDoesNotExist ' , '-c' , 'print(str(server.socket_name))' ],
518
524
[],
519
525
{},
526
+ {},
520
527
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}' ,
522
556
),
523
557
],
524
558
)
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 ,
527
572
):
528
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
+
529
578
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 ,
531
585
)
586
+ cli_args = [cli_cmd ] + [cli_arg .format (** template_ctx ) for cli_arg in cli_args ]
532
587
533
- cli_args [:] = [cli_arg .format (** template_ctx ) for cli_arg in cli_args ]
534
588
for k , v in env .items ():
535
589
monkeypatch .setenv (k , v .format (** template_ctx ))
536
590
537
591
with tmpdir .as_cwd ():
538
592
runner = CliRunner ()
539
593
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 (
542
601
cli .cli , cli_args , input = '' .join (inputs ), catch_exceptions = False
543
602
)
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
544
664
545
665
546
666
@pytest .mark .parametrize (
0 commit comments