Skip to content

Commit

Permalink
fix: tests under Python 3.13 (fixes #228)
Browse files Browse the repository at this point in the history
  • Loading branch information
neithere committed Jun 16, 2024
1 parent 0ff6c31 commit cdb70d5
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Dependencies
------------

The `argh` library is supported (and tested unless otherwise specified)
on the following versions of Python: 3.8, 3.9, 3.10, 3.11, 3.12.
on the following versions of Python: 3.8, 3.9, 3.10, 3.11, 3.12, .13.

If you need support for ancient Pythons, please use the following versions
of Argh (the numeric puns were semi-intentional):
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Software Development :: User Interfaces",
Expand Down
97 changes: 78 additions & 19 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,18 +724,34 @@ def remind(
help_normalised = re.sub(r"\s+", " ", parser.format_help())

assert "name 'Basil'" in help_normalised
assert "-t TASK, --task TASK 'hang the Moose'" in help_normalised
assert (
"-r REASON, --reason REASON 'there are creatures living in it'"
in help_normalised
)

# explicit help message is not obscured by the implicit one
# but is still present
assert (
"-n NOTE, --note NOTE why is it a remarkable animal? "
"(default: 'it can speak English')"
) in help_normalised
# argh#228 — argparse in Python before 3.13 duplicated the placeholder in help
if sys.version_info < (3, 13):
assert "-t TASK, --task TASK 'hang the Moose'" in help_normalised
assert (
"-r REASON, --reason REASON 'there are creatures living in it'"
in help_normalised
)

# explicit help message is not obscured by the implicit one
# but is still present
assert (
"-n NOTE, --note NOTE why is it a remarkable animal? "
"(default: 'it can speak English')"
) in help_normalised
else:
assert "-t, --task TASK 'hang the Moose'" in help_normalised
assert (
"-r, --reason REASON 'there are creatures living in it'"
in help_normalised
)

# explicit help message is not obscured by the implicit one
# but is still present
assert (
"-n, --note NOTE why is it a remarkable animal? "
"(default: 'it can speak English')"
) in help_normalised


def test_default_arg_values_in_help__regression():
Expand All @@ -750,9 +766,16 @@ def foo(*, bar=""):
# doesn't break
parser.format_help()

# argh#228 — argparse in Python before 3.13 duplicated the placeholder in help
if sys.version_info < (3, 13):
expected_line = "-b BAR, --bar BAR ''"
# note the empty str repr ^^^
else:
expected_line = "-b, --bar BAR ''"
# note the empty str repr ^^^

# now check details
assert "-b BAR, --bar BAR ''" in parser.format_help()
# note the empty str repr ^^^
assert expected_line in parser.format_help()


def test_help_formatting_is_preserved():
Expand Down Expand Up @@ -868,6 +891,19 @@ def second_func():

run(parser, "first-func --help", exit=True)
captured = capsys.readouterr()

# argh#228 — argparse in Python before 3.13 duplicated the placeholder in help
if sys.version_info < (3, 13):
arg_help_lines = (
" -h, --help show this help message and exit\n"
" -f FOO, --foo FOO 123"
)
else:
arg_help_lines = (
" -h, --help show this help message and exit\n"
" -f, --foo FOO 123"
)

assert (
captured.out
== unindent(
Expand All @@ -877,8 +913,7 @@ def second_func():
Owl stretching time
{HELP_OPTIONS_LABEL}:
-h, --help show this help message and exit
-f FOO, --foo FOO 123
{arg_help_lines}
"""
)[1:]
)
Expand Down Expand Up @@ -997,6 +1032,19 @@ def second_func():

run(parser, "my-group first-func --help", exit=True)
captured = capsys.readouterr()

# argh#228 — argparse in Python before 3.13 duplicated the placeholder in help
if sys.version_info < (3, 13):
arg_help_lines = (
" -h, --help show this help message and exit\n"
" -f FOO, --foo FOO 123"
)
else:
arg_help_lines = (
" -h, --help show this help message and exit\n"
" -f, --foo FOO 123"
)

assert (
captured.out
== unindent(
Expand All @@ -1006,8 +1054,7 @@ def second_func():
Owl stretching time
{HELP_OPTIONS_LABEL}:
-h, --help show this help message and exit
-f FOO, --foo FOO 123
{arg_help_lines}
"""
)[1:]
)
Expand Down Expand Up @@ -1079,6 +1126,19 @@ def second_func():

run(parser, "first-func --help", exit=True)
captured = capsys.readouterr()

# argh#228 — argparse in Python before 3.13 duplicated the placeholder in help
if sys.version_info < (3, 13):
arg_help_lines = (
" -h, --help show this help message and exit\n"
" -f FOO, --foo FOO 123"
)
else:
arg_help_lines = (
" -h, --help show this help message and exit\n"
" -f, --foo FOO 123"
)

assert (
captured.out
== unindent(
Expand All @@ -1088,8 +1148,7 @@ def second_func():
func description override
{HELP_OPTIONS_LABEL}:
-h, --help show this help message and exit
-f FOO, --foo FOO 123
{arg_help_lines}
"""
)[1:]
)
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ envlist =
py310
py311
py312
py313
pypy3
as-module
lint
Expand All @@ -21,6 +22,7 @@ python =
3.10: py310
3.11: py311,lint,as-module
3.12: py312
3.13: py313
pypy-3.9: pypy3
pypy-3.10: pypy3

Expand Down

0 comments on commit cdb70d5

Please sign in to comment.