Skip to content

Commit 156988c

Browse files
committed
Test textwrap_body, current_date and sortable_datetime
1 parent 65941da commit 156988c

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
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"

tests/test_blurb.py

Lines changed: 61 additions & 0 deletions
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,66 @@ 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+
(
55+
"This is a test of the textwrap_body function with a string. It should wrap\n"
56+
"the text to 79 characters.\n"
57+
),
58+
),
59+
(
60+
[
61+
"This is a test of the textwrap_body function",
62+
"with an iterable of strings.",
63+
"It should wrap the text to 79 characters.",
64+
],
65+
"",
66+
(
67+
"This is a test of the textwrap_body function with an iterable of strings. It\n"
68+
"should wrap the text to 79 characters.\n"
69+
),
70+
),
71+
(
72+
"This is a test of the textwrap_body function with a string and subsequent indent.",
73+
" ",
74+
(
75+
"This is a test of the textwrap_body function with a string and subsequent\n"
76+
" indent.\n"
77+
),
78+
),
79+
(
80+
"This is a test of the textwrap_body function with a bullet list and subsequent indent. The list should not be wrapped.\n"
81+
"\n"
82+
"* Item 1\n"
83+
"* Item 2\n",
84+
" ",
85+
(
86+
"This is a test of the textwrap_body function with a bullet list and\n"
87+
" subsequent indent. The list should not be wrapped.\n"
88+
"\n"
89+
" * Item 1\n"
90+
" * Item 2\n"
91+
),
92+
),
93+
),
94+
)
95+
def test_textwrap_body(body, subsequent_indent, expected):
96+
assert blurb.textwrap_body(body, subsequent_indent=subsequent_indent) == expected
97+
98+
99+
@time_machine.travel("2025-01-07")
100+
def test_current_date():
101+
assert blurb.current_date() == "2025-01-07"
102+
103+
104+
@time_machine.travel("2025-01-07 16:28:41")
105+
def test_sortable_datetime():
106+
assert blurb.sortable_datetime() == "2025-01-07-16-28-41"
107+
47108
@pytest.mark.parametrize(
48109
"version1, version2",
49110
(

0 commit comments

Comments
 (0)