Skip to content

Commit d499d6c

Browse files
committed
Test new expand form for relative paths
1 parent 845588b commit d499d6c

File tree

2 files changed

+55
-10
lines changed

2 files changed

+55
-10
lines changed

tmuxp/config.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def inline(sconf):
124124
return sconf
125125

126126

127-
def expand(sconf):
127+
def expand(sconf, cwd=None):
128128
"""Return config with shorthand and inline properties expanded.
129129
130130
This is necessary to keep the code in the :class:`WorkspaceBuilder` clean
@@ -142,12 +142,22 @@ def expand(sconf):
142142
Kaptan will load JSON/YAML/INI files into python dicts for you.
143143
:param sconf: the configuration for the session
144144
:type sconf: dict
145+
:param cwd: directory to expand relative paths against. should be the dir of
146+
the config directory.
145147
:rtype: dict
146148
147149
"""
148150

151+
if not cwd:
152+
cwd = os.getcwd()
153+
149154
# Any config section, session, window, pane that can contain the
150155
# 'shell_command' value
156+
if 'start_directory' in sconf:
157+
if any(sconf['start_directory'].startswith(a) for a in ['.', './']):
158+
sconf['start_directory'] = os.path.normpath(os.path.join(cwd, sconf['start_directory']))
159+
elif any(sconf['start_directory'] == a for a in ['.', './']):
160+
sconf['start_directory'] = os.path.normpath(os.path.join(cwd, sconf['start_directory']))
151161

152162
if ('shell_command' in sconf and isinstance(sconf['shell_command'], basestring)):
153163
sconf['shell_command'] = [sconf['shell_command']]
@@ -202,13 +212,10 @@ def trickle(sconf):
202212

203213
# Prepend start_directory to relative window commands
204214
if session_start_directory:
205-
206215
if not 'start_directory' in windowconfig:
207216
windowconfig['start_directory'] = session_start_directory
208217
else:
209-
if any(windowconfig['start_directory'] == a for a in ['.', './']):
210-
windowconfig['start_directory'] = os.getcwd()
211-
elif not any(windowconfig['start_directory'].startswith(a) for a in ['~', '/']):
218+
if not any(windowconfig['start_directory'].startswith(a) for a in ['~', '/']):
212219
windowconfig['start_directory'] = os.path.join(
213220
session_start_directory, windowconfig['start_directory'])
214221

tmuxp/testsuite/test_config.py

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,25 @@ class ExpandTest(unittest.TestCase):
167167
'vim',
168168
]
169169
},
170+
{
171+
'start_directory': './',
172+
'panes': [
173+
'pwd'
174+
]
175+
},
176+
{
177+
'start_directory': './asdf/',
178+
'panes': [
179+
'pwd'
180+
]
181+
},
182+
{
183+
'start_directory': '../',
184+
'panes': [
185+
'pwd'
186+
]
187+
},
188+
170189
{
171190
'panes': [
172191
'top'
@@ -194,8 +213,9 @@ class ExpandTest(unittest.TestCase):
194213
{
195214
'window_name': 'logging',
196215
'panes': [
197-
{'shell_command': ['tail -F /var/log/syslog'],
198-
}
216+
{
217+
'shell_command': ['tail -F /var/log/syslog'],
218+
}
199219
]
200220
},
201221
{
@@ -206,6 +226,25 @@ class ExpandTest(unittest.TestCase):
206226
{'shell_command': ['vim']}
207227
]
208228
},
229+
{
230+
'start_directory': os.path.abspath('./'),
231+
'panes': [
232+
{'shell_command': ['pwd']}
233+
]
234+
},
235+
{
236+
'start_directory': os.path.abspath('./asdf/'),
237+
'panes': [
238+
{'shell_command': ['pwd']}
239+
]
240+
},
241+
{
242+
'start_directory': os.path.abspath('../'),
243+
'panes': [
244+
{'shell_command': ['pwd']}
245+
]
246+
},
247+
209248
{
210249
'panes': [
211250
{'shell_command': ['top']}
@@ -215,11 +254,10 @@ class ExpandTest(unittest.TestCase):
215254
}
216255

217256
def test_config(self):
218-
'''
219-
expands shell commands from string to list
220-
'''
257+
"""Expand shell commands from string to list."""
221258
self.maxDiff = None
222259
test_config = config.expand(self.before_config)
260+
logger.error(test_config)
223261
self.assertDictEqual(test_config, self.after_config)
224262

225263

0 commit comments

Comments
 (0)