From c817b29dc77fa15d64e2126e9eadb88c28bb42f9 Mon Sep 17 00:00:00 2001 From: Hal Blackburn Date: Thu, 1 Sep 2022 16:34:35 +0000 Subject: [PATCH] fix: handle 3+ word Options: section names parse_defaults() was failing with an AssertionError when an options section with 3 or more words was used. e.g. "Very Advanced Options:". This fixes https://github.com/jazzband/docopt-ng/issues/9 --- docopt/__init__.py | 4 +--- tests/test_docopt.py | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docopt/__init__.py b/docopt/__init__.py index c735337..60310d9 100644 --- a/docopt/__init__.py +++ b/docopt/__init__.py @@ -711,9 +711,7 @@ def parse_defaults(docstring: str) -> list[Option]: defaults = [] for s in parse_section("options:", docstring): options_literal, _, s = s.partition(":") - if " " in options_literal: - _, _, options_literal = options_literal.partition(" ") - assert options_literal.lower().strip() == "options" + assert options_literal.lower().endswith("options") split = re.split(r"\n[ \t]*(-\S+?)", "\n" + s)[1:] split = [s1 + s2 for s1, s2 in zip(split[::2], split[1::2])] for s in split: diff --git a/tests/test_docopt.py b/tests/test_docopt.py index 0df70de..9056fba 100644 --- a/tests/test_docopt.py +++ b/tests/test_docopt.py @@ -643,6 +643,7 @@ def test_language_errors(): [ pytest.param("Usage: prog\n Options: --foo\n"), pytest.param("Usage: prog\n Advanced Options: --foo\n"), + pytest.param("Usage: prog\n Very Advanced Options: --foo\n"), ], ) def test_docopt_reports_options_in_usage_section(doc: str):