Skip to content

Commit

Permalink
Test textwrap_body, current_date and sortable_datetime (#42)
Browse files Browse the repository at this point in the history
hugovk authored Jan 15, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 65941da + 0f2c292 commit df1ef06
Showing 3 changed files with 56 additions and 2 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ optional-dependencies.tests = [
"pyfakefs",
"pytest",
"pytest-cov",
"time-machine",
]
urls.Changelog = "https://github.com/python/blurb/blob/main/CHANGELOG.md"
urls.Homepage = "https://github.com/python/blurb"
3 changes: 1 addition & 2 deletions src/blurb/blurb.py
Original file line number Diff line number Diff line change
@@ -139,7 +139,6 @@ def unsanitize_section(section):
return _unsanitize_section.get(section, section)

def next_filename_unsanitize_sections(filename):
s = filename
for key, value in _unsanitize_section.items():
for separator in "/\\":
key = f"{separator}{key}{separator}"
@@ -494,7 +493,7 @@ def finish_entry():
if "gh-issue" not in metadata and "bpo" not in metadata:
throw("'gh-issue:' or 'bpo:' must be specified in the metadata!")

if not 'section' in metadata:
if 'section' not in metadata:
throw("No 'section' specified. You must provide one!")

self.append((metadata, text))
54 changes: 54 additions & 0 deletions tests/test_blurb.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import time_machine

from blurb import blurb

@@ -44,6 +45,59 @@ def test_unsanitize_section_changed(section, expected):
assert unsanitized == expected


@pytest.mark.parametrize(
"body, subsequent_indent, expected",
(
(
"This is a test of the textwrap_body function with a string. It should wrap the text to 79 characters.",
"",
"This is a test of the textwrap_body function with a string. It should wrap\n"
"the text to 79 characters.\n",
),
(
[
"This is a test of the textwrap_body function",
"with an iterable of strings.",
"It should wrap the text to 79 characters.",
],
"",
"This is a test of the textwrap_body function with an iterable of strings. It\n"
"should wrap the text to 79 characters.\n",
),
(
"This is a test of the textwrap_body function with a string and subsequent indent.",
" ",
"This is a test of the textwrap_body function with a string and subsequent\n"
" indent.\n",
),
(
"This is a test of the textwrap_body function with a bullet list and subsequent indent. The list should not be wrapped.\n"
"\n"
"* Item 1\n"
"* Item 2\n",
" ",
"This is a test of the textwrap_body function with a bullet list and\n"
" subsequent indent. The list should not be wrapped.\n"
"\n"
" * Item 1\n"
" * Item 2\n",
),
),
)
def test_textwrap_body(body, subsequent_indent, expected):
assert blurb.textwrap_body(body, subsequent_indent=subsequent_indent) == expected


@time_machine.travel("2025-01-07")
def test_current_date():
assert blurb.current_date() == "2025-01-07"


@time_machine.travel("2025-01-07 16:28:41")
def test_sortable_datetime():
assert blurb.sortable_datetime() == "2025-01-07-16-28-41"


@pytest.mark.parametrize(
"version1, version2",
(

0 comments on commit df1ef06

Please sign in to comment.