Skip to content

Commit df1ef06

Browse files
authored
Test textwrap_body, current_date and sortable_datetime (#42)
2 parents 65941da + 0f2c292 commit df1ef06

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ optional-dependencies.tests = [
3434
"pyfakefs",
3535
"pytest",
3636
"pytest-cov",
37+
"time-machine",
3738
]
3839
urls.Changelog = "https://github.com/python/blurb/blob/main/CHANGELOG.md"
3940
urls.Homepage = "https://github.com/python/blurb"

src/blurb/blurb.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ def unsanitize_section(section):
139139
return _unsanitize_section.get(section, section)
140140

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

497-
if not 'section' in metadata:
496+
if 'section' not in metadata:
498497
throw("No 'section' specified. You must provide one!")
499498

500499
self.append((metadata, text))

tests/test_blurb.py

+54
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
import time_machine
23

34
from blurb import blurb
45

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

4647

48+
@pytest.mark.parametrize(
49+
"body, subsequent_indent, expected",
50+
(
51+
(
52+
"This is a test of the textwrap_body function with a string. It should wrap the text to 79 characters.",
53+
"",
54+
"This is a test of the textwrap_body function with a string. It should wrap\n"
55+
"the text to 79 characters.\n",
56+
),
57+
(
58+
[
59+
"This is a test of the textwrap_body function",
60+
"with an iterable of strings.",
61+
"It should wrap the text to 79 characters.",
62+
],
63+
"",
64+
"This is a test of the textwrap_body function with an iterable of strings. It\n"
65+
"should wrap the text to 79 characters.\n",
66+
),
67+
(
68+
"This is a test of the textwrap_body function with a string and subsequent indent.",
69+
" ",
70+
"This is a test of the textwrap_body function with a string and subsequent\n"
71+
" indent.\n",
72+
),
73+
(
74+
"This is a test of the textwrap_body function with a bullet list and subsequent indent. The list should not be wrapped.\n"
75+
"\n"
76+
"* Item 1\n"
77+
"* Item 2\n",
78+
" ",
79+
"This is a test of the textwrap_body function with a bullet list and\n"
80+
" subsequent indent. The list should not be wrapped.\n"
81+
"\n"
82+
" * Item 1\n"
83+
" * Item 2\n",
84+
),
85+
),
86+
)
87+
def test_textwrap_body(body, subsequent_indent, expected):
88+
assert blurb.textwrap_body(body, subsequent_indent=subsequent_indent) == expected
89+
90+
91+
@time_machine.travel("2025-01-07")
92+
def test_current_date():
93+
assert blurb.current_date() == "2025-01-07"
94+
95+
96+
@time_machine.travel("2025-01-07 16:28:41")
97+
def test_sortable_datetime():
98+
assert blurb.sortable_datetime() == "2025-01-07-16-28-41"
99+
100+
47101
@pytest.mark.parametrize(
48102
"version1, version2",
49103
(

0 commit comments

Comments
 (0)