From 19c14f0e76f770fde67a6b3ba39b8015b186cc92 Mon Sep 17 00:00:00 2001 From: Doyle Rowland Date: Mon, 10 Jul 2023 22:51:45 -0400 Subject: [PATCH] fix: not recognizing `yield` as a sphinx field name (#254) * fix: not recognizing as sphinx field name * test: for recognizing as sphinx field name --- src/docformatter/syntax.py | 2 +- tests/_data/string_files/format_sphinx.toml | 14 ++++++++ tests/formatter/test_format_sphinx.py | 39 +++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/docformatter/syntax.py b/src/docformatter/syntax.py index c6af9a6..a389341 100644 --- a/src/docformatter/syntax.py +++ b/src/docformatter/syntax.py @@ -59,7 +59,7 @@ REST_REGEX = r"((\.{2}|`{2}) ?[\w.~-]+(:{2}|`{2})?[\w ]*?|`[\w.~]+`)" """Regular expression to use for finding reST directives.""" -SPHINX_REGEX = r":(param|raises|return|rtype|type)[a-zA-Z0-9_\-.() ]*:" +SPHINX_REGEX = r":(param|raises|return|rtype|type|yield)[a-zA-Z0-9_\-.() ]*:" """Regular expression to use for finding Sphinx-style field lists.""" URL_PATTERNS = ( diff --git a/tests/_data/string_files/format_sphinx.toml b/tests/_data/string_files/format_sphinx.toml index e2e566e..38eefaa 100644 --- a/tests/_data/string_files/format_sphinx.toml +++ b/tests/_data/string_files/format_sphinx.toml @@ -236,3 +236,17 @@ outstring='''"""CC. c c :math:`[0, 1]`. """''' + +[issue_253] +instring='''""" + My test fixture. + + :param caplog: Pytest caplog fixture. + :yield: Until test complete, then run cleanup. + """''' +outstring='''""" + My test fixture. + + :param caplog: Pytest caplog fixture. + :yield: Until test complete, then run cleanup. + """''' diff --git a/tests/formatter/test_format_sphinx.py b/tests/formatter/test_format_sphinx.py index 297d682..03480db 100644 --- a/tests/formatter/test_format_sphinx.py +++ b/tests/formatter/test_format_sphinx.py @@ -433,3 +433,42 @@ def test_format_docstring_sphinx_style_ignore_directive( INDENTATION, instring, ) + + @pytest.mark.unit + @pytest.mark.parametrize( + "args", + [ + [ + "--wrap-descriptions", + "120", + "--wrap-summaries", + "120", + "--pre-summary-newline", + "--black", + "", + ] + ], + ) + def test_format_docstring_sphinx_style_recognize_yield( + self, + test_args, + args, + ): + """Should identify `yield` as sphinx field name. + + See issue #253. + """ + uut = Formatter( + test_args, + sys.stderr, + sys.stdin, + sys.stdout, + ) + + instring = self.TEST_STRINGS["issue_253"]["instring"] + outstring = self.TEST_STRINGS["issue_253"]["outstring"] + + assert outstring == uut._do_format_docstring( + INDENTATION, + instring, + )