@@ -25,22 +25,26 @@ class CLIShellFixture(t.NamedTuple):
25
25
test_id : str
26
26
27
27
# test params
28
+ cli_cmd : list [str ]
28
29
cli_args : list [str ]
29
30
inputs : list [t .Any ]
30
31
env : dict [str , str ]
31
32
expected_output : str
32
33
33
34
34
35
TEST_SHELL_FIXTURES : list [CLIShellFixture ] = [
36
+ # Regular shell command
35
37
CLIShellFixture (
36
38
test_id = "print-socket-name" ,
39
+ cli_cmd = ["shell" ],
37
40
cli_args = ["-L{SOCKET_NAME}" , "-c" , "print(str(server.socket_name))" ],
38
41
inputs = [],
39
42
env = {},
40
43
expected_output = "{SERVER_SOCKET_NAME}" ,
41
44
),
42
45
CLIShellFixture (
43
46
test_id = "print-session-name" ,
47
+ cli_cmd = ["shell" ],
44
48
cli_args = [
45
49
"-L{SOCKET_NAME}" ,
46
50
"{SESSION_NAME}" ,
@@ -53,6 +57,7 @@ class CLIShellFixture(t.NamedTuple):
53
57
),
54
58
CLIShellFixture (
55
59
test_id = "print-has-session" ,
60
+ cli_cmd = ["shell" ],
56
61
cli_args = [
57
62
"-L{SOCKET_NAME}" ,
58
63
"{SESSION_NAME}" ,
@@ -66,6 +71,7 @@ class CLIShellFixture(t.NamedTuple):
66
71
),
67
72
CLIShellFixture (
68
73
test_id = "print-window-name" ,
74
+ cli_cmd = ["shell" ],
69
75
cli_args = [
70
76
"-L{SOCKET_NAME}" ,
71
77
"{SESSION_NAME}" ,
@@ -79,6 +85,7 @@ class CLIShellFixture(t.NamedTuple):
79
85
),
80
86
CLIShellFixture (
81
87
test_id = "print-pane-id" ,
88
+ cli_cmd = ["shell" ],
82
89
cli_args = [
83
90
"-L{SOCKET_NAME}" ,
84
91
"{SESSION_NAME}" ,
@@ -92,6 +99,7 @@ class CLIShellFixture(t.NamedTuple):
92
99
),
93
100
CLIShellFixture (
94
101
test_id = "print-pane-id-obeys-tmux-pane-env-var" ,
102
+ cli_cmd = ["shell" ],
95
103
cli_args = [
96
104
"-L{SOCKET_NAME}" ,
97
105
"-c" ,
@@ -101,72 +109,93 @@ class CLIShellFixture(t.NamedTuple):
101
109
env = {"TMUX_PANE" : "{PANE_ID}" },
102
110
expected_output = "{PANE_ID}" ,
103
111
),
104
- ]
105
-
106
-
107
- class CLIShellTargetMissingFixture (t .NamedTuple ):
108
- """Test fixture for tmuxp shell target missing tests."""
109
-
110
- test_id : str
111
- cli_args : list [str ]
112
- inputs : list [t .Any ]
113
- env : dict [t .Any , t .Any ]
114
- template_ctx : dict [str , str ]
115
- exception : type [exc .TmuxpException | subprocess .CalledProcessError ]
116
- message : str
117
-
118
-
119
- TEST_SHELL_TARGET_MISSING_FIXTURES : list [CLIShellTargetMissingFixture ] = [
120
- CLIShellTargetMissingFixture (
121
- test_id = "nonexistent_socket" ,
122
- cli_args = ["-LDoesNotExist" , "-c" , "print(str(server.socket_name))" ],
112
+ # Shell with --pdb
113
+ CLIShellFixture (
114
+ test_id = "print-socket-name-pdb" ,
115
+ cli_cmd = ["shell" , "--pdb" ],
116
+ cli_args = ["-L{SOCKET_NAME}" , "-c" , "print(str(server.socket_name))" ],
123
117
inputs = [],
124
118
env = {},
125
- template_ctx = {},
126
- exception = subprocess .CalledProcessError ,
127
- message = r".*DoesNotExist.*" ,
119
+ expected_output = "{SERVER_SOCKET_NAME}" ,
128
120
),
129
- CLIShellTargetMissingFixture (
130
- test_id = "nonexistent_session" ,
121
+ CLIShellFixture (
122
+ test_id = "print-session-name-pdb" ,
123
+ cli_cmd = ["shell" , "--pdb" ],
131
124
cli_args = [
132
125
"-L{SOCKET_NAME}" ,
133
- "nonexistent_session " ,
126
+ "{SESSION_NAME} " ,
134
127
"-c" ,
135
- "print(str(server.socket_name) )" ,
128
+ "print(session.name )" ,
136
129
],
137
130
inputs = [],
138
131
env = {},
139
- template_ctx = {"session_name" : "nonexistent_session" },
140
- exception = exc .TmuxpException ,
141
- message = "Session not found: nonexistent_session" ,
132
+ expected_output = "{SESSION_NAME}" ,
142
133
),
143
- CLIShellTargetMissingFixture (
144
- test_id = "nonexistent_window" ,
134
+ CLIShellFixture (
135
+ test_id = "print-has-session-pdb" ,
136
+ cli_cmd = ["shell" , "--pdb" ],
145
137
cli_args = [
146
138
"-L{SOCKET_NAME}" ,
147
139
"{SESSION_NAME}" ,
148
- "nonexistent_window " ,
140
+ "{WINDOW_NAME} " ,
149
141
"-c" ,
150
- "print(str( server.socket_name ))" ,
142
+ "print(server.has_session(session.name ))" ,
151
143
],
152
144
inputs = [],
153
145
env = {},
154
- template_ctx = {"window_name" : "nonexistent_window" },
155
- exception = exc .TmuxpException ,
156
- message = "Window not found: {WINDOW_NAME}" ,
146
+ expected_output = "True" ,
147
+ ),
148
+ CLIShellFixture (
149
+ test_id = "print-window-name-pdb" ,
150
+ cli_cmd = ["shell" , "--pdb" ],
151
+ cli_args = [
152
+ "-L{SOCKET_NAME}" ,
153
+ "{SESSION_NAME}" ,
154
+ "{WINDOW_NAME}" ,
155
+ "-c" ,
156
+ "print(window.name)" ,
157
+ ],
158
+ inputs = [],
159
+ env = {},
160
+ expected_output = "{WINDOW_NAME}" ,
161
+ ),
162
+ CLIShellFixture (
163
+ test_id = "print-pane-id-pdb" ,
164
+ cli_cmd = ["shell" , "--pdb" ],
165
+ cli_args = [
166
+ "-L{SOCKET_NAME}" ,
167
+ "{SESSION_NAME}" ,
168
+ "{WINDOW_NAME}" ,
169
+ "-c" ,
170
+ "print(pane.id)" ,
171
+ ],
172
+ inputs = [],
173
+ env = {},
174
+ expected_output = "{PANE_ID}" ,
175
+ ),
176
+ CLIShellFixture (
177
+ test_id = "print-pane-id-obeys-tmux-pane-env-var-pdb" ,
178
+ cli_cmd = ["shell" , "--pdb" ],
179
+ cli_args = [
180
+ "-L{SOCKET_NAME}" ,
181
+ "-c" ,
182
+ "print(pane.id)" ,
183
+ ],
184
+ inputs = [],
185
+ env = {"TMUX_PANE" : "{PANE_ID}" },
186
+ expected_output = "{PANE_ID}" ,
157
187
),
158
188
]
159
189
160
190
161
- @pytest .mark .parametrize ("cli_cmd" , [["shell" ], ["shell" , "--pdb" ]])
162
191
@pytest .mark .parametrize (
163
192
list (CLIShellFixture ._fields ),
164
193
TEST_SHELL_FIXTURES ,
165
194
ids = [test .test_id for test in TEST_SHELL_FIXTURES ],
166
195
)
167
196
def test_shell (
168
- cli_cmd : list [str ],
169
197
test_id : str ,
198
+ cli_cmd : list [str ],
170
199
cli_args : list [str ],
171
200
inputs : list [t .Any ],
172
201
env : dict [str , str ],
@@ -205,28 +234,121 @@ def test_shell(
205
234
assert expected_output .format (** template_ctx ) in result .out
206
235
207
236
208
- @pytest .mark .parametrize (
209
- "cli_cmd" ,
210
- [
211
- ["shell" ],
212
- ["shell" , "--pdb" ],
213
- ],
214
- )
237
+ class CLIShellTargetMissingFixture (t .NamedTuple ):
238
+ """Test fixture for tmuxp shell target missing tests."""
239
+
240
+ test_id : str
241
+ cli_cmd : list [str ]
242
+ cli_args : list [str ]
243
+ inputs : list [t .Any ]
244
+ env : dict [t .Any , t .Any ]
245
+ template_ctx : dict [str , str ]
246
+ exception : type [exc .TmuxpException | subprocess .CalledProcessError ]
247
+ message : str
248
+
249
+
250
+ TEST_SHELL_TARGET_MISSING_FIXTURES : list [CLIShellTargetMissingFixture ] = [
251
+ # Regular shell command
252
+ CLIShellTargetMissingFixture (
253
+ test_id = "nonexistent_socket" ,
254
+ cli_cmd = ["shell" ],
255
+ cli_args = ["-LDoesNotExist" , "-c" , "print(str(server.socket_name))" ],
256
+ inputs = [],
257
+ env = {},
258
+ template_ctx = {},
259
+ exception = subprocess .CalledProcessError ,
260
+ message = r".*DoesNotExist.*" ,
261
+ ),
262
+ CLIShellTargetMissingFixture (
263
+ test_id = "nonexistent_session" ,
264
+ cli_cmd = ["shell" ],
265
+ cli_args = [
266
+ "-L{SOCKET_NAME}" ,
267
+ "nonexistent_session" ,
268
+ "-c" ,
269
+ "print(str(server.socket_name))" ,
270
+ ],
271
+ inputs = [],
272
+ env = {},
273
+ template_ctx = {"session_name" : "nonexistent_session" },
274
+ exception = exc .TmuxpException ,
275
+ message = "Session not found: nonexistent_session" ,
276
+ ),
277
+ CLIShellTargetMissingFixture (
278
+ test_id = "nonexistent_window" ,
279
+ cli_cmd = ["shell" ],
280
+ cli_args = [
281
+ "-L{SOCKET_NAME}" ,
282
+ "{SESSION_NAME}" ,
283
+ "nonexistent_window" ,
284
+ "-c" ,
285
+ "print(str(server.socket_name))" ,
286
+ ],
287
+ inputs = [],
288
+ env = {},
289
+ template_ctx = {"window_name" : "nonexistent_window" },
290
+ exception = exc .TmuxpException ,
291
+ message = "Window not found: {WINDOW_NAME}" ,
292
+ ),
293
+ # Shell with --pdb
294
+ CLIShellTargetMissingFixture (
295
+ test_id = "nonexistent_socket_pdb" ,
296
+ cli_cmd = ["shell" , "--pdb" ],
297
+ cli_args = ["-LDoesNotExist" , "-c" , "print(str(server.socket_name))" ],
298
+ inputs = [],
299
+ env = {},
300
+ template_ctx = {},
301
+ exception = subprocess .CalledProcessError ,
302
+ message = r".*DoesNotExist.*" ,
303
+ ),
304
+ CLIShellTargetMissingFixture (
305
+ test_id = "nonexistent_session_pdb" ,
306
+ cli_cmd = ["shell" , "--pdb" ],
307
+ cli_args = [
308
+ "-L{SOCKET_NAME}" ,
309
+ "nonexistent_session" ,
310
+ "-c" ,
311
+ "print(str(server.socket_name))" ,
312
+ ],
313
+ inputs = [],
314
+ env = {},
315
+ template_ctx = {"session_name" : "nonexistent_session" },
316
+ exception = exc .TmuxpException ,
317
+ message = "Session not found: nonexistent_session" ,
318
+ ),
319
+ CLIShellTargetMissingFixture (
320
+ test_id = "nonexistent_window_pdb" ,
321
+ cli_cmd = ["shell" , "--pdb" ],
322
+ cli_args = [
323
+ "-L{SOCKET_NAME}" ,
324
+ "{SESSION_NAME}" ,
325
+ "nonexistent_window" ,
326
+ "-c" ,
327
+ "print(str(server.socket_name))" ,
328
+ ],
329
+ inputs = [],
330
+ env = {},
331
+ template_ctx = {"window_name" : "nonexistent_window" },
332
+ exception = exc .TmuxpException ,
333
+ message = "Window not found: {WINDOW_NAME}" ,
334
+ ),
335
+ ]
336
+
337
+
215
338
@pytest .mark .parametrize (
216
339
list (CLIShellTargetMissingFixture ._fields ),
217
340
TEST_SHELL_TARGET_MISSING_FIXTURES ,
218
341
ids = [test .test_id for test in TEST_SHELL_TARGET_MISSING_FIXTURES ],
219
342
)
220
343
def test_shell_target_missing (
221
- cli_cmd : list [str ],
222
344
test_id : str ,
345
+ cli_cmd : list [str ],
223
346
cli_args : list [str ],
224
347
inputs : list [t .Any ],
225
348
env : dict [t .Any , t .Any ],
226
349
template_ctx : dict [str , str ],
227
350
exception : type [exc .TmuxpException | subprocess .CalledProcessError ],
228
351
message : str ,
229
- socket_name : str ,
230
352
server : Server ,
231
353
session : Session ,
232
354
tmp_path : pathlib .Path ,
@@ -269,6 +391,7 @@ class CLIShellInteractiveFixture(t.NamedTuple):
269
391
"""Test fixture for tmuxp shell interactive tests."""
270
392
271
393
test_id : str
394
+ cli_cmd : list [str ]
272
395
cli_args : list [str ]
273
396
inputs : list [t .Any ]
274
397
env : dict [str , str ]
@@ -278,6 +401,7 @@ class CLIShellInteractiveFixture(t.NamedTuple):
278
401
TEST_SHELL_INTERACTIVE_FIXTURES : list [CLIShellInteractiveFixture ] = [
279
402
CLIShellInteractiveFixture (
280
403
test_id = "basic_interactive" ,
404
+ cli_cmd = ["shell" , "--code" ],
281
405
cli_args = [
282
406
"-L{SOCKET_NAME}" ,
283
407
],
@@ -287,6 +411,7 @@ class CLIShellInteractiveFixture(t.NamedTuple):
287
411
),
288
412
CLIShellInteractiveFixture (
289
413
test_id = "interactive_with_pane_id" ,
414
+ cli_cmd = ["shell" , "--code" ],
290
415
cli_args = [
291
416
"-L{SOCKET_NAME}" ,
292
417
],
@@ -297,20 +422,14 @@ class CLIShellInteractiveFixture(t.NamedTuple):
297
422
]
298
423
299
424
300
- @pytest .mark .parametrize (
301
- "cli_cmd" ,
302
- [
303
- ["shell" , "--code" ],
304
- ],
305
- )
306
425
@pytest .mark .parametrize (
307
426
list (CLIShellInteractiveFixture ._fields ),
308
427
TEST_SHELL_INTERACTIVE_FIXTURES ,
309
428
ids = [test .test_id for test in TEST_SHELL_INTERACTIVE_FIXTURES ],
310
429
)
311
430
def test_shell_interactive (
312
- cli_cmd : list [str ],
313
431
test_id : str ,
432
+ cli_cmd : list [str ],
314
433
cli_args : list [str ],
315
434
inputs : list [t .Any ],
316
435
env : dict [str , str ],
0 commit comments