Skip to content

Commit f936cfa

Browse files
committed
more tmuxinator import tests
1 parent 14384b8 commit f936cfa

File tree

1 file changed

+103
-2
lines changed

1 file changed

+103
-2
lines changed

tmuxp/testsuite/test_config_tmuxinator.py

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
TMUXP_DIR = os.path.join(os.path.dirname(__file__), '.tmuxp')
1616

1717
# https://github.com/aziz/tmuxinator
18-
18+
# TODO: handle 'root' with a cd shell_command_before
1919

2020
def tmuxinator_to_tmuxp(sconf):
2121
'''
@@ -28,12 +28,19 @@ def tmuxinator_to_tmuxp(sconf):
2828

2929
if 'project_name' in sconf:
3030
tmuxp_config['session_name'] = sconf['project_name']
31+
elif 'name' in sconf:
32+
tmuxp_config['session_name'] = sconf['name']
3133
else:
3234
tmuxp_config['session_name'] = None
3335

3436
if 'cli_args' in sconf:
3537
tmuxp_config['config'] = sconf['cli_args']
3638

39+
if '-f' in tmuxp_config['config']:
40+
tmuxp_config['config'] = tmuxp_config['config'].replace('-f', '').strip()
41+
elif 'tmux_options' in sconf:
42+
tmuxp_config['config'] = sconf['tmux_options']
43+
3744
if '-f' in tmuxp_config['config']:
3845
tmuxp_config['config'] = tmuxp_config['config'].replace('-f', '').strip()
3946

@@ -45,7 +52,14 @@ def tmuxinator_to_tmuxp(sconf):
4552
if 'tabs' in sconf:
4653
sconf['windows'] = sconf.pop('tabs')
4754

48-
if 'pre' in sconf:
55+
if 'pre' in sconf and 'pre_window' in sconf:
56+
tmuxp_config['shell_command'] = sconf['pre']
57+
58+
if isinstance(sconf['pre'], basestring):
59+
tmuxp_config['shell_command_before'] = [sconf['pre_window']]
60+
else:
61+
tmuxp_config['shell_command_before'] = sconf['pre_window']
62+
elif 'pre' in sconf:
4963
if isinstance(sconf['pre'], basestring):
5064
tmuxp_config['shell_command_before'] = [sconf['pre']]
5165
else:
@@ -69,6 +83,10 @@ def tmuxinator_to_tmuxp(sconf):
6983
windowdict['panes'] = [v]
7084
tmuxp_config['windows'].append(windowdict)
7185
continue
86+
elif isinstance(v, list):
87+
windowdict['panes'] = v
88+
tmuxp_config['windows'].append(windowdict)
89+
continue
7290

7391
if 'pre' in v:
7492
windowdict['shell_command_before'] = v['pre']
@@ -430,12 +448,95 @@ class TmuxinatoriSampleTest(unittest.TestCase):
430448
]
431449
}
432450

451+
tmuxp_dict = {
452+
'session_name': 'sample',
453+
'socket_name': 'foo',
454+
'config': '~/.tmux.mac.conf',
455+
'shell_command': 'sudo /etc/rc.d/mysqld start',
456+
'shell_command_before': [
457+
'rbenv shell 2.0.0-p247'
458+
],
459+
'windows': [
460+
{
461+
'window_name': 'editor',
462+
'shell_command_before': [
463+
'echo "I get run in each pane, before each pane command!"',
464+
None
465+
],
466+
'layout': 'main-vertical',
467+
'panes': [
468+
'vim',
469+
None,
470+
'top'
471+
]
472+
},
473+
{
474+
'window_name': 'shell',
475+
'panes': [
476+
'git pull',
477+
'git merge'
478+
]
479+
},
480+
{
481+
'window_name': 'guard',
482+
'layout': 'tiled',
483+
'shell_command_before': [
484+
'echo "I get run in each pane."',
485+
'echo "Before each pane command!"'
486+
],
487+
'panes': [
488+
None,
489+
None,
490+
None
491+
]
492+
},
493+
{
494+
'window_name': 'database',
495+
'panes': [
496+
'bundle exec rails db'
497+
]
498+
},
499+
{
500+
'window_name': 'server',
501+
'panes': [
502+
'bundle exec rails s'
503+
]
504+
},
505+
{
506+
'window_name': 'logs',
507+
'panes': [
508+
'tail -f log/development.log'
509+
]
510+
},
511+
{
512+
'window_name': 'console',
513+
'panes': [
514+
'bundle exec rails c'
515+
]
516+
},
517+
{
518+
'window_name': 'capistrano',
519+
'panes': [
520+
None
521+
]
522+
},
523+
{
524+
'window_name': 'server',
525+
'panes': [
526+
'ssh user@example.com'
527+
]
528+
}
529+
]
530+
}
531+
433532
def test_config_to_dict(self):
434533
self.maxDiff = None
435534
configparser = kaptan.Kaptan(handler='yaml')
436535
test_config = configparser.import_config(self.tmuxinator_yaml)
437536
yaml_to_dict = test_config.get()
438537
self.assertDictEqual(yaml_to_dict, self.tmuxinator_dict)
439538

539+
self.assertDictEqual(tmuxinator_to_tmuxp(self.tmuxinator_dict), self.tmuxp_dict)
540+
440541
if __name__ == '__main__':
441542
unittest.main()

0 commit comments

Comments
 (0)