@@ -143,3 +143,67 @@ def test_commit_and_tag_from_below_scm_root(repo: str, scm_command: str, scm_cla
143
143
assert tag_info .distance_to_latest_tag == 0
144
144
assert tag_info .current_version == "30.1.0"
145
145
assert tag_info .dirty is False
146
+
147
+
148
+ # write tests for no-commit, no-tag and dry-run
149
+ @pytest .mark .parametrize (
150
+ ["repo" , "scm_command" , "scm_class" ],
151
+ [
152
+ param ("git_repo" , "git" , scm .Git , id = "git" ),
153
+ param ("hg_repo" , "hg" , scm .Mercurial , id = "hg" ),
154
+ ],
155
+ )
156
+ @pytest .mark .parametrize (
157
+ ["commit" , "tag" , "dry_run" , "should_commit" , "should_tag" ],
158
+ [
159
+ param (True , True , True , False , False , id = "dry-run-stops-commit-and-tag" ),
160
+ param (True , False , False , True , False , id = "commit-no-tag" ),
161
+ param (False , True , False , False , False , id = "no-commit-stops-tag" ),
162
+ ],
163
+ )
164
+ def test_commit_tag_dry_run_interactions (
165
+ repo : str ,
166
+ scm_command : str ,
167
+ scm_class : scm .SourceCodeManager ,
168
+ commit : bool ,
169
+ tag : bool ,
170
+ dry_run : bool ,
171
+ should_commit : bool ,
172
+ should_tag : bool ,
173
+ caplog : LogCaptureFixture ,
174
+ request ,
175
+ ):
176
+ """Combinations of commit, tag, dry-run and should produce the expected results."""
177
+ # Arrange
178
+ repo_path : Path = request .getfixturevalue (repo )
179
+ version_path = repo_path / "VERSION"
180
+ version_path .write_text ("30.0.3" )
181
+
182
+ overrides = {"current_version" : "30.0.3" , "commit" : commit , "tag" : tag , "files" : [{"filename" : str (version_path )}]}
183
+ context = {
184
+ "current_version" : "30.0.3" ,
185
+ "new_version" : "30.1.0" ,
186
+ }
187
+ with inside_dir (repo_path ):
188
+ conf , version_config , current_version = get_config_data (overrides )
189
+ subprocess .run ([scm_command , "add" , "VERSION" ], check = True , capture_output = True )
190
+ subprocess .run ([scm_command , "commit" , "-m" , "initial commit" ], check = True , capture_output = True )
191
+ version_path .write_text ("30.1.0" )
192
+ # Act
193
+ scm_class .commit_to_scm (files = [version_path ], config = conf , context = context , dry_run = dry_run )
194
+ scm_class .tag_in_scm (config = conf , context = context , dry_run = dry_run )
195
+
196
+ # Assert
197
+ if commit and dry_run :
198
+ assert "Would commit" in caplog .text
199
+ elif should_commit :
200
+ assert "Committing " in caplog .text
201
+ else :
202
+ assert "Would not commit" in caplog .text
203
+
204
+ if tag and dry_run :
205
+ assert "Would tag" in caplog .text
206
+ elif should_tag :
207
+ assert "Tagging " in caplog .text
208
+ else :
209
+ assert "Would not tag" in caplog .text
0 commit comments