@@ -37,26 +37,31 @@ def test_update_changelog_subcommand_help():
3737 assert "Pull request title" in result .stdout
3838
3939
40- def test_bump_version_patch ():
41- """Test version bumping with patch increment."""
40+ @pytest .mark .parametrize ("start_version,bump_type,expected_version" , [
41+ pytest .param ("1.2.3" , "patch" , "1.2.4" , id = "patch_bump" ),
42+ pytest .param ("1.2.3" , "minor" , "1.3.0" , id = "minor_bump" ),
43+ pytest .param ("1.2.3" , "major" , "2.0.0" , id = "major_bump" ),
44+ ])
45+ def test_bump_version (start_version , bump_type , expected_version ):
46+ """Test version bumping with different increment types."""
4247 with tempfile .TemporaryDirectory () as temp_dir :
4348 temp_path = Path (temp_dir )
4449
4550 # Create mock Cargo.toml
46- cargo_content = '''[package]
51+ cargo_content = f '''[package]
4752name = "test-package"
48- version = "1.2.3 "
53+ version = "{ start_version } "
4954edition = "2021"
5055'''
5156 cargo_path = temp_path / "Cargo.toml"
5257 cargo_path .write_text (cargo_content )
5358
5459 # Create mock changelog
55- changelog_content = '''# Changelog
60+ changelog_content = f '''# Changelog
5661
5762## UNRELEASED
5863
59- ## 1.2.3 (2024-01-01)
64+ ## { start_version } (2024-01-01)
6065
6166- Some old change
6267'''
@@ -68,104 +73,20 @@ def test_bump_version_patch():
6873 # Run the script
6974 result = subprocess .run ([sys .executable ,
7075 str (Path (__file__ ).parent .parent .parent / "modify_changelog.py" ),
71- "bump_version" , "patch" ],
76+ "bump_version" , bump_type ],
7277 capture_output = True , text = True , cwd = temp_path )
7378
7479 assert result .returncode == 0
75- assert result .stdout .strip () == "1.2.4"
80+ assert result .stdout .strip () == expected_version
7681
7782 # Check Cargo.toml was updated
7883 updated_cargo = cargo_path .read_text ()
79- assert 'version = "1.2.4 "' in updated_cargo
84+ assert f 'version = "{ expected_version } "' in updated_cargo
8085
8186 # Check changelog was updated
8287 updated_changelog = changelog_path .read_text ()
8388 assert "## UNRELEASED" in updated_changelog
84- assert "## 1.2.4 (" in updated_changelog
85-
86-
87- def test_bump_version_minor ():
88- """Test version bumping with minor increment."""
89- with tempfile .TemporaryDirectory () as temp_dir :
90- temp_path = Path (temp_dir )
91-
92- # Create mock Cargo.toml
93- cargo_content = '''[package]
94- name = "test-package"
95- version = "1.2.3"
96- edition = "2021"
97- '''
98- cargo_path = temp_path / "Cargo.toml"
99- cargo_path .write_text (cargo_content )
100-
101- # Create mock changelog
102- changelog_content = '''# Changelog
103-
104- ## UNRELEASED
105-
106- ## 1.2.3 (2024-01-01)
107-
108- - Some old change
109- '''
110- docs_dir = temp_path / "docs"
111- docs_dir .mkdir ()
112- changelog_path = docs_dir / "changelog.md"
113- changelog_path .write_text (changelog_content )
114-
115- # Run the script
116- result = subprocess .run ([sys .executable ,
117- str (Path (__file__ ).parent .parent .parent / "modify_changelog.py" ),
118- "bump_version" , "minor" ],
119- capture_output = True , text = True , cwd = temp_path )
120-
121- assert result .returncode == 0
122- assert result .stdout .strip () == "1.3.0"
123-
124- # Check Cargo.toml was updated
125- updated_cargo = cargo_path .read_text ()
126- assert 'version = "1.3.0"' in updated_cargo
127-
128-
129- def test_bump_version_major ():
130- """Test version bumping with major increment."""
131- with tempfile .TemporaryDirectory () as temp_dir :
132- temp_path = Path (temp_dir )
133-
134- # Create mock Cargo.toml
135- cargo_content = '''[package]
136- name = "test-package"
137- version = "1.2.3"
138- edition = "2021"
139- '''
140- cargo_path = temp_path / "Cargo.toml"
141- cargo_path .write_text (cargo_content )
142-
143- # Create mock changelog
144- changelog_content = '''# Changelog
145-
146- ## UNRELEASED
147-
148- ## 1.2.3 (2024-01-01)
149-
150- - Some old change
151- '''
152- docs_dir = temp_path / "docs"
153- docs_dir .mkdir ()
154- changelog_path = docs_dir / "changelog.md"
155- changelog_path .write_text (changelog_content )
156-
157- # Run the script
158- result = subprocess .run ([sys .executable ,
159- str (Path (__file__ ).parent .parent .parent / "modify_changelog.py" ),
160- "bump_version" , "major" ],
161- capture_output = True , text = True , cwd = temp_path )
162-
163- assert result .returncode == 0
164- assert result .stdout .strip () == "2.0.0"
165-
166- # Check Cargo.toml was updated
167- updated_cargo = cargo_path .read_text ()
168- assert 'version = "2.0.0"' in updated_cargo
89+ assert f"## { expected_version } (" in updated_changelog
16990
17091
17192def test_update_changelog_new_entry ():
@@ -202,7 +123,7 @@ def test_update_changelog_new_entry():
202123
203124
204125def test_update_changelog_duplicate_entry ():
205- """Test that duplicate PR entries are not added ."""
126+ """Test that modifying PR title updates the existing changelog entry instead of making a new one ."""
206127 with tempfile .TemporaryDirectory () as temp_dir :
207128 temp_path = Path (temp_dir )
208129
@@ -222,14 +143,20 @@ def test_update_changelog_duplicate_entry():
222143 changelog_path = docs_dir / "changelog.md"
223144 changelog_path .write_text (changelog_content )
224145
225- # Run the script
146+ # Run the script with updated title for same PR
226147 result = subprocess .run ([sys .executable ,
227148 str (Path (__file__ ).parent .parent .parent / "modify_changelog.py" ),
228- "update_changelog" , "123" , "Fix important bug" ],
149+ "update_changelog" , "123" , "Fix critical security bug" ],
229150 capture_output = True , text = True , cwd = temp_path )
230151
231- assert result .returncode == 1
232- assert "Changelog entry for PR #123 already exists" in result .stdout
152+ assert result .returncode == 0
153+ assert "Updated changelog entry for PR #123: Fix critical security bug" in result .stdout
154+
155+ # Check that the changelog was updated, not duplicated
156+ updated_changelog = changelog_path .read_text ()
157+ assert "- Fix critical security bug [#123](https://github.com/egraphs-good/egglog-python/pull/123)" in updated_changelog
158+ assert "- Fix important bug [#123]" not in updated_changelog # Old entry should be gone
159+ assert updated_changelog .count ("[#123]" ) == 1 # Should only have one entry for PR 123
233160
234161
235162def test_update_changelog_missing_file ():
0 commit comments