44import os
55import unittest
66import logging
7+ import time
78import kaptan
89from .. import Window , config , exc
910from ..workspacebuilder import WorkspaceBuilder
@@ -24,7 +25,7 @@ class TwoPaneTest(TmuxTestCase):
2425 - vim
2526 start_directory: '~'
2627 - shell_command:
27- - cowsay "hey"
28+ - echo "hey"
2829 window_name: editor
2930 - panes:
3031 - shell_command:
@@ -70,9 +71,9 @@ class ThreePaneTest(TmuxTestCase):
7071 - vim
7172 start_directory: '~'
7273 - shell_command:
73- - cowsay "hey"
74+ - echo "hey"
7475 - shell_command:
75- - cowsay "moo"
76+ - echo "moo"
7677 '''
7778
7879 def test_split_windows (self ):
@@ -112,9 +113,9 @@ class FocusAndPaneIndexTest(TmuxTestCase):
112113 - vim
113114 start_directory: '~'
114115 - shell_command:
115- - cowsay "hey"
116+ - echo "hey"
116117 - shell_command:
117- - cowsay "moo"
118+ - echo "moo"
118119 - top
119120 focus: true
120121 - window_name: window 2
@@ -124,9 +125,9 @@ class FocusAndPaneIndexTest(TmuxTestCase):
124125 start_directory: '~'
125126 focus: true
126127 - shell_command:
127- - cowsay "hey"
128+ - echo "hey"
128129 - shell_command:
129- - cowsay "moo"
130+ - echo "moo"
130131
131132 '''
132133
@@ -165,8 +166,6 @@ def test_split_windows(self):
165166
166167class WindowOptions (TmuxTestCase ):
167168
168- '''sample config with no session name'''
169-
170169 yaml_config = '''
171170 session_name: test window options
172171 start_directory: '~'
@@ -179,9 +178,9 @@ class WindowOptions(TmuxTestCase):
179178 - vim
180179 start_directory: '~'
181180 - shell_command:
182- - cowsay "hey"
181+ - echo "hey"
183182 - shell_command:
184- - cowsay "moo"
183+ - echo "moo"
185184 window_name: editor
186185 '''
187186
@@ -208,6 +207,69 @@ def test_window_options(self):
208207 w .select_layout (wconf ['layout' ])
209208
210209
210+ class WindowAutomaticRename (TmuxTestCase ):
211+
212+ yaml_config = '''
213+ session_name: test window options
214+ start_directory: '~'
215+ windows:
216+ - layout: main-horizontal
217+ options:
218+ automatic-rename: on
219+ panes:
220+ - shell_command:
221+ - nano
222+ start_directory: '~'
223+ - shell_command:
224+ - echo "hey"
225+ - shell_command:
226+ - echo "moo"
227+ '''
228+
229+ def test_automatic_rename_option (self ):
230+ """ with option automatic-rename: on. """
231+ s = self .session
232+ sconfig = kaptan .Kaptan (handler = 'yaml' )
233+ sconfig = sconfig .import_config (self .yaml_config ).get ()
234+
235+ builder = WorkspaceBuilder (sconf = sconfig )
236+
237+ window_count = len (self .session ._windows ) # current window count
238+ self .assertEqual (len (s ._windows ), window_count )
239+ for w , wconf in builder .iter_create_windows (s ):
240+
241+ window_pane_count = len (w ._panes )
242+ for p in builder .iter_create_panes (w , wconf ):
243+ p = p
244+ self .assertEqual (len (s ._windows ), window_count )
245+ self .assertIsInstance (w , Window )
246+ self .assertEqual (w .show_window_option ('automatic-rename' ), 'on' )
247+
248+ self .assertEqual (len (s ._windows ), window_count )
249+
250+ window_count += 1
251+ w .select_layout (wconf ['layout' ])
252+
253+ w = s .attached_window ()
254+
255+ for i in range (5 ):
256+ w = s .attached_window ()
257+ if w ['window_name' ] == 'nano' :
258+ break
259+ time .sleep (.1 )
260+
261+ self .assertEqual (w .get ('window_name' ), 'nano' )
262+
263+ w .select_pane ('-D' )
264+ for i in range (5 ):
265+ w = s .attached_window ()
266+ if w ['window_name' ] != 'nano' :
267+ break
268+ time .sleep (.1 )
269+
270+ self .assertNotEqual (w .get ('window_name' ), 'nano' )
271+
272+
211273class TestsToDo (object ):
212274
213275 def test_uses_first_window_if_exists (self ):
0 commit comments