27
27
constants ,
28
28
exceptions ,
29
29
plugin ,
30
+ rich_utils ,
30
31
utils ,
31
32
)
32
33
from cmd2 .rl_utils import (
@@ -51,12 +52,12 @@ def arg_decorator(func):
51
52
52
53
@functools .wraps (func )
53
54
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
56
57
try :
57
58
retval = func (* args , ** kwargs )
58
59
finally :
59
- ansi .allow_style = old
60
+ rich_utils .allow_style = old
60
61
return retval
61
62
62
63
return cmd_wrapper
@@ -225,31 +226,31 @@ def test_set_no_settables(base_app):
225
226
@pytest .mark .parametrize (
226
227
'new_val, is_valid, expected' ,
227
228
[
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 ),
235
236
],
236
237
)
237
238
def test_set_allow_style (base_app , new_val , is_valid , expected ):
238
239
# Initialize allow_style for this test
239
- ansi .allow_style = ansi .AllowStyle .TERMINAL
240
+ rich_utils .allow_style = rich_utils .AllowStyle .TERMINAL
240
241
241
242
# Use the set command to alter it
242
243
out , err = run_cmd (base_app , 'set allow_style {}' .format (new_val ))
243
244
assert base_app .last_result is is_valid
244
245
245
246
# Verify the results
246
- assert ansi .allow_style == expected
247
+ assert rich_utils .allow_style == expected
247
248
if is_valid :
248
249
assert not err
249
250
assert out
250
251
251
252
# 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
253
254
254
255
255
256
def test_set_with_choices (base_app ):
@@ -1163,8 +1164,8 @@ def test_escaping_prompt():
1163
1164
assert rl_escape_prompt (prompt ) == prompt
1164
1165
1165
1166
# 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 )
1168
1169
1169
1170
escape_start = "\x01 "
1170
1171
escape_end = "\x02 "
@@ -1175,7 +1176,7 @@ def test_escaping_prompt():
1175
1176
assert escaped_prompt == prompt
1176
1177
else :
1177
1178
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 )
1179
1180
1180
1181
assert rl_unescape_prompt (escaped_prompt ) == prompt
1181
1182
@@ -1989,21 +1990,21 @@ def test_poutput_none(outsim_app):
1989
1990
assert out == expected
1990
1991
1991
1992
1992
- @with_ansi_style (ansi .AllowStyle .ALWAYS )
1993
+ @with_ansi_style (rich_utils .AllowStyle .ALWAYS )
1993
1994
def test_poutput_ansi_always (outsim_app ):
1994
1995
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 )
1996
1997
outsim_app .poutput (colored_msg )
1997
1998
out = outsim_app .stdout .getvalue ()
1998
1999
expected = colored_msg + '\n '
1999
2000
assert colored_msg != msg
2000
2001
assert out == expected
2001
2002
2002
2003
2003
- @with_ansi_style (ansi .AllowStyle .NEVER )
2004
+ @with_ansi_style (rich_utils .AllowStyle .NEVER )
2004
2005
def test_poutput_ansi_never (outsim_app ):
2005
2006
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 )
2007
2008
outsim_app .poutput (colored_msg )
2008
2009
out = outsim_app .stdout .getvalue ()
2009
2010
expected = msg + '\n '
@@ -2183,16 +2184,16 @@ def test_multiple_aliases(base_app):
2183
2184
verify_help_text (base_app , out )
2184
2185
2185
2186
2186
- @with_ansi_style (ansi .AllowStyle .ALWAYS )
2187
+ @with_ansi_style (rich_utils .AllowStyle .ALWAYS )
2187
2188
def test_perror_style (base_app , capsys ):
2188
2189
msg = 'testing...'
2189
2190
end = '\n '
2190
2191
base_app .perror (msg )
2191
2192
out , err = capsys .readouterr ()
2192
- assert err == ansi .style_error (msg ) + end
2193
+ assert err == rich_utils .style_error (msg ) + end
2193
2194
2194
2195
2195
- @with_ansi_style (ansi .AllowStyle .ALWAYS )
2196
+ @with_ansi_style (rich_utils .AllowStyle .ALWAYS )
2196
2197
def test_perror_no_style (base_app , capsys ):
2197
2198
msg = 'testing...'
2198
2199
end = '\n '
@@ -2201,16 +2202,16 @@ def test_perror_no_style(base_app, capsys):
2201
2202
assert err == msg + end
2202
2203
2203
2204
2204
- @with_ansi_style (ansi .AllowStyle .ALWAYS )
2205
+ @with_ansi_style (rich_utils .AllowStyle .ALWAYS )
2205
2206
def test_pexcept_style (base_app , capsys ):
2206
2207
msg = Exception ('testing...' )
2207
2208
2208
2209
base_app .pexcept (msg )
2209
2210
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..." ))
2211
2212
2212
2213
2213
- @with_ansi_style (ansi .AllowStyle .ALWAYS )
2214
+ @with_ansi_style (rich_utils .AllowStyle .ALWAYS )
2214
2215
def test_pexcept_no_style (base_app , capsys ):
2215
2216
msg = Exception ('testing...' )
2216
2217
@@ -2219,14 +2220,14 @@ def test_pexcept_no_style(base_app, capsys):
2219
2220
assert err .startswith ("EXCEPTION of type 'Exception' occurred with message: testing..." )
2220
2221
2221
2222
2222
- @with_ansi_style (ansi .AllowStyle .ALWAYS )
2223
+ @with_ansi_style (rich_utils .AllowStyle .ALWAYS )
2223
2224
def test_pexcept_not_exception (base_app , capsys ):
2224
2225
# Pass in a msg that is not an Exception object
2225
2226
msg = False
2226
2227
2227
2228
base_app .pexcept (msg )
2228
2229
out , err = capsys .readouterr ()
2229
- assert err .startswith (ansi .style_error (msg ))
2230
+ assert err .startswith (rich_utils .style_error (msg ))
2230
2231
2231
2232
2232
2233
def test_ppaged (outsim_app ):
@@ -2237,22 +2238,22 @@ def test_ppaged(outsim_app):
2237
2238
assert out == msg + end
2238
2239
2239
2240
2240
- @with_ansi_style (ansi .AllowStyle .TERMINAL )
2241
+ @with_ansi_style (rich_utils .AllowStyle .TERMINAL )
2241
2242
def test_ppaged_strips_ansi_when_redirecting (outsim_app ):
2242
2243
msg = 'testing...'
2243
2244
end = '\n '
2244
2245
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 ))
2246
2247
out = outsim_app .stdout .getvalue ()
2247
2248
assert out == msg + end
2248
2249
2249
2250
2250
- @with_ansi_style (ansi .AllowStyle .ALWAYS )
2251
+ @with_ansi_style (rich_utils .AllowStyle .ALWAYS )
2251
2252
def test_ppaged_strips_ansi_when_redirecting_if_always (outsim_app ):
2252
2253
msg = 'testing...'
2253
2254
end = '\n '
2254
2255
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 )
2256
2257
outsim_app .ppaged (colored_msg )
2257
2258
out = outsim_app .stdout .getvalue ()
2258
2259
assert out == colored_msg + end
@@ -2435,12 +2436,12 @@ def do_echo(self, args):
2435
2436
self .perror (args )
2436
2437
2437
2438
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 ))
2439
2440
# perror uses colors by default
2440
2441
self .perror (args )
2441
2442
2442
2443
2443
- @with_ansi_style (ansi .AllowStyle .ALWAYS )
2444
+ @with_ansi_style (rich_utils .AllowStyle .ALWAYS )
2444
2445
def test_ansi_pouterr_always_tty (mocker , capsys ):
2445
2446
app = AnsiApp ()
2446
2447
mocker .patch .object (app .stdout , 'isatty' , return_value = True )
@@ -2463,7 +2464,7 @@ def test_ansi_pouterr_always_tty(mocker, capsys):
2463
2464
assert 'oopsie' in err
2464
2465
2465
2466
2466
- @with_ansi_style (ansi .AllowStyle .ALWAYS )
2467
+ @with_ansi_style (rich_utils .AllowStyle .ALWAYS )
2467
2468
def test_ansi_pouterr_always_notty (mocker , capsys ):
2468
2469
app = AnsiApp ()
2469
2470
mocker .patch .object (app .stdout , 'isatty' , return_value = False )
@@ -2486,7 +2487,7 @@ def test_ansi_pouterr_always_notty(mocker, capsys):
2486
2487
assert 'oopsie' in err
2487
2488
2488
2489
2489
- @with_ansi_style (ansi .AllowStyle .TERMINAL )
2490
+ @with_ansi_style (rich_utils .AllowStyle .TERMINAL )
2490
2491
def test_ansi_terminal_tty (mocker , capsys ):
2491
2492
app = AnsiApp ()
2492
2493
mocker .patch .object (app .stdout , 'isatty' , return_value = True )
@@ -2508,7 +2509,7 @@ def test_ansi_terminal_tty(mocker, capsys):
2508
2509
assert 'oopsie' in err
2509
2510
2510
2511
2511
- @with_ansi_style (ansi .AllowStyle .TERMINAL )
2512
+ @with_ansi_style (rich_utils .AllowStyle .TERMINAL )
2512
2513
def test_ansi_terminal_notty (mocker , capsys ):
2513
2514
app = AnsiApp ()
2514
2515
mocker .patch .object (app .stdout , 'isatty' , return_value = False )
@@ -2523,7 +2524,7 @@ def test_ansi_terminal_notty(mocker, capsys):
2523
2524
assert out == err == 'oopsie\n '
2524
2525
2525
2526
2526
- @with_ansi_style (ansi .AllowStyle .NEVER )
2527
+ @with_ansi_style (rich_utils .AllowStyle .NEVER )
2527
2528
def test_ansi_never_tty (mocker , capsys ):
2528
2529
app = AnsiApp ()
2529
2530
mocker .patch .object (app .stdout , 'isatty' , return_value = True )
@@ -2538,7 +2539,7 @@ def test_ansi_never_tty(mocker, capsys):
2538
2539
assert out == err == 'oopsie\n '
2539
2540
2540
2541
2541
- @with_ansi_style (ansi .AllowStyle .NEVER )
2542
+ @with_ansi_style (rich_utils .AllowStyle .NEVER )
2542
2543
def test_ansi_never_notty (mocker , capsys ):
2543
2544
app = AnsiApp ()
2544
2545
mocker .patch .object (app .stdout , 'isatty' , return_value = False )
0 commit comments