Skip to content

Commit

Permalink
fix: not capitalizing first word when summary ends in period (#185)
Browse files Browse the repository at this point in the history
* fix: not capitalizing first word in summary with period

* test: for capitalizing first word in summary with period
  • Loading branch information
weibullguy authored Apr 24, 2023
1 parent 154028b commit 1e9076a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/docformatter/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
# SOFTWARE.
"""This module provides docformatter string functions."""


import contextlib
# Standard Library Imports
import re

Expand Down Expand Up @@ -110,7 +112,13 @@ def normalize_summary(summary: str) -> str:
and (not summary.startswith("#"))
):
summary += "."
summary = summary[0].upper() + summary[1:]

with contextlib.suppress(IndexError):
# Look for underscores in the first word, this would typically
# indicate the first word is a variable name or some other
# non-standard English word.
if "_" not in summary.split(" ", 1)[0]:
summary = summary[0].upper() + summary[1:]

return summary

Expand Down
23 changes: 23 additions & 0 deletions tests/test_string_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,29 @@ def test_normalize_summary_capitalize_first_letter(self):
"don't lower case I'm"
)

@pytest.mark.unit
def test_normalize_summary_capitalize_first_letter_with_period(self):
"""Capitalize the first letter of the summary even when ends in period.
See issue #184. See requirement docformatter_4.5.1.
"""
assert (
"This is a summary that needs to be capped."
== docformatter.normalize_summary(
"this is a summary that needs to be capped."
)
)

@pytest.mark.unit
def test_normalize_summary_dont_capitalize_first_letter_if_variable(self):
"""Capitalize the first word unless it looks like a variable."""
assert (
"num_iterations should not be capitalized in this summary."
== docformatter.normalize_summary(
"num_iterations should not be capitalized in this summary"
)
)


class TestSplitters:
"""Class for testing the string splitting function.
Expand Down

0 comments on commit 1e9076a

Please sign in to comment.