@@ -108,47 +108,58 @@ def mock_eof(prompt):
108108def test_run_with_dash_c ():
109109 """Verify only a single command is run when -c is passed in"""
110110
111- @recline .command (name = "single command" )
112- def single_command ():
111+ command_name = "single command dash c"
112+ preexisting = command_name in recline .commands .COMMAND_REGISTRY
113+
114+ @recline .command (name = command_name )
115+ def single_cmd ():
113116 return 73
114117
115- assert shell .relax (argv = ["ut_program" , "-c" , "single" , "command" ]) == 73
118+ try :
119+ assert shell .relax (argv = ["ut_program" , "-c" , "single" , "command" , "dash" , "c" ]) == 73
120+ assert command_name in recline .commands .COMMAND_REGISTRY
121+ finally :
122+ if not preexisting :
123+ recline .commands .COMMAND_REGISTRY .pop (command_name , None )
124+
125+ if not preexisting :
126+ assert command_name not in recline .commands .COMMAND_REGISTRY
116127
117128
118129def test_run_non_repl ():
119130 """Verify that if a program is not trying to be a repl, then we will parse
120131 a command from the input and exit
121132 """
122133
123- @recline .command (name = "single command" )
124- def single_command ():
134+ @recline .command (name = "single command non repl " )
135+ def single_cmd ():
125136 return 73
126137
127- assert shell .relax (argv = ["ut_program" , "single" , "command" ], repl_mode = False ) == 73
138+ assert shell .relax (argv = ["ut_program" , "single" , "command" , "non" , "repl" ], repl_mode = False ) == 73
128139
129140
130141def test_run_single_command ():
131142 """Verify that if a program is not trying to be a repl, then we will parse
132143 a command from the input and exit
133144 """
134145
135- @recline .command (name = "single command" )
136- def single_command ():
146+ @recline .command (name = "single command one shot " )
147+ def single_cmd ():
137148 return 73
138149
139- assert shell .relax (argv = ["ut_program" ], single_command = "single command" ) == 73
150+ assert shell .relax (argv = ["ut_program" ], single_command = "single command one shot " ) == 73
140151
141152
142153def test_relax_uses_sys_argv_when_none (monkeypatch ):
143154 """Verify that relax() uses sys.argv when no argv is provided (covers the argv=None branch)."""
144155
145156 import sys
146157
147- @recline .command (name = "single command" )
148- def single_command ():
158+ @recline .command (name = "single command sys argv " )
159+ def single_cmd ():
149160 return 45
150161
151- monkeypatch .setattr (sys , "argv" , ["ut_program" , "-c" , "single" , "command" ])
162+ monkeypatch .setattr (sys , "argv" , ["ut_program" , "-c" , "single" , "command" , "sys" , "argv" ])
152163 result = shell .relax ()
153164 assert result == 45
154165
@@ -235,9 +246,12 @@ def mock_input(prompt):
235246 def mock_execute (cmd ):
236247 raise bc .DebugInterrupt ()
237248
249+ def mock_debug ():
250+ debug_called [0 ] = True
251+
238252 monkeypatch .setattr (builtins , "input" , mock_input )
239253 monkeypatch .setattr (shell , "execute" , mock_execute )
240- monkeypatch .setattr (bc , "debug" , lambda : debug_called . __setitem__ ( 0 , True ) )
254+ monkeypatch .setattr (bc , "debug" , mock_debug )
241255
242256 with pytest .raises (SystemExit ):
243257 shell .relax (argv = ["ut_program" ])
@@ -354,7 +368,9 @@ def test_run_one_command_command_cancelled(monkeypatch):
354368 from recline .commands .async_command import CommandCancelled
355369 from recline .commands .cli_command import CLICommand
356370
357- recline .commands .COMMAND_REGISTRY ["__cancel_test" ] = CLICommand (lambda : None , name = "__cancel_test" )
371+ monkeypatch .setitem (
372+ recline .commands .COMMAND_REGISTRY , "__cancel_test" , CLICommand (lambda : None , name = "__cancel_test" )
373+ )
358374
359375 def _raise_cancelled (cmd , args ):
360376 raise CommandCancelled (99 )
0 commit comments