1818import kaptan
1919
2020from .. import config , exc
21+ from .._compat import support
2122from .helpers import TestCase
2223
2324
25+
2426logger = logging .getLogger (__name__ )
2527TMUXP_DIR = os .path .join (os .path .dirname (__file__ ), '.tmuxp' )
2628current_dir = os .path .abspath (os .path .dirname (__file__ ))
@@ -1061,6 +1063,42 @@ def test_no_window_name(self):
10611063 config .validate_schema (sconfig )
10621064
10631065
1066+ class ConfigExpandEnvironmentVariables (TestCase , unittest .TestCase ):
1067+ def test_replaces_start_directory (self ):
1068+ env_key = "TESTHEY92"
1069+ env_value = "HEYO1"
1070+ yaml_config = """
1071+ start_directory: {TEST_VAR}/test
1072+ shell_command_before: {TEST_VAR}/test2
1073+ before_script: {TEST_VAR}/test3
1074+ session_name: hi - {TEST_VAR}
1075+ windows:
1076+ - window_name: editor
1077+ panes:
1078+ - shell_command:
1079+ - tail -F /var/log/syslog
1080+ start_directory: /var/log
1081+ - window_name: logging @ {TEST_VAR}
1082+ automatic_rename: true
1083+ panes:
1084+ - shell_command:
1085+ - htop
1086+ """ .format (
1087+ TEST_VAR = "${%s}" % env_key
1088+ )
1089+
1090+ sconfig = kaptan .Kaptan (handler = 'yaml' )
1091+ sconfig = sconfig .import_config (yaml_config ).get ()
1092+
1093+ with support .EnvironmentVarGuard () as env :
1094+ env .set (env_key , env_value )
1095+ sconfig = config .expand (sconfig )
1096+ self .assertEqual ("%s/test" % env_value , sconfig ['start_directory' ])
1097+ self .assertIn ("%s/test2" % env_value , sconfig ['shell_command_before' ])
1098+ self .assertEqual ("%s/test3" % env_value , sconfig ['before_script' ])
1099+ self .assertEqual ("hi - %s" % env_value , sconfig ['session_name' ])
1100+ self .assertEqual ("logging @ %s" % env_value , sconfig ['windows' ][1 ]['window_name' ])
1101+
10641102def suite ():
10651103 suite = unittest .TestSuite ()
10661104 suite .addTest (unittest .makeSuite (ConfigBlankPanes ))
@@ -1071,4 +1109,5 @@ def suite():
10711109 suite .addTest (unittest .makeSuite (ShellCommandBeforeTest ))
10721110 suite .addTest (unittest .makeSuite (ShellCommandBeforeSession ))
10731111 suite .addTest (unittest .makeSuite (TrickleRelativeStartDirectory ))
1112+ suite .addTest (unittest .makeSuite (ConfigExpandEnvironmentVariables ))
10741113 return suite
0 commit comments