Skip to content

Commit 423a478

Browse files
committed
let's try autorename test. update select_pane to correctly use -l -U -D -L -R or custom target_pane input
1 parent 1dd1368 commit 423a478

File tree

2 files changed

+79
-16
lines changed

2 files changed

+79
-16
lines changed

tmuxp/testsuite/test_workspacebuilder.py

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import unittest
66
import logging
7+
import time
78
import kaptan
89
from .. import Window, config, exc
910
from ..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

166167
class 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+
211273
class TestsToDo(object):
212274

213275
def test_uses_first_window_if_exists(self):

tmuxp/window.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,17 @@ def select_pane(self, target_pane):
235235
'''
236236
``$ tmux select-pane``
237237
238-
:param target_pane: ``target_pane``, or ``-U``,``-D``, ``-L``, ``-R``.
238+
:param target_pane: ``target_pane``, or ``-U``,``-D``, ``-L``, ``-R``
239+
or ``-l``.
239240
:type target_pane: string
240241
:rtype: :class:`Pane`
241242
242-
Todo: make 'up', 'down', 'left', 'right' acceptable ``target_pane``.
243243
'''
244-
# if isinstance(target_pane, basestring) and not ':' not in target_pane or isinstance(target_pane, int):
245-
# target_pane = "%s.%s" % (self.target, target_pane)
246244

247-
proc = self.tmux('select-pane', '-t%s' % target_pane)
245+
if target_pane in ['-l', '-U', '-D', '-L', '-R']:
246+
proc = self.tmux('select-pane', '-t%s' % self.get('window_id'), target_pane)
247+
else:
248+
proc = self.tmux('select-pane', '-t%s' % target_pane)
248249

249250
if proc.stderr:
250251
raise Exception(proc.stderr)

0 commit comments

Comments
 (0)