88
99import re
1010
11+ import pytest
12+
1113import changelog_utils
1214
1315
16+ def _require (condition : bool , message : str ) -> None :
17+ if not condition :
18+ pytest .fail (message )
19+
20+
1421def _section_body (lines : list [str ], header : str ) -> list [str ]:
1522 """Return lines between a section header and the next section/release header."""
1623 try :
@@ -49,20 +56,35 @@ def test_breaking_changes_moved_out_of_changed_section(self):
4956 processed = changelog_utils ._ReleaseNotesPostProcessor .process (content ) # noqa: SLF001
5057 lines = processed .splitlines ()
5158
52- assert "### ⚠️ Breaking Changes" in processed
59+ _require (
60+ "### ⚠️ Breaking Changes" in processed ,
61+ "Expected breaking changes section to be present" ,
62+ )
5363
5464 breaking_start = lines .index ("### ⚠️ Breaking Changes" )
5565 changed_start = lines .index ("### Changed" )
56- assert breaking_start < changed_start
66+ _require (
67+ breaking_start < changed_start ,
68+ "Expected breaking changes section to appear before the Changed section" ,
69+ )
5770
5871 breaking_body = _section_body (lines , "### ⚠️ Breaking Changes" )
59- assert any ("MSRV" in line for line in breaking_body )
72+ _require (
73+ any ("MSRV" in line for line in breaking_body ),
74+ "Expected MSRV entry to be present in breaking changes section" ,
75+ )
6076
6177 changed_body = _section_body (lines , "### Changed" )
62- assert not any ("MSRV" in line for line in changed_body )
78+ _require (
79+ not any ("MSRV" in line for line in changed_body ),
80+ "Expected MSRV entry to be removed from Changed section" ,
81+ )
6382
6483 # The breaking section should not include verbose body details.
65- assert not any ("Details that should not appear" in line for line in breaking_body )
84+ _require (
85+ not any ("Details that should not appear" in line for line in breaking_body ),
86+ "Expected verbose breaking-change body details to be trimmed" ,
87+ )
6688
6789 def test_commit_links_attached_to_top_level_only (self ):
6890 top_sha = "1234567890123456789012345678901234567890" # 40 chars
@@ -84,14 +106,23 @@ def test_commit_links_attached_to_top_level_only(self):
84106 processed = changelog_utils ._ReleaseNotesPostProcessor .process (content ) # noqa: SLF001
85107
86108 # Top-level bullet should keep an attached (shortened) commit link.
87- assert "`1234567`" in processed
109+ _require (
110+ "`1234567`" in processed ,
111+ "Expected top-level bullet to keep an attached (shortened) commit link" ,
112+ )
88113
89114 # Nested bullets should not include commit links (they're dropped).
90- assert "`9876543`" not in processed
115+ _require (
116+ "`9876543`" not in processed ,
117+ "Expected nested bullet commit links to be dropped" ,
118+ )
91119
92120 # No standalone commit-link-only lines should remain.
93121 commit_only_re = re .compile (r"^\s*\[`[a-f0-9]{7,40}`\]\([^)]*\)\s*$" )
94- assert not any (commit_only_re .match (line ) for line in processed .splitlines ())
122+ _require (
123+ not any (commit_only_re .match (line ) for line in processed .splitlines ()),
124+ "Expected no standalone commit-link-only lines to remain" ,
125+ )
95126
96127 def test_added_section_consolidates_many_entries_from_same_commit (self ):
97128 sha = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" # 40 chars
@@ -114,16 +145,19 @@ def test_added_section_consolidates_many_entries_from_same_commit(self):
114145
115146 added_body = _section_body (lines , "### Added" )
116147 top_level_bullets = [line for line in added_body if line .startswith ("- **" )]
117- assert len (top_level_bullets ) == 1
148+ _require (
149+ len (top_level_bullets ) == 1 ,
150+ "Expected Added section to consolidate into a single top-level bullet" ,
151+ )
118152
119153 # Ensure we preserved the details as nested items.
120- assert "Add helper function" in processed
121- assert "Add another helper" in processed
122- assert "Add tests for new API" in processed
154+ _require ( "Add helper function" in processed , "Expected helper entry to be preserved" )
155+ _require ( "Add another helper" in processed , "Expected helper entry to be preserved" )
156+ _require ( "Add tests for new API" in processed , "Expected tests entry to be preserved" )
123157
124158 # Bucket structure should be present.
125- assert " - Tests" in processed
126- assert " - Other" in processed
159+ _require ( " - Tests" in processed , "Expected consolidated output to include a Tests bucket" )
160+ _require ( " - Other" in processed , "Expected consolidated output to include an Other bucket" )
127161
128162 def test_wording_normalization_replacements (self ):
129163 content = """# Changelog
@@ -137,7 +171,10 @@ def test_wording_normalization_replacements(self):
137171
138172 processed = changelog_utils ._ReleaseNotesPostProcessor .process (content ) # noqa: SLF001
139173
140- assert "retryable" in processed
141- assert "determinants" in processed
142- assert "retriable" not in processed
143- assert re .search (r"\bdets\b" , processed , flags = re .IGNORECASE ) is None
174+ _require ("retryable" in processed , "Expected 'retriable' to be normalized to 'retryable'" )
175+ _require ("determinants" in processed , "Expected 'dets' to be normalized to 'determinants'" )
176+ _require ("retriable" not in processed , "Expected original word 'retriable' to be removed" )
177+ _require (
178+ re .search (r"\bdets\b" , processed , flags = re .IGNORECASE ) is None ,
179+ "Expected original token 'dets' to be removed" ,
180+ )
0 commit comments