Skip to content

Commit 1fbdc82

Browse files
Fix AttributeError in docstring meta init and improve test isolation across shell tests (#43)
* Initial plan * Fix AttributeError in docstring meta and improve test isolation in shell tests Agent-Logs-Url: https://github.com/NetApp/recline/sessions/f54164fb-39cc-4b8c-bfa9-2cc5f0d302cb Co-authored-by: RobertBlackhart <5414318+RobertBlackhart@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: RobertBlackhart <5414318+RobertBlackhart@users.noreply.github.com>
1 parent 1fc5e13 commit 1fbdc82

2 files changed

Lines changed: 32 additions & 15 deletions

File tree

tests/test_commands/test_man_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ def test_generate_help_text(command_name, args, kwargs, short_doc, long_doc, exa
9090
Parameter(arg, Parameter.KEYWORD_ONLY, default=val)
9191
for arg, val in kwargs.items()
9292
]
93+
command_class.docstring.meta = []
9394
if args or kwargs:
94-
command_class.docstring.meta = [DocstringMeta(["arg"], "")]
95+
command_class.docstring.meta.append(DocstringMeta(["arg"], ""))
9596
for label, description in examples.items():
9697
command_class.docstring.meta.append(
9798
DocstringMeta(["examples", label], description)

tests/test_repl/test_shell.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,47 +108,58 @@ def mock_eof(prompt):
108108
def 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

118129
def 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

130141
def 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

142153
def 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

Comments
 (0)