@@ -433,6 +433,164 @@ def test_load_symlinked_workspace(
433
433
assert pane .current_path == str (realtemp )
434
434
435
435
436
+ if t .TYPE_CHECKING :
437
+ from typing_extensions import TypeAlias
438
+
439
+ ExpectedOutput : TypeAlias = t .Optional [t .Union [str , t .List [str ]]]
440
+
441
+
442
+ class CLILoadFixture (t .NamedTuple ):
443
+ test_id : str
444
+ cli_args : t .List [t .Union [str , t .List [str ]]]
445
+ config_paths : t .List [str ]
446
+ session_names : t .List [str ]
447
+ expected_exit_code : int
448
+ expected_in_out : "ExpectedOutput" = None
449
+ expected_not_in_out : "ExpectedOutput" = None
450
+ expected_in_err : "ExpectedOutput" = None
451
+ expected_not_in_err : "ExpectedOutput" = None
452
+
453
+
454
+ TEST_LOAD_FIXTURES = [
455
+ CLILoadFixture (
456
+ test_id = "dir-relative-dot-samedir" ,
457
+ cli_args = ["load" , "." ],
458
+ config_paths = ["{tmp_path}/.tmuxp.yaml" ],
459
+ session_names = ["my_config" ],
460
+ expected_exit_code = 0 ,
461
+ expected_in_out = None ,
462
+ expected_not_in_out = None ,
463
+ ),
464
+ CLILoadFixture (
465
+ test_id = "dir-relative-dot-slash-samedir" ,
466
+ cli_args = ["load" , "./" ],
467
+ config_paths = ["{tmp_path}/.tmuxp.yaml" ],
468
+ session_names = ["my_config" ],
469
+ expected_exit_code = 0 ,
470
+ expected_in_out = None ,
471
+ expected_not_in_out = None ,
472
+ ),
473
+ CLILoadFixture (
474
+ test_id = "dir-relative-file-samedir" ,
475
+ cli_args = ["load" , "./.tmuxp.yaml" ],
476
+ config_paths = ["{tmp_path}/.tmuxp.yaml" ],
477
+ session_names = ["my_config" ],
478
+ expected_exit_code = 0 ,
479
+ expected_in_out = None ,
480
+ expected_not_in_out = None ,
481
+ ),
482
+ CLILoadFixture (
483
+ test_id = "filename-relative-file-samedir" ,
484
+ cli_args = ["load" , "./my_config.yaml" ],
485
+ config_paths = ["{tmp_path}/my_config.yaml" ],
486
+ session_names = ["my_config" ],
487
+ expected_exit_code = 0 ,
488
+ expected_in_out = None ,
489
+ expected_not_in_out = None ,
490
+ ),
491
+ CLILoadFixture (
492
+ test_id = "configdir-session-name" ,
493
+ cli_args = ["load" , "my_config" ],
494
+ config_paths = ["{TMUXP_CONFIGDIR}/my_config.yaml" ],
495
+ session_names = ["my_config" ],
496
+ expected_exit_code = 0 ,
497
+ expected_in_out = None ,
498
+ expected_not_in_out = None ,
499
+ ),
500
+ CLILoadFixture (
501
+ test_id = "configdir-absolute" ,
502
+ cli_args = ["load" , "~/.config/tmuxp/my_config.yaml" ],
503
+ config_paths = ["{TMUXP_CONFIGDIR}/my_config.yaml" ],
504
+ session_names = ["my_config" ],
505
+ expected_exit_code = 0 ,
506
+ expected_in_out = None ,
507
+ expected_not_in_out = None ,
508
+ ),
509
+ #
510
+ # Multiple configs
511
+ #
512
+ CLILoadFixture (
513
+ test_id = "configdir-session-name-double" ,
514
+ cli_args = ["load" , "my_config" , "second_config" ],
515
+ config_paths = [
516
+ "{TMUXP_CONFIGDIR}/my_config.yaml" ,
517
+ "{TMUXP_CONFIGDIR}/second_config.yaml" ,
518
+ ],
519
+ session_names = ["my_config" , "second_config" ],
520
+ expected_exit_code = 0 ,
521
+ expected_in_out = None ,
522
+ expected_not_in_out = None ,
523
+ ),
524
+ ]
525
+
526
+
527
+ @pytest .mark .parametrize (
528
+ list (CLILoadFixture ._fields ),
529
+ TEST_LOAD_FIXTURES ,
530
+ ids = [test .test_id for test in TEST_LOAD_FIXTURES ],
531
+ )
532
+ @pytest .mark .usefixtures ("tmuxp_configdir_default" )
533
+ def test_load (
534
+ tmp_path : pathlib .Path ,
535
+ tmuxp_configdir : pathlib .Path ,
536
+ server : "Server" ,
537
+ session : Session ,
538
+ capsys : pytest .CaptureFixture ,
539
+ monkeypatch : pytest .MonkeyPatch ,
540
+ test_id : str ,
541
+ cli_args : t .List [str ],
542
+ config_paths : t .List [str ],
543
+ session_names : t .List [str ],
544
+ expected_exit_code : int ,
545
+ expected_in_out : "ExpectedOutput" ,
546
+ expected_not_in_out : "ExpectedOutput" ,
547
+ expected_in_err : "ExpectedOutput" ,
548
+ expected_not_in_err : "ExpectedOutput" ,
549
+ ) -> None :
550
+ assert server .socket_name is not None
551
+
552
+ monkeypatch .chdir (tmp_path )
553
+ for session_name , config_path in zip (session_names , config_paths ):
554
+ tmuxp_config = pathlib .Path (
555
+ config_path .format (tmp_path = tmp_path , TMUXP_CONFIGDIR = tmuxp_configdir )
556
+ )
557
+ tmuxp_config .write_text (
558
+ """
559
+ session_name: {session_name}
560
+ windows:
561
+ - window_name: test
562
+ panes:
563
+ -
564
+ """ .format (
565
+ session_name = session_name
566
+ ),
567
+ encoding = "utf-8" ,
568
+ )
569
+
570
+ try :
571
+ cli .cli ([* cli_args , "-d" , "-L" , server .socket_name , "-y" ])
572
+ except SystemExit :
573
+ pass
574
+
575
+ result = capsys .readouterr ()
576
+ output = "" .join (list (result .out ))
577
+
578
+ if expected_in_out is not None :
579
+ if isinstance (expected_in_out , str ):
580
+ expected_in_out = [expected_in_out ]
581
+ for needle in expected_in_out :
582
+ assert needle in output
583
+
584
+ if expected_not_in_out is not None :
585
+ if isinstance (expected_not_in_out , str ):
586
+ expected_not_in_out = [expected_not_in_out ]
587
+ for needle in expected_not_in_out :
588
+ assert needle not in output
589
+
590
+ for session_name in session_names :
591
+ assert server .has_session (session_name )
592
+
593
+
436
594
def test_regression_00132_session_name_with_dots (
437
595
tmp_path : pathlib .Path ,
438
596
server : "Server" ,
0 commit comments