Skip to content

Commit 7f6cf6f

Browse files
committed
fix: fix tests that failed after updating regex's
As docformatter becomes more strict in identifying patterns and handling the various patterns that are identified, some of the older tests are failing. These tests fail because the patterns in the test strings are not strictly reST, Sphinx, etc.
1 parent 095b7e0 commit 7f6cf6f

File tree

9 files changed

+26
-23
lines changed

9 files changed

+26
-23
lines changed

README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ Do you use *docformatter*? What style docstrings do you use? Add some badges t
199199
.. image:: https://img.shields.io/badge/%20style-google-3666d6.svg
200200
:target: https://google.github.io/styleguide/pyguide.html#s3.8-comments-and-docstrings
201201
202+
Assistance
203+
==========
204+
``docformatter`` has an IRC channel on `Libera.Chat`_ in the `#docformatter`_ room.
205+
.. _`Libera.Chat`: https://libera.chat
206+
.. _`#docformatter`: https://web.libera.chat/#docformatter
207+
202208
Issues
203209
======
204210

src/docformatter/constants.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@
7676
OPTION_REGEX = r"^ {0,}-{1,2}[\S ]+ \w+"
7777
"""Regular expression to use for finding option lists."""
7878

79-
REST_INLINE_REGEX = (
80-
r"(?<!^\.{2} )(:)*([*]{1,2}|_?[`]{1,2}|[|\[])[\w <>:.-]+([*]{1,"
81-
r"2}|[`]{1,2}_?|[|]|[\]]_?)"
82-
)
79+
REST_DIRECTIVE_REGEX = r"^( {0,}\.\. .+?:{1,2}.*\n(?:[ \t]{1,}.*\n|\n)*)"
80+
"""Regular expression to use for finding reST directives."""
81+
82+
REST_INLINE_REGEX = r"(?<!^\.{2} )(:)*([*]{1,2}|_?[`]{1,2}|[|\[])[\w <>:.-]+([*]{1,2}|[`]{1,2}_?|[|]|[\]]_?)" # noqa: E501
8383
"""Regular expression to use for finding inline reST markup."""
8484

8585
REST_SECTION_REGEX = (

src/docformatter/patterns/rest.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@
3131
import re
3232

3333
# docformatter Package Imports
34-
from docformatter.constants import REST_INLINE_REGEX
34+
from docformatter.constants import REST_DIRECTIVE_REGEX, REST_INLINE_REGEX
3535

3636

3737
def do_find_rest_directives(
3838
text: str,
39-
indent: int = 0,
4039
) -> list[tuple[int, int]]:
4140
"""Determine if docstring contains any reST directives.
4241
@@ -52,10 +51,7 @@ def do_find_rest_directives(
5251
bool
5352
True if the docstring is a reST directive, False otherwise.
5453
"""
55-
_rest_directive_regex = (
56-
r"^( {0,}\.\. .+?::.*\n(?:[ \t]{" + str(indent + 1) + r",}.*\n|\n)*)"
57-
)
58-
_rest_iter = re.finditer(_rest_directive_regex, text, flags=re.MULTILINE)
54+
_rest_iter = re.finditer(REST_DIRECTIVE_REGEX, text, flags=re.MULTILINE)
5955
return [(_rest.start(0), _rest.end(0)) for _rest in _rest_iter]
6056

6157

src/docformatter/strings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def do_split_summary(lines) -> List[str]:
402402
# in a multiline docstring. Thus, insert a newline and then the remaining text to
403403
# the list of lines.
404404
if rest_text:
405-
_pos = 1 if len(lines) >= 2 else 0 # noqa: PLR2004
405+
_pos = 1 if len(lines) >= 3 else 0 # noqa: PLR2004
406406
_leading_spaces = " " * (len(lines[_pos]) - len(lines[_pos].lstrip()))
407407
_internal_spaces = " " * (_pos)
408408
lines.insert(1, "")

src/docformatter/wrappers/description.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def do_wrap_description( # noqa: PLR0913
8989
not force_wrap
9090
and (
9191
_patterns.is_some_sort_of_code(text)
92-
or _patterns.do_find_rest_directives(text, len(indentation))
92+
or _patterns.do_find_rest_directives(text)
9393
or _patterns.is_type_of_list(text, strict, style)
9494
)
9595
):

tests/_data/string_files/description_wrappers.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ expected = """
8585
instring = """
8686
This is a long docstring containing some reST directives.
8787
88-
.. note
88+
.. note::
8989
This is a note in the reST dialog.
9090
"""
9191
expected = """
9292
This is a long docstring containing some reST directives.
9393
94-
.. note
94+
.. note::
9595
This is a note in the reST dialog."""

tests/_data/string_files/do_format_code.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ source='''
5050
class TestClass:
5151
"""This is a class docstring.
5252
:cvar test_int: a class attribute.
53-
..py.method: big_method()
53+
.. py:method:: big_method()
5454
"""
5555
'''
5656
expected='''
5757
class TestClass:
5858
"""This is a class docstring.
5959
6060
:cvar test_int: a class attribute.
61-
..py.method: big_method()
61+
.. py:method:: big_method()
6262
"""
6363
6464
'''
@@ -678,15 +678,15 @@ class TestClass:
678678
679679
"""This is a class docstring.
680680
:cvar test_int: a class attribute.
681-
..py.method: big_method()
681+
..py:method:: big_method()
682682
"""
683683
'''
684684
expected='''
685685
class TestClass:
686686
"""This is a class docstring.
687687
688688
:cvar test_int: a class attribute.
689-
..py.method: big_method()
689+
..py:method:: big_method()
690690
"""
691691
692692
'''
@@ -870,8 +870,8 @@ expected='''def mixed_links():
870870
871871
Once ``mpm`` is located, we can rely on it to produce the main output of the plugin.
872872
873-
The output must supports both `Xbar dialect
874-
<https://github.com/matryer/xbar-plugins/blob/main/CONTRIBUTING.md#plugin-api>`_
873+
The output must supports both
874+
`Xbar dialect <https://github.com/matryer/xbar-plugins/blob/main/CONTRIBUTING.md#plugin-api>`_
875875
and `SwiftBar dialect <https://github.com/swiftbar/SwiftBar#plugin-api>`_.
876876
"""
877877

tests/_data/string_files/do_format_docstrings.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,8 @@ source='''"""This is another docstring with `a link`_.
487487
"""'''
488488
expected='''"""This is another docstring with `a link`_.
489489
490-
.. a link: http://www.reliqual.com/wiki/how_to_use_ramstk/verification_and_validation_module/index.html.
490+
.. a link:
491+
http://www.reliqual.com/wiki/how_to_use_ramstk/verification_and_validation_module/index.html.
491492
"""'''
492493

493494
[issue_75_2]

tests/_data/string_files/string_functions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ expected = ["This e.g. a sentence.", ""]
116116

117117
[do_split_multi_sentence_summary] # See issue #283.
118118
instring = ["This is a sentence. This is another.", ""]
119-
expected = ["This is a sentence.","","This is another."]
119+
expected = ["This is a sentence.", "This is another.", ""]
120120

121121
[do_split_multi_sentence_summary_2] # See issue #283.
122122
instring = ["This e.g. a sentence. This is another.", ""]
123-
expected = ["This e.g. a sentence.", "", "This is another."]
123+
expected = ["This e.g. a sentence.", "This is another.", ""]
124124

125125
[do_split_description_url_outside_param]
126126
instring = "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm https://mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm\n:param a:mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"

0 commit comments

Comments
 (0)