@@ -362,18 +362,12 @@ def test_actions_spans_in_usage():
362
362
mut_ex .add_argument ("--opt" , nargs = "?" )
363
363
mut_ex .add_argument ("--opts" , nargs = "+" )
364
364
365
- # https://github.com/python/cpython/issues/82619
366
- if sys .version_info < (3 , 9 ): # pragma: <3.9 cover
367
- zom_metavar = "[\x1b [36mzom\x1b [0m [\x1b [36mzom\x1b [0m \x1b [36m...\x1b [0m]]"
368
- else : # pragma: >=3.9 cover
369
- zom_metavar = "[\x1b [36mzom\x1b [0m \x1b [36m...\x1b [0m]"
370
-
371
365
usage_text = (
372
- f "\x1b [38;5;208mUsage:\x1b [0m \x1b [38;5;244mPROG\x1b [0m [\x1b [36m-h\x1b [0m] "
373
- f "[\x1b [36m--opt\x1b [0m [\x1b [38;5;36mOPT\x1b [0m] | "
374
- f "\x1b [36m--opts\x1b [0m \x1b [38;5;36mOPTS\x1b [0m [\x1b [38;5;36mOPTS\x1b [0m \x1b [38;5;36m...\x1b [0m]]\n "
375
- f "\x1b [36mrequired\x1b [0m \x1b [36mint\x1b [0m \x1b [36mint\x1b [0m [\x1b [36moptional\x1b [0m] "
376
- f" { zom_metavar } \x1b [36moom\x1b [0m [\x1b [36moom\x1b [0m \x1b [36m...\x1b [0m] \x1b [36m...\x1b [0m \x1b [36mparser\x1b [0m \x1b [36m...\x1b [0m"
366
+ "\x1b [38;5;208mUsage:\x1b [0m \x1b [38;5;244mPROG\x1b [0m [\x1b [36m-h\x1b [0m] "
367
+ "[\x1b [36m--opt\x1b [0m [\x1b [38;5;36mOPT\x1b [0m] | "
368
+ "\x1b [36m--opts\x1b [0m \x1b [38;5;36mOPTS\x1b [0m [\x1b [38;5;36mOPTS\x1b [0m \x1b [38;5;36m...\x1b [0m]]\n "
369
+ "\x1b [36mrequired\x1b [0m \x1b [36mint\x1b [0m \x1b [36mint\x1b [0m [\x1b [36moptional\x1b [0m] "
370
+ "[ \x1b [36mzom \x1b [0m \x1b [36m... \x1b [0m] \x1b [36moom\x1b [0m [\x1b [36moom\x1b [0m \x1b [36m...\x1b [0m] \x1b [36m...\x1b [0m \x1b [36mparser\x1b [0m \x1b [36m...\x1b [0m"
377
371
)
378
372
expected_help_output = f"""\
379
373
{ usage_text }
@@ -396,9 +390,8 @@ def test_actions_spans_in_usage():
396
390
assert parser .format_help () == clean_argparse (expected_help_output )
397
391
398
392
399
- @pytest .mark .skipif (sys .version_info < (3 , 9 ), reason = "not available in 3.8" )
400
393
@pytest .mark .usefixtures ("force_color" )
401
- def test_boolean_optional_action_spans (): # pragma: >=3.9 cover
394
+ def test_boolean_optional_action_spans ():
402
395
parser = ArgumentParser ("PROG" , formatter_class = RichHelpFormatter )
403
396
parser .add_argument ("--bool" , action = argparse .BooleanOptionalAction )
404
397
expected_help_output = """\
@@ -732,8 +725,9 @@ def test_rich_lazy_import():
732
725
if mod_name != "rich" and not mod_name .startswith ("rich." )
733
726
}
734
727
lazy_rich = {k : v for k , v in r .__dict__ .items () if k not in r .__all__ }
735
- with patch .dict (sys .modules , sys_modules_no_rich , clear = True ), patch .dict (
736
- r .__dict__ , lazy_rich , clear = True
728
+ with (
729
+ patch .dict (sys .modules , sys_modules_no_rich , clear = True ),
730
+ patch .dict (r .__dict__ , lazy_rich , clear = True ),
737
731
):
738
732
parser = ArgumentParser (formatter_class = RichHelpFormatter )
739
733
parser .add_argument ("--foo" , help = "foo help" )
@@ -809,8 +803,9 @@ def test_legacy_windows(): # pragma: win32 cover
809
803
# Legacy windows console on new windows => colors: YES, initialization: YES
810
804
init_win_colors = Mock (return_value = True )
811
805
parser = ArgumentParser ("PROG" , formatter_class = RichHelpFormatter )
812
- with patch ("rich.console.detect_legacy_windows" , return_value = True ), patch (
813
- "rich_argparse._common._initialize_win_colors" , init_win_colors
806
+ with (
807
+ patch ("rich.console.detect_legacy_windows" , return_value = True ),
808
+ patch ("rich_argparse._common._initialize_win_colors" , init_win_colors ),
814
809
):
815
810
help = parser .format_help ()
816
811
assert help == clean_argparse (expected_colored_output )
@@ -819,8 +814,9 @@ def test_legacy_windows(): # pragma: win32 cover
819
814
# Legacy windows console on old windows => colors: NO, initialization: YES
820
815
init_win_colors = Mock (return_value = False )
821
816
parser = ArgumentParser ("PROG" , formatter_class = RichHelpFormatter )
822
- with patch ("rich.console.detect_legacy_windows" , return_value = True ), patch (
823
- "rich_argparse._common._initialize_win_colors" , init_win_colors
817
+ with (
818
+ patch ("rich.console.detect_legacy_windows" , return_value = True ),
819
+ patch ("rich_argparse._common._initialize_win_colors" , init_win_colors ),
824
820
):
825
821
help = parser .format_help ()
826
822
assert help == clean_argparse (expected_output )
@@ -834,8 +830,9 @@ def fmt_no_color(prog):
834
830
835
831
init_win_colors = Mock (return_value = True )
836
832
no_colors_parser = ArgumentParser ("PROG" , formatter_class = fmt_no_color )
837
- with patch ("rich.console.detect_legacy_windows" , return_value = True ), patch (
838
- "rich_argparse._common._initialize_win_colors" , init_win_colors
833
+ with (
834
+ patch ("rich.console.detect_legacy_windows" , return_value = True ),
835
+ patch ("rich_argparse._common._initialize_win_colors" , init_win_colors ),
839
836
):
840
837
help = no_colors_parser .format_help ()
841
838
assert help == clean_argparse (expected_output )
@@ -1067,10 +1064,6 @@ def test_metavar_spans():
1067
1064
meg .add_argument ("--op7" , metavar = ("MET1" , "MET2" , "MET3" ), nargs = 3 )
1068
1065
help_text = parser .format_help ()
1069
1066
1070
- op3_metavar = "[\x1b [38;5;36mOP3\x1b [0m \x1b [38;5;36m...\x1b [0m]"
1071
- if sys .version_info < (3 , 9 ): # pragma: <3.9 cover
1072
- op3_metavar = f"[\x1b [38;5;36mOP3\x1b [0m { op3_metavar } ]"
1073
-
1074
1067
if sys .version_info >= (3 , 13 ): # pragma: >=3.13 cover
1075
1068
usage_tail = """ |
1076
1069
\x1b [36m--op2\x1b [0m [\x1b [38;5;36mMET1\x1b [0m [\x1b [38;5;36mMET2\x1b [0m \x1b [38;5;36m...\x1b [0m]] |
@@ -1081,11 +1074,11 @@ def test_metavar_spans():
1081
1074
\x1b [36m--op7\x1b [0m \x1b [38;5;36mMET1\x1b [0m \x1b [38;5;36mMET2\x1b [0m \x1b [38;5;36mMET3\x1b [0m]
1082
1075
"""
1083
1076
else : # pragma: <3.13 cover
1084
- usage_tail = f """
1077
+ usage_tail = """
1085
1078
| \x1b [36m--op2\x1b [0m
1086
1079
[\x1b [38;5;36mMET1\x1b [0m [\x1b [38;5;36mMET2\x1b [0m \x1b [38;5;36m...\x1b [0m]]
1087
1080
| \x1b [36m--op3\x1b [0m
1088
- { op3_metavar }
1081
+ [ \x1b [38;5;36mOP3 \x1b [0m \x1b [38;5;36m... \x1b [0m]
1089
1082
| \x1b [36m--op4\x1b [0m
1090
1083
\x1b [38;5;36mMET1\x1b [0m
1091
1084
[\x1b [38;5;36mMET2\x1b [0m \x1b [38;5;36m...\x1b [0m]
@@ -1109,7 +1102,7 @@ def test_metavar_spans():
1109
1102
\x1b [39mmessage and exit\x1b [0m
1110
1103
\x1b [36m--op1\x1b [0m [\x1b [38;5;36mMET\x1b [0m]
1111
1104
\x1b [36m--op2\x1b [0m [\x1b [38;5;36mMET1\x1b [0m [\x1b [38;5;36mMET2\x1b [0m \x1b [38;5;36m...\x1b [0m]]
1112
- \x1b [36m--op3\x1b [0m { op3_metavar }
1105
+ \x1b [36m--op3\x1b [0m [ \x1b [38;5;36mOP3 \x1b [0m \x1b [38;5;36m... \x1b [0m]
1113
1106
\x1b [36m--op4\x1b [0m \x1b [38;5;36mMET1\x1b [0m [\x1b [38;5;36mMET2\x1b [0m \x1b [38;5;36m...\x1b [0m]
1114
1107
\x1b [36m--op5\x1b [0m \x1b [38;5;36mOP5\x1b [0m [\x1b [38;5;36mOP5\x1b [0m \x1b [38;5;36m...\x1b [0m]
1115
1108
\x1b [36m--op6\x1b [0m \x1b [38;5;36mOP6\x1b [0m \x1b [38;5;36mOP6\x1b [0m \x1b [38;5;36mOP6\x1b [0m
0 commit comments