@@ -312,6 +312,7 @@ def test_handle_configure_no_new_library(mocker):
312312 with pytest .raises (ValueError , match = "Configuring a new library failed." ):
313313 handle_configure ()
314314
315+
315316def test_create_new_changelog_for_library (mocker ):
316317 """Tests that the changelog files are created correctly."""
317318 library_id = "google-cloud-language"
@@ -325,7 +326,9 @@ def test_create_new_changelog_for_library(mocker):
325326 docs_changelog_path = f"{ output } /packages/{ library_id } /docs/CHANGELOG.md"
326327
327328 # Check that makedirs was called for both parent directories
328- mock_makedirs .assert_any_call (os .path .dirname (package_changelog_path ), exist_ok = True )
329+ mock_makedirs .assert_any_call (
330+ os .path .dirname (package_changelog_path ), exist_ok = True
331+ )
329332 mock_makedirs .assert_any_call (os .path .dirname (docs_changelog_path ), exist_ok = True )
330333 assert mock_makedirs .call_count == 2
331334
@@ -1141,29 +1144,60 @@ def test_get_previous_version_failure(mock_state_file):
11411144 _get_previous_version ("google-cloud-does-not-exist" , LIBRARIAN_DIR )
11421145
11431146
1144- def test_update_changelog_for_library_success (mocker ):
1145- m = mock_open ()
1146-
1147+ def test_update_changelog_for_library_writes_both_changelogs (mocker ):
1148+ """Tests that _update_changelog_for_library writes to both changelogs."""
11471149 mock_content = """# Changelog
11481150
11491151[PyPI History][1]
11501152
11511153[1]: https://pypi.org/project/google-cloud-language/#history
1154+ """
1155+ mock_read = mocker .patch ("cli._read_text_file" , return_value = mock_content )
1156+ mock_write = mocker .patch ("cli._write_text_file" )
1157+ mock_path_exists = mocker .patch ("cli.os.path.lexists" , return_value = True )
1158+ _update_changelog_for_library (
1159+ "repo" ,
1160+ "output" ,
1161+ _MOCK_LIBRARY_CHANGES ,
1162+ "1.2.3" ,
1163+ "1.2.2" ,
1164+ "google-cloud-language" ,
1165+ is_mono_repo = True ,
1166+ )
11521167
1153- ## [2.17.2](https://github.com/googleapis/google-cloud-python/compare/google-cloud-language-v2.17.1...google-cloud-language-v2.17.2) (2025-06-11)
1168+ assert mock_write .call_count == 2
1169+ mock_write .assert_any_call (
1170+ "output/packages/google-cloud-language/CHANGELOG.md" , mocker .ANY
1171+ )
1172+ mock_write .assert_any_call (
1173+ "output/packages/google-cloud-language/docs/CHANGELOG.md" , mocker .ANY
1174+ )
11541175
1176+
1177+ def test_update_changelog_for_library_single_repo (mocker ):
1178+ """Tests that _update_changelog_for_library writes to both changelogs in a single repo."""
1179+ mock_content = """# Changelog
1180+
1181+ [PyPI History][1]
1182+
1183+ [1]: https://pypi.org/project/google-cloud-language/#history
11551184"""
1156- with unittest .mock .patch ("cli.open" , m ):
1157- mocker .patch ("cli._read_text_file" , return_value = mock_content )
1158- _update_changelog_for_library (
1159- "repo" ,
1160- "output" ,
1161- _MOCK_LIBRARY_CHANGES ,
1162- "1.2.3" ,
1163- "1.2.2" ,
1164- "google-cloud-language" ,
1165- "CHANGELOG.md" ,
1166- )
1185+ mock_read = mocker .patch ("cli._read_text_file" , return_value = mock_content )
1186+ mock_write = mocker .patch ("cli._write_text_file" )
1187+ mock_path_exists = mocker .patch ("cli.os.path.lexists" , return_value = True )
1188+ _update_changelog_for_library (
1189+ "repo" ,
1190+ "output" ,
1191+ _MOCK_LIBRARY_CHANGES ,
1192+ "1.2.3" ,
1193+ "1.2.2" ,
1194+ "google-cloud-language" ,
1195+ is_mono_repo = False ,
1196+ )
1197+
1198+ assert mock_write .call_count == 2
1199+ mock_write .assert_any_call ("output/CHANGELOG.md" , mocker .ANY )
1200+ mock_write .assert_any_call ("output/docs/CHANGELOG.md" , mocker .ANY )
11671201
11681202
11691203def test_process_changelog_success ():
0 commit comments