Skip to content

Commit 2dd2677

Browse files
committed
Try to start fixing some tests
1 parent 3614096 commit 2dd2677

File tree

3 files changed

+47
-46
lines changed

3 files changed

+47
-46
lines changed

tests/test_argparse.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,9 @@ def base_helpless(self, args):
293293
# This subcommand has aliases and no help text. It exists to prevent changes to _set_parser_prog() which
294294
# use an approach which relies on action._choices_actions list. See comment in that function for more
295295
# details.
296-
parser_bar = base_subparsers.add_parser('helpless', aliases=['helpless_1', 'helpless_2'])
297-
parser_bar.add_argument('z', help='string')
298-
parser_bar.set_defaults(func=base_bar)
296+
parser_helplesss = base_subparsers.add_parser('helpless', aliases=['helpless_1', 'helpless_2'])
297+
parser_helplesss.add_argument('z', help='string')
298+
parser_helplesss.set_defaults(func=base_helpless)
299299

300300
@cmd2.with_argparser(base_parser)
301301
def do_base(self, args):
@@ -414,7 +414,7 @@ def test_subcmd_decorator(subcommand_app):
414414

415415
# Test subcommand that has no help option
416416
out, err = run_cmd(subcommand_app, 'test_subcmd_decorator helpless_subcmd')
417-
assert "'subcommand': 'helpless_subcmd'" in out[0]
417+
assert out[0].startswith('{')
418418

419419
out, err = run_cmd(subcommand_app, 'help test_subcmd_decorator helpless_subcmd')
420420
assert out[0] == 'Usage: test_subcmd_decorator helpless_subcmd'

tests/test_cmd2.py

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
constants,
2828
exceptions,
2929
plugin,
30+
rich_utils,
3031
utils,
3132
)
3233
from cmd2.rl_utils import (
@@ -51,12 +52,12 @@ def arg_decorator(func):
5152

5253
@functools.wraps(func)
5354
def cmd_wrapper(*args, **kwargs):
54-
old = ansi.allow_style
55-
ansi.allow_style = style
55+
old = rich_utils.allow_style
56+
rich_utils.allow_style = style
5657
try:
5758
retval = func(*args, **kwargs)
5859
finally:
59-
ansi.allow_style = old
60+
rich_utils.allow_style = old
6061
return retval
6162

6263
return cmd_wrapper
@@ -225,31 +226,31 @@ def test_set_no_settables(base_app):
225226
@pytest.mark.parametrize(
226227
'new_val, is_valid, expected',
227228
[
228-
(ansi.AllowStyle.NEVER, True, ansi.AllowStyle.NEVER),
229-
('neVeR', True, ansi.AllowStyle.NEVER),
230-
(ansi.AllowStyle.TERMINAL, True, ansi.AllowStyle.TERMINAL),
231-
('TeRMInal', True, ansi.AllowStyle.TERMINAL),
232-
(ansi.AllowStyle.ALWAYS, True, ansi.AllowStyle.ALWAYS),
233-
('AlWaYs', True, ansi.AllowStyle.ALWAYS),
234-
('invalid', False, ansi.AllowStyle.TERMINAL),
229+
(rich_utils.AllowStyle.NEVER, True, rich_utils.AllowStyle.NEVER),
230+
('neVeR', True, rich_utils.AllowStyle.NEVER),
231+
(rich_utils.AllowStyle.TERMINAL, True, rich_utils.AllowStyle.TERMINAL),
232+
('TeRMInal', True, rich_utils.AllowStyle.TERMINAL),
233+
(rich_utils.AllowStyle.ALWAYS, True, rich_utils.AllowStyle.ALWAYS),
234+
('AlWaYs', True, rich_utils.AllowStyle.ALWAYS),
235+
('invalid', False, rich_utils.AllowStyle.TERMINAL),
235236
],
236237
)
237238
def test_set_allow_style(base_app, new_val, is_valid, expected):
238239
# Initialize allow_style for this test
239-
ansi.allow_style = ansi.AllowStyle.TERMINAL
240+
rich_utils.allow_style = rich_utils.AllowStyle.TERMINAL
240241

241242
# Use the set command to alter it
242243
out, err = run_cmd(base_app, 'set allow_style {}'.format(new_val))
243244
assert base_app.last_result is is_valid
244245

245246
# Verify the results
246-
assert ansi.allow_style == expected
247+
assert rich_utils.allow_style == expected
247248
if is_valid:
248249
assert not err
249250
assert out
250251

251252
# Reset allow_style to its default since it's an application-wide setting that can affect other unit tests
252-
ansi.allow_style = ansi.AllowStyle.TERMINAL
253+
rich_utils.allow_style = rich_utils.AllowStyle.TERMINAL
253254

254255

255256
def test_set_with_choices(base_app):
@@ -1163,8 +1164,8 @@ def test_escaping_prompt():
11631164
assert rl_escape_prompt(prompt) == prompt
11641165

11651166
# This prompt has color which needs to be escaped
1166-
color = ansi.Fg.CYAN
1167-
prompt = ansi.style('InColor', fg=color)
1167+
color = rich_utils.Fg.CYAN
1168+
prompt = rich_utils.style('InColor', fg=color)
11681169

11691170
escape_start = "\x01"
11701171
escape_end = "\x02"
@@ -1175,7 +1176,7 @@ def test_escaping_prompt():
11751176
assert escaped_prompt == prompt
11761177
else:
11771178
assert escaped_prompt.startswith(escape_start + color + escape_end)
1178-
assert escaped_prompt.endswith(escape_start + ansi.Fg.RESET + escape_end)
1179+
assert escaped_prompt.endswith(escape_start + rich_utils.Fg.RESET + escape_end)
11791180

11801181
assert rl_unescape_prompt(escaped_prompt) == prompt
11811182

@@ -1989,21 +1990,21 @@ def test_poutput_none(outsim_app):
19891990
assert out == expected
19901991

19911992

1992-
@with_ansi_style(ansi.AllowStyle.ALWAYS)
1993+
@with_ansi_style(rich_utils.AllowStyle.ALWAYS)
19931994
def test_poutput_ansi_always(outsim_app):
19941995
msg = 'Hello World'
1995-
colored_msg = ansi.style(msg, fg=ansi.Fg.CYAN)
1996+
colored_msg = rich_utils.style(msg, fg=rich_utils.Fg.CYAN)
19961997
outsim_app.poutput(colored_msg)
19971998
out = outsim_app.stdout.getvalue()
19981999
expected = colored_msg + '\n'
19992000
assert colored_msg != msg
20002001
assert out == expected
20012002

20022003

2003-
@with_ansi_style(ansi.AllowStyle.NEVER)
2004+
@with_ansi_style(rich_utils.AllowStyle.NEVER)
20042005
def test_poutput_ansi_never(outsim_app):
20052006
msg = 'Hello World'
2006-
colored_msg = ansi.style(msg, fg=ansi.Fg.CYAN)
2007+
colored_msg = rich_utils.style(msg, fg=rich_utils.Fg.CYAN)
20072008
outsim_app.poutput(colored_msg)
20082009
out = outsim_app.stdout.getvalue()
20092010
expected = msg + '\n'
@@ -2183,16 +2184,16 @@ def test_multiple_aliases(base_app):
21832184
verify_help_text(base_app, out)
21842185

21852186

2186-
@with_ansi_style(ansi.AllowStyle.ALWAYS)
2187+
@with_ansi_style(rich_utils.AllowStyle.ALWAYS)
21872188
def test_perror_style(base_app, capsys):
21882189
msg = 'testing...'
21892190
end = '\n'
21902191
base_app.perror(msg)
21912192
out, err = capsys.readouterr()
2192-
assert err == ansi.style_error(msg) + end
2193+
assert err == rich_utils.style_error(msg) + end
21932194

21942195

2195-
@with_ansi_style(ansi.AllowStyle.ALWAYS)
2196+
@with_ansi_style(rich_utils.AllowStyle.ALWAYS)
21962197
def test_perror_no_style(base_app, capsys):
21972198
msg = 'testing...'
21982199
end = '\n'
@@ -2201,16 +2202,16 @@ def test_perror_no_style(base_app, capsys):
22012202
assert err == msg + end
22022203

22032204

2204-
@with_ansi_style(ansi.AllowStyle.ALWAYS)
2205+
@with_ansi_style(rich_utils.AllowStyle.ALWAYS)
22052206
def test_pexcept_style(base_app, capsys):
22062207
msg = Exception('testing...')
22072208

22082209
base_app.pexcept(msg)
22092210
out, err = capsys.readouterr()
2210-
assert err.startswith(ansi.style_error("EXCEPTION of type 'Exception' occurred with message: testing..."))
2211+
assert err.startswith(rich_utils.style_error("EXCEPTION of type 'Exception' occurred with message: testing..."))
22112212

22122213

2213-
@with_ansi_style(ansi.AllowStyle.ALWAYS)
2214+
@with_ansi_style(rich_utils.AllowStyle.ALWAYS)
22142215
def test_pexcept_no_style(base_app, capsys):
22152216
msg = Exception('testing...')
22162217

@@ -2219,14 +2220,14 @@ def test_pexcept_no_style(base_app, capsys):
22192220
assert err.startswith("EXCEPTION of type 'Exception' occurred with message: testing...")
22202221

22212222

2222-
@with_ansi_style(ansi.AllowStyle.ALWAYS)
2223+
@with_ansi_style(rich_utils.AllowStyle.ALWAYS)
22232224
def test_pexcept_not_exception(base_app, capsys):
22242225
# Pass in a msg that is not an Exception object
22252226
msg = False
22262227

22272228
base_app.pexcept(msg)
22282229
out, err = capsys.readouterr()
2229-
assert err.startswith(ansi.style_error(msg))
2230+
assert err.startswith(rich_utils.style_error(msg))
22302231

22312232

22322233
def test_ppaged(outsim_app):
@@ -2237,22 +2238,22 @@ def test_ppaged(outsim_app):
22372238
assert out == msg + end
22382239

22392240

2240-
@with_ansi_style(ansi.AllowStyle.TERMINAL)
2241+
@with_ansi_style(rich_utils.AllowStyle.TERMINAL)
22412242
def test_ppaged_strips_ansi_when_redirecting(outsim_app):
22422243
msg = 'testing...'
22432244
end = '\n'
22442245
outsim_app._redirecting = True
2245-
outsim_app.ppaged(ansi.style(msg, fg=ansi.Fg.RED))
2246+
outsim_app.ppaged(rich_utils.style(msg, fg=rich_utils.Fg.RED))
22462247
out = outsim_app.stdout.getvalue()
22472248
assert out == msg + end
22482249

22492250

2250-
@with_ansi_style(ansi.AllowStyle.ALWAYS)
2251+
@with_ansi_style(rich_utils.AllowStyle.ALWAYS)
22512252
def test_ppaged_strips_ansi_when_redirecting_if_always(outsim_app):
22522253
msg = 'testing...'
22532254
end = '\n'
22542255
outsim_app._redirecting = True
2255-
colored_msg = ansi.style(msg, fg=ansi.Fg.RED)
2256+
colored_msg = rich_utils.style(msg, fg=rich_utils.Fg.RED)
22562257
outsim_app.ppaged(colored_msg)
22572258
out = outsim_app.stdout.getvalue()
22582259
assert out == colored_msg + end
@@ -2435,12 +2436,12 @@ def do_echo(self, args):
24352436
self.perror(args)
24362437

24372438
def do_echo_error(self, args):
2438-
self.poutput(ansi.style(args, fg=ansi.Fg.RED))
2439+
self.poutput(rich_utils.style(args, fg=rich_utils.Fg.RED))
24392440
# perror uses colors by default
24402441
self.perror(args)
24412442

24422443

2443-
@with_ansi_style(ansi.AllowStyle.ALWAYS)
2444+
@with_ansi_style(rich_utils.AllowStyle.ALWAYS)
24442445
def test_ansi_pouterr_always_tty(mocker, capsys):
24452446
app = AnsiApp()
24462447
mocker.patch.object(app.stdout, 'isatty', return_value=True)
@@ -2463,7 +2464,7 @@ def test_ansi_pouterr_always_tty(mocker, capsys):
24632464
assert 'oopsie' in err
24642465

24652466

2466-
@with_ansi_style(ansi.AllowStyle.ALWAYS)
2467+
@with_ansi_style(rich_utils.AllowStyle.ALWAYS)
24672468
def test_ansi_pouterr_always_notty(mocker, capsys):
24682469
app = AnsiApp()
24692470
mocker.patch.object(app.stdout, 'isatty', return_value=False)
@@ -2486,7 +2487,7 @@ def test_ansi_pouterr_always_notty(mocker, capsys):
24862487
assert 'oopsie' in err
24872488

24882489

2489-
@with_ansi_style(ansi.AllowStyle.TERMINAL)
2490+
@with_ansi_style(rich_utils.AllowStyle.TERMINAL)
24902491
def test_ansi_terminal_tty(mocker, capsys):
24912492
app = AnsiApp()
24922493
mocker.patch.object(app.stdout, 'isatty', return_value=True)
@@ -2508,7 +2509,7 @@ def test_ansi_terminal_tty(mocker, capsys):
25082509
assert 'oopsie' in err
25092510

25102511

2511-
@with_ansi_style(ansi.AllowStyle.TERMINAL)
2512+
@with_ansi_style(rich_utils.AllowStyle.TERMINAL)
25122513
def test_ansi_terminal_notty(mocker, capsys):
25132514
app = AnsiApp()
25142515
mocker.patch.object(app.stdout, 'isatty', return_value=False)
@@ -2523,7 +2524,7 @@ def test_ansi_terminal_notty(mocker, capsys):
25232524
assert out == err == 'oopsie\n'
25242525

25252526

2526-
@with_ansi_style(ansi.AllowStyle.NEVER)
2527+
@with_ansi_style(rich_utils.AllowStyle.NEVER)
25272528
def test_ansi_never_tty(mocker, capsys):
25282529
app = AnsiApp()
25292530
mocker.patch.object(app.stdout, 'isatty', return_value=True)
@@ -2538,7 +2539,7 @@ def test_ansi_never_tty(mocker, capsys):
25382539
assert out == err == 'oopsie\n'
25392540

25402541

2541-
@with_ansi_style(ansi.AllowStyle.NEVER)
2542+
@with_ansi_style(rich_utils.AllowStyle.NEVER)
25422543
def test_ansi_never_notty(mocker, capsys):
25432544
app = AnsiApp()
25442545
mocker.patch.object(app.stdout, 'isatty', return_value=False)

tests_isolated/test_commandset/test_argparse_subcommands.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ def base_helpless(self, args):
5252
# This subcommand has aliases and no help text. It exists to prevent changes to _set_parser_prog() which
5353
# use an approach which relies on action._choices_actions list. See comment in that function for more
5454
# details.
55-
parser_bar = base_subparsers.add_parser('helpless', aliases=['helpless_1', 'helpless_2'])
56-
parser_bar.add_argument('z', help='string')
57-
parser_bar.set_defaults(func=base_bar)
55+
parser_helpless = base_subparsers.add_parser('helpless', aliases=['helpless_1', 'helpless_2'])
56+
parser_helpless.add_argument('z', help='string')
57+
parser_helpless.set_defaults(func=base_helpless)
5858

5959
@cmd2.with_argparser(base_parser)
6060
def do_base(self, args):

0 commit comments

Comments
 (0)