@@ -25,22 +25,26 @@ class CLIShellFixture(t.NamedTuple):
2525 test_id : str
2626
2727 # test params
28+ cli_cmd : list [str ]
2829 cli_args : list [str ]
2930 inputs : list [t .Any ]
3031 env : dict [str , str ]
3132 expected_output : str
3233
3334
3435TEST_SHELL_FIXTURES : list [CLIShellFixture ] = [
36+ # Regular shell command
3537 CLIShellFixture (
3638 test_id = "print-socket-name" ,
39+ cli_cmd = ["shell" ],
3740 cli_args = ["-L{SOCKET_NAME}" , "-c" , "print(str(server.socket_name))" ],
3841 inputs = [],
3942 env = {},
4043 expected_output = "{SERVER_SOCKET_NAME}" ,
4144 ),
4245 CLIShellFixture (
4346 test_id = "print-session-name" ,
47+ cli_cmd = ["shell" ],
4448 cli_args = [
4549 "-L{SOCKET_NAME}" ,
4650 "{SESSION_NAME}" ,
@@ -53,6 +57,7 @@ class CLIShellFixture(t.NamedTuple):
5357 ),
5458 CLIShellFixture (
5559 test_id = "print-has-session" ,
60+ cli_cmd = ["shell" ],
5661 cli_args = [
5762 "-L{SOCKET_NAME}" ,
5863 "{SESSION_NAME}" ,
@@ -66,6 +71,7 @@ class CLIShellFixture(t.NamedTuple):
6671 ),
6772 CLIShellFixture (
6873 test_id = "print-window-name" ,
74+ cli_cmd = ["shell" ],
6975 cli_args = [
7076 "-L{SOCKET_NAME}" ,
7177 "{SESSION_NAME}" ,
@@ -79,6 +85,7 @@ class CLIShellFixture(t.NamedTuple):
7985 ),
8086 CLIShellFixture (
8187 test_id = "print-pane-id" ,
88+ cli_cmd = ["shell" ],
8289 cli_args = [
8390 "-L{SOCKET_NAME}" ,
8491 "{SESSION_NAME}" ,
@@ -92,6 +99,7 @@ class CLIShellFixture(t.NamedTuple):
9299 ),
93100 CLIShellFixture (
94101 test_id = "print-pane-id-obeys-tmux-pane-env-var" ,
102+ cli_cmd = ["shell" ],
95103 cli_args = [
96104 "-L{SOCKET_NAME}" ,
97105 "-c" ,
@@ -101,72 +109,93 @@ class CLIShellFixture(t.NamedTuple):
101109 env = {"TMUX_PANE" : "{PANE_ID}" },
102110 expected_output = "{PANE_ID}" ,
103111 ),
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))" ],
123117 inputs = [],
124118 env = {},
125- template_ctx = {},
126- exception = subprocess .CalledProcessError ,
127- message = r".*DoesNotExist.*" ,
119+ expected_output = "{SERVER_SOCKET_NAME}" ,
128120 ),
129- CLIShellTargetMissingFixture (
130- test_id = "nonexistent_session" ,
121+ CLIShellFixture (
122+ test_id = "print-session-name-pdb" ,
123+ cli_cmd = ["shell" , "--pdb" ],
131124 cli_args = [
132125 "-L{SOCKET_NAME}" ,
133- "nonexistent_session " ,
126+ "{SESSION_NAME} " ,
134127 "-c" ,
135- "print(str(server.socket_name) )" ,
128+ "print(session.name )" ,
136129 ],
137130 inputs = [],
138131 env = {},
139- template_ctx = {"session_name" : "nonexistent_session" },
140- exception = exc .TmuxpException ,
141- message = "Session not found: nonexistent_session" ,
132+ expected_output = "{SESSION_NAME}" ,
142133 ),
143- CLIShellTargetMissingFixture (
144- test_id = "nonexistent_window" ,
134+ CLIShellFixture (
135+ test_id = "print-has-session-pdb" ,
136+ cli_cmd = ["shell" , "--pdb" ],
145137 cli_args = [
146138 "-L{SOCKET_NAME}" ,
147139 "{SESSION_NAME}" ,
148- "nonexistent_window " ,
140+ "{WINDOW_NAME} " ,
149141 "-c" ,
150- "print(str( server.socket_name ))" ,
142+ "print(server.has_session(session.name ))" ,
151143 ],
152144 inputs = [],
153145 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}" ,
157187 ),
158188]
159189
160190
161- @pytest .mark .parametrize ("cli_cmd" , [["shell" ], ["shell" , "--pdb" ]])
162191@pytest .mark .parametrize (
163192 list (CLIShellFixture ._fields ),
164193 TEST_SHELL_FIXTURES ,
165194 ids = [test .test_id for test in TEST_SHELL_FIXTURES ],
166195)
167196def test_shell (
168- cli_cmd : list [str ],
169197 test_id : str ,
198+ cli_cmd : list [str ],
170199 cli_args : list [str ],
171200 inputs : list [t .Any ],
172201 env : dict [str , str ],
@@ -205,28 +234,121 @@ def test_shell(
205234 assert expected_output .format (** template_ctx ) in result .out
206235
207236
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+
215338@pytest .mark .parametrize (
216339 list (CLIShellTargetMissingFixture ._fields ),
217340 TEST_SHELL_TARGET_MISSING_FIXTURES ,
218341 ids = [test .test_id for test in TEST_SHELL_TARGET_MISSING_FIXTURES ],
219342)
220343def test_shell_target_missing (
221- cli_cmd : list [str ],
222344 test_id : str ,
345+ cli_cmd : list [str ],
223346 cli_args : list [str ],
224347 inputs : list [t .Any ],
225348 env : dict [t .Any , t .Any ],
226349 template_ctx : dict [str , str ],
227350 exception : type [exc .TmuxpException | subprocess .CalledProcessError ],
228351 message : str ,
229- socket_name : str ,
230352 server : Server ,
231353 session : Session ,
232354 tmp_path : pathlib .Path ,
@@ -269,6 +391,7 @@ class CLIShellInteractiveFixture(t.NamedTuple):
269391 """Test fixture for tmuxp shell interactive tests."""
270392
271393 test_id : str
394+ cli_cmd : list [str ]
272395 cli_args : list [str ]
273396 inputs : list [t .Any ]
274397 env : dict [str , str ]
@@ -278,6 +401,7 @@ class CLIShellInteractiveFixture(t.NamedTuple):
278401TEST_SHELL_INTERACTIVE_FIXTURES : list [CLIShellInteractiveFixture ] = [
279402 CLIShellInteractiveFixture (
280403 test_id = "basic_interactive" ,
404+ cli_cmd = ["shell" , "--code" ],
281405 cli_args = [
282406 "-L{SOCKET_NAME}" ,
283407 ],
@@ -287,6 +411,7 @@ class CLIShellInteractiveFixture(t.NamedTuple):
287411 ),
288412 CLIShellInteractiveFixture (
289413 test_id = "interactive_with_pane_id" ,
414+ cli_cmd = ["shell" , "--code" ],
290415 cli_args = [
291416 "-L{SOCKET_NAME}" ,
292417 ],
@@ -297,20 +422,14 @@ class CLIShellInteractiveFixture(t.NamedTuple):
297422]
298423
299424
300- @pytest .mark .parametrize (
301- "cli_cmd" ,
302- [
303- ["shell" , "--code" ],
304- ],
305- )
306425@pytest .mark .parametrize (
307426 list (CLIShellInteractiveFixture ._fields ),
308427 TEST_SHELL_INTERACTIVE_FIXTURES ,
309428 ids = [test .test_id for test in TEST_SHELL_INTERACTIVE_FIXTURES ],
310429)
311430def test_shell_interactive (
312- cli_cmd : list [str ],
313431 test_id : str ,
432+ cli_cmd : list [str ],
314433 cli_args : list [str ],
315434 inputs : list [t .Any ],
316435 env : dict [str , str ],
0 commit comments