@@ -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,83 @@ 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" ],
103
+ cli_args = [
104
+ "-L{SOCKET_NAME}" ,
105
+ "-c" ,
106
+ "print(pane.id)" ,
107
+ ],
108
+ inputs = [],
109
+ env = {"TMUX_PANE" : "{PANE_ID}" },
110
+ expected_output = "{PANE_ID}" ,
111
+ ),
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))" ],
117
+ inputs = [],
118
+ env = {},
119
+ expected_output = "{SERVER_SOCKET_NAME}" ,
120
+ ),
121
+ CLIShellFixture (
122
+ test_id = "print-session-name-pdb" ,
123
+ cli_cmd = ["shell" , "--pdb" ],
124
+ cli_args = [
125
+ "-L{SOCKET_NAME}" ,
126
+ "{SESSION_NAME}" ,
127
+ "-c" ,
128
+ "print(session.name)" ,
129
+ ],
130
+ inputs = [],
131
+ env = {},
132
+ expected_output = "{SESSION_NAME}" ,
133
+ ),
134
+ CLIShellFixture (
135
+ test_id = "print-has-session-pdb" ,
136
+ cli_cmd = ["shell" , "--pdb" ],
137
+ cli_args = [
138
+ "-L{SOCKET_NAME}" ,
139
+ "{SESSION_NAME}" ,
140
+ "{WINDOW_NAME}" ,
141
+ "-c" ,
142
+ "print(server.has_session(session.name))" ,
143
+ ],
144
+ inputs = [],
145
+ env = {},
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" ],
95
179
cli_args = [
96
180
"-L{SOCKET_NAME}" ,
97
181
"-c" ,
@@ -108,6 +192,7 @@ class CLIShellTargetMissingFixture(t.NamedTuple):
108
192
"""Test fixture for tmuxp shell target missing tests."""
109
193
110
194
test_id : str
195
+ cli_cmd : list [str ]
111
196
cli_args : list [str ]
112
197
inputs : list [t .Any ]
113
198
env : dict [t .Any , t .Any ]
@@ -117,8 +202,10 @@ class CLIShellTargetMissingFixture(t.NamedTuple):
117
202
118
203
119
204
TEST_SHELL_TARGET_MISSING_FIXTURES : list [CLIShellTargetMissingFixture ] = [
205
+ # Regular shell command
120
206
CLIShellTargetMissingFixture (
121
207
test_id = "nonexistent_socket" ,
208
+ cli_cmd = ["shell" ],
122
209
cli_args = ["-LDoesNotExist" , "-c" , "print(str(server.socket_name))" ],
123
210
inputs = [],
124
211
env = {},
@@ -128,6 +215,7 @@ class CLIShellTargetMissingFixture(t.NamedTuple):
128
215
),
129
216
CLIShellTargetMissingFixture (
130
217
test_id = "nonexistent_session" ,
218
+ cli_cmd = ["shell" ],
131
219
cli_args = [
132
220
"-L{SOCKET_NAME}" ,
133
221
"nonexistent_session" ,
@@ -142,6 +230,49 @@ class CLIShellTargetMissingFixture(t.NamedTuple):
142
230
),
143
231
CLIShellTargetMissingFixture (
144
232
test_id = "nonexistent_window" ,
233
+ cli_cmd = ["shell" ],
234
+ cli_args = [
235
+ "-L{SOCKET_NAME}" ,
236
+ "{SESSION_NAME}" ,
237
+ "nonexistent_window" ,
238
+ "-c" ,
239
+ "print(str(server.socket_name))" ,
240
+ ],
241
+ inputs = [],
242
+ env = {},
243
+ template_ctx = {"window_name" : "nonexistent_window" },
244
+ exception = exc .TmuxpException ,
245
+ message = "Window not found: {WINDOW_NAME}" ,
246
+ ),
247
+ # Shell with --pdb
248
+ CLIShellTargetMissingFixture (
249
+ test_id = "nonexistent_socket_pdb" ,
250
+ cli_cmd = ["shell" , "--pdb" ],
251
+ cli_args = ["-LDoesNotExist" , "-c" , "print(str(server.socket_name))" ],
252
+ inputs = [],
253
+ env = {},
254
+ template_ctx = {},
255
+ exception = subprocess .CalledProcessError ,
256
+ message = r".*DoesNotExist.*" ,
257
+ ),
258
+ CLIShellTargetMissingFixture (
259
+ test_id = "nonexistent_session_pdb" ,
260
+ cli_cmd = ["shell" , "--pdb" ],
261
+ cli_args = [
262
+ "-L{SOCKET_NAME}" ,
263
+ "nonexistent_session" ,
264
+ "-c" ,
265
+ "print(str(server.socket_name))" ,
266
+ ],
267
+ inputs = [],
268
+ env = {},
269
+ template_ctx = {"session_name" : "nonexistent_session" },
270
+ exception = exc .TmuxpException ,
271
+ message = "Session not found: nonexistent_session" ,
272
+ ),
273
+ CLIShellTargetMissingFixture (
274
+ test_id = "nonexistent_window_pdb" ,
275
+ cli_cmd = ["shell" , "--pdb" ],
145
276
cli_args = [
146
277
"-L{SOCKET_NAME}" ,
147
278
"{SESSION_NAME}" ,
@@ -158,15 +289,49 @@ class CLIShellTargetMissingFixture(t.NamedTuple):
158
289
]
159
290
160
291
161
- @pytest .mark .parametrize ("cli_cmd" , [["shell" ], ["shell" , "--pdb" ]])
292
+ class CLIShellInteractiveFixture (t .NamedTuple ):
293
+ """Test fixture for tmuxp shell interactive tests."""
294
+
295
+ test_id : str
296
+ cli_cmd : list [str ]
297
+ cli_args : list [str ]
298
+ inputs : list [t .Any ]
299
+ env : dict [str , str ]
300
+ message : str
301
+
302
+
303
+ TEST_SHELL_INTERACTIVE_FIXTURES : list [CLIShellInteractiveFixture ] = [
304
+ CLIShellInteractiveFixture (
305
+ test_id = "basic_interactive" ,
306
+ cli_cmd = ["shell" , "--code" ],
307
+ cli_args = [
308
+ "-L{SOCKET_NAME}" ,
309
+ ],
310
+ inputs = [],
311
+ env = {},
312
+ message = "(InteractiveConsole)" ,
313
+ ),
314
+ CLIShellInteractiveFixture (
315
+ test_id = "interactive_with_pane_id" ,
316
+ cli_cmd = ["shell" , "--code" ],
317
+ cli_args = [
318
+ "-L{SOCKET_NAME}" ,
319
+ ],
320
+ inputs = [],
321
+ env = {"PANE_ID" : "{PANE_ID}" },
322
+ message = "(InteractiveConsole)" ,
323
+ ),
324
+ ]
325
+
326
+
162
327
@pytest .mark .parametrize (
163
328
list (CLIShellFixture ._fields ),
164
329
TEST_SHELL_FIXTURES ,
165
330
ids = [test .test_id for test in TEST_SHELL_FIXTURES ],
166
331
)
167
332
def test_shell (
168
- cli_cmd : list [str ],
169
333
test_id : str ,
334
+ cli_cmd : list [str ],
170
335
cli_args : list [str ],
171
336
inputs : list [t .Any ],
172
337
env : dict [str , str ],
@@ -205,28 +370,20 @@ def test_shell(
205
370
assert expected_output .format (** template_ctx ) in result .out
206
371
207
372
208
- @pytest .mark .parametrize (
209
- "cli_cmd" ,
210
- [
211
- ["shell" ],
212
- ["shell" , "--pdb" ],
213
- ],
214
- )
215
373
@pytest .mark .parametrize (
216
374
list (CLIShellTargetMissingFixture ._fields ),
217
375
TEST_SHELL_TARGET_MISSING_FIXTURES ,
218
376
ids = [test .test_id for test in TEST_SHELL_TARGET_MISSING_FIXTURES ],
219
377
)
220
378
def test_shell_target_missing (
221
- cli_cmd : list [str ],
222
379
test_id : str ,
380
+ cli_cmd : list [str ],
223
381
cli_args : list [str ],
224
382
inputs : list [t .Any ],
225
383
env : dict [t .Any , t .Any ],
226
384
template_ctx : dict [str , str ],
227
385
exception : type [exc .TmuxpException | subprocess .CalledProcessError ],
228
386
message : str ,
229
- socket_name : str ,
230
387
server : Server ,
231
388
session : Session ,
232
389
tmp_path : pathlib .Path ,
@@ -265,52 +422,14 @@ def test_shell_target_missing(
265
422
assert message .format (** template_ctx ) in result .out
266
423
267
424
268
- class CLIShellInteractiveFixture (t .NamedTuple ):
269
- """Test fixture for tmuxp shell interactive tests."""
270
-
271
- test_id : str
272
- cli_args : list [str ]
273
- inputs : list [t .Any ]
274
- env : dict [str , str ]
275
- message : str
276
-
277
-
278
- TEST_SHELL_INTERACTIVE_FIXTURES : list [CLIShellInteractiveFixture ] = [
279
- CLIShellInteractiveFixture (
280
- test_id = "basic_interactive" ,
281
- cli_args = [
282
- "-L{SOCKET_NAME}" ,
283
- ],
284
- inputs = [],
285
- env = {},
286
- message = "(InteractiveConsole)" ,
287
- ),
288
- CLIShellInteractiveFixture (
289
- test_id = "interactive_with_pane_id" ,
290
- cli_args = [
291
- "-L{SOCKET_NAME}" ,
292
- ],
293
- inputs = [],
294
- env = {"PANE_ID" : "{PANE_ID}" },
295
- message = "(InteractiveConsole)" ,
296
- ),
297
- ]
298
-
299
-
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