@@ -37,26 +37,31 @@ def test_update_changelog_subcommand_help():
37
37
assert "Pull request title" in result .stdout
38
38
39
39
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."""
42
47
with tempfile .TemporaryDirectory () as temp_dir :
43
48
temp_path = Path (temp_dir )
44
49
45
50
# Create mock Cargo.toml
46
- cargo_content = '''[package]
51
+ cargo_content = f '''[package]
47
52
name = "test-package"
48
- version = "1.2.3 "
53
+ version = "{ start_version } "
49
54
edition = "2021"
50
55
'''
51
56
cargo_path = temp_path / "Cargo.toml"
52
57
cargo_path .write_text (cargo_content )
53
58
54
59
# Create mock changelog
55
- changelog_content = '''# Changelog
60
+ changelog_content = f '''# Changelog
56
61
57
62
## UNRELEASED
58
63
59
- ## 1.2.3 (2024-01-01)
64
+ ## { start_version } (2024-01-01)
60
65
61
66
- Some old change
62
67
'''
@@ -68,104 +73,20 @@ def test_bump_version_patch():
68
73
# Run the script
69
74
result = subprocess .run ([sys .executable ,
70
75
str (Path (__file__ ).parent .parent .parent / "modify_changelog.py" ),
71
- "bump_version" , "patch" ],
76
+ "bump_version" , bump_type ],
72
77
capture_output = True , text = True , cwd = temp_path )
73
78
74
79
assert result .returncode == 0
75
- assert result .stdout .strip () == "1.2.4"
80
+ assert result .stdout .strip () == expected_version
76
81
77
82
# Check Cargo.toml was updated
78
83
updated_cargo = cargo_path .read_text ()
79
- assert 'version = "1.2.4 "' in updated_cargo
84
+ assert f 'version = "{ expected_version } "' in updated_cargo
80
85
81
86
# Check changelog was updated
82
87
updated_changelog = changelog_path .read_text ()
83
88
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
169
90
170
91
171
92
def test_update_changelog_new_entry ():
@@ -202,7 +123,7 @@ def test_update_changelog_new_entry():
202
123
203
124
204
125
def 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 ."""
206
127
with tempfile .TemporaryDirectory () as temp_dir :
207
128
temp_path = Path (temp_dir )
208
129
@@ -222,14 +143,20 @@ def test_update_changelog_duplicate_entry():
222
143
changelog_path = docs_dir / "changelog.md"
223
144
changelog_path .write_text (changelog_content )
224
145
225
- # Run the script
146
+ # Run the script with updated title for same PR
226
147
result = subprocess .run ([sys .executable ,
227
148
str (Path (__file__ ).parent .parent .parent / "modify_changelog.py" ),
228
- "update_changelog" , "123" , "Fix important bug" ],
149
+ "update_changelog" , "123" , "Fix critical security bug" ],
229
150
capture_output = True , text = True , cwd = temp_path )
230
151
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
233
160
234
161
235
162
def test_update_changelog_missing_file ():
0 commit comments