|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +from __future__ import absolute_import, division, print_function, with_statement |
| 3 | + |
| 4 | +import os |
| 5 | +import unittest |
| 6 | +import logging |
| 7 | +import time |
| 8 | +import kaptan |
| 9 | +from .. import Window, config, exc |
| 10 | +from ..workspacebuilder import WorkspaceBuilder |
| 11 | +from .helpers import TmuxTestCase |
| 12 | + |
| 13 | +logger = logging.getLogger(__name__) |
| 14 | + |
| 15 | +current_dir = os.path.abspath(os.path.dirname(__file__)) |
| 16 | +example_dir = os.path.abspath(os.path.join(current_dir, '..', '..')) |
| 17 | + |
| 18 | + |
| 19 | +def freeza(session): |
| 20 | + sconf = {} |
| 21 | + |
| 22 | + sconf['session_name'] = session['session_name'] |
| 23 | + |
| 24 | + sconf['windows'] = [] |
| 25 | + for w in session.windows: |
| 26 | + wconf = {} |
| 27 | + wconf['options'] = w.show_window_options() |
| 28 | + wconf['window_name'] = w.get('window_name') |
| 29 | + wconf['panes'] = [] |
| 30 | + logger.error(w) |
| 31 | + logger.error(dict(w)) |
| 32 | + |
| 33 | + for p in w.panes: |
| 34 | + pconf = {} |
| 35 | + pconf['shell_command'] = [] |
| 36 | + pconf['shell_command'].append('cd ' + p.get('pane_current_path')) |
| 37 | + pconf['shell_command'].append(p.get('pane_current_command')) |
| 38 | + wconf['panes'].append(pconf) |
| 39 | + logger.error(p) |
| 40 | + logger.error(dict(p)) |
| 41 | + |
| 42 | + |
| 43 | + sconf['windows'].append(wconf) |
| 44 | + |
| 45 | + logger.error(sconf) |
| 46 | + |
| 47 | + return sconf |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | +class FreezeTest(TmuxTestCase): |
| 55 | + |
| 56 | + yaml_config = ''' |
| 57 | + session_name: sampleconfig |
| 58 | + start_directory: '~' |
| 59 | + windows: |
| 60 | + - layout: main-vertical |
| 61 | + panes: |
| 62 | + - shell_command: |
| 63 | + - vim |
| 64 | + start_directory: '~' |
| 65 | + - shell_command: |
| 66 | + - echo "hey" |
| 67 | + - cd ../ |
| 68 | + window_name: editor |
| 69 | + - panes: |
| 70 | + - shell_command: |
| 71 | + - tail -F /var/log/syslog |
| 72 | + start_directory: /var/log |
| 73 | + window_name: logging |
| 74 | + - window_name: test |
| 75 | + panes: |
| 76 | + - shell_command: |
| 77 | + - htop |
| 78 | + ''' |
| 79 | + |
| 80 | + def test_split_windows(self): |
| 81 | + sconfig = kaptan.Kaptan(handler='yaml') |
| 82 | + sconfig = sconfig.import_config(self.yaml_config).get() |
| 83 | + |
| 84 | + builder = WorkspaceBuilder(sconf=sconfig) |
| 85 | + builder.build(session=self.session) |
| 86 | + assert(self.session == builder.session) |
| 87 | + |
| 88 | + import time |
| 89 | + time.sleep(1) |
| 90 | + |
| 91 | + session = self.session |
| 92 | + sconf = freeza(session) |
| 93 | + |
| 94 | + config.check_consistency(sconf) |
| 95 | + |
| 96 | + sconf = config.inline(sconf) |
| 97 | + |
| 98 | + kaptanconf = kaptan.Kaptan() |
| 99 | + kaptanconf = kaptanconf.import_config(sconf) |
| 100 | + json = kaptanconf.export('json', indent=2) |
| 101 | + json = kaptanconf.export('json', indent=2) |
| 102 | + yaml = kaptanconf.export( |
| 103 | + 'yaml', indent=2, default_flow_style=False, safe=True) |
| 104 | + |
| 105 | + |
| 106 | + logger.error(json) |
| 107 | + logger.error(yaml) |
| 108 | + |
| 109 | +if __name__ == '__main__': |
| 110 | + unittest.main() |
0 commit comments