From 156988c6d9366ef750e3416f23a3512b25497c49 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Tue, 7 Jan 2025 16:50:03 +0200 Subject: [PATCH 1/5] Test textwrap_body, current_date and sortable_datetime --- pyproject.toml | 1 + tests/test_blurb.py | 61 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 29e9bac..d6f0669 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/tests/test_blurb.py b/tests/test_blurb.py index e9da901..8814ff1 100644 --- a/tests/test_blurb.py +++ b/tests/test_blurb.py @@ -1,4 +1,5 @@ import pytest +import time_machine from blurb import blurb @@ -44,6 +45,66 @@ 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", ( From 7cb5abb6372c96ca463ed81e428c0a8702c807f3 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Tue, 7 Jan 2025 16:52:11 +0200 Subject: [PATCH 2/5] Remove unused variable --- src/blurb/blurb.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/blurb/blurb.py b/src/blurb/blurb.py index 9950554..0c5e37a 100755 --- a/src/blurb/blurb.py +++ b/src/blurb/blurb.py @@ -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}" From 1e6dd0f9d86ac20caa583d4de9dff8309e83146e Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Tue, 7 Jan 2025 16:53:27 +0200 Subject: [PATCH 3/5] Use 'not in' to test membership --- src/blurb/blurb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blurb/blurb.py b/src/blurb/blurb.py index 0c5e37a..b3998b5 100755 --- a/src/blurb/blurb.py +++ b/src/blurb/blurb.py @@ -493,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)) From ee43c4806c64369de8eb4147732ca82f8d351b6c Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Tue, 7 Jan 2025 18:03:30 +0200 Subject: [PATCH 4/5] Remove extra parentheses --- tests/test_blurb.py | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/tests/test_blurb.py b/tests/test_blurb.py index 8814ff1..dc75497 100644 --- a/tests/test_blurb.py +++ b/tests/test_blurb.py @@ -51,10 +51,8 @@ def test_unsanitize_section_changed(section, 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 a string. It should wrap\n" + "the text to 79 characters.\n", ), ( [ @@ -63,18 +61,14 @@ def test_unsanitize_section_changed(section, expected): "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 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 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" @@ -82,13 +76,11 @@ def test_unsanitize_section_changed(section, expected): "* 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" - ), + "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", ), ), ) From 0f2c29299bdea1b637db9232ddda6b4ab88ec611 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Wed, 15 Jan 2025 14:40:24 +0200 Subject: [PATCH 5/5] Add newline --- tests/test_blurb.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_blurb.py b/tests/test_blurb.py index dc75497..caf0f4e 100644 --- a/tests/test_blurb.py +++ b/tests/test_blurb.py @@ -97,6 +97,7 @@ def test_current_date(): def test_sortable_datetime(): assert blurb.sortable_datetime() == "2025-01-07-16-28-41" + @pytest.mark.parametrize( "version1, version2", (