3636 _clean_up_files_after_post_processing ,
3737 _copy_files_needed_for_post_processing ,
3838 _create_main_version_header ,
39+ _get_library_dist_name ,
3940 _determine_library_namespace ,
4041 _get_library_id ,
4142 _get_libraries_to_prepare_for_release ,
5051 _update_changelog_for_library ,
5152 _update_global_changelog ,
5253 _update_version_for_library ,
54+ _verify_library_dist_name ,
5355 _verify_library_namespace ,
5456 _write_json_file ,
5557 _write_text_file ,
@@ -364,7 +366,6 @@ def test_run_nox_sessions_success(mocker, mock_generate_request_data_for_nox):
364366 "unit-3.9" ,
365367 "unit-3.13" ,
366368 "docs" ,
367- "system-3.13" ,
368369 "lint" ,
369370 "lint_setup_py" ,
370371 "mypy-3.13" ,
@@ -377,7 +378,6 @@ def test_run_nox_sessions_success(mocker, mock_generate_request_data_for_nox):
377378 mocker .call ("unit-3.9" , "mock-library" , "repo" ),
378379 mocker .call ("unit-3.13" , "mock-library" , "repo" ),
379380 mocker .call ("docs" , "mock-library" , "repo" ),
380- mocker .call ("system-3.13" , "mock-library" , "repo" ),
381381 mocker .call ("lint" , "mock-library" , "repo" ),
382382 mocker .call ("lint_setup_py" , "mock-library" , "repo" ),
383383 mocker .call ("mypy-3.13" , "mock-library" , "repo" ),
@@ -430,7 +430,8 @@ def test_handle_build_success(caplog, mocker, mock_build_request_file):
430430 caplog .set_level (logging .INFO )
431431
432432 mocker .patch ("cli._run_nox_sessions" )
433- mocker .patch ("cli._verify_library_namespace" , return_value = True )
433+ mocker .patch ("cli._verify_library_namespace" )
434+ mocker .patch ("cli._verify_library_dist_name" )
434435 handle_build ()
435436
436437 assert "'build' command executed." in caplog .text
@@ -507,14 +508,44 @@ def test_handle_release_init_success(mocker, mock_release_init_request_file):
507508 handle_release_init ()
508509
509510
510- def test_handle_release_init_fail ():
511+ def test_handle_release_init_fail_value_error_file ():
511512 """
512513 Tests that handle_release_init fails to read `librarian/release-init-request.json`.
513514 """
514- with pytest .raises (ValueError ):
515+ with pytest .raises (ValueError , match = "No such file or directory" ):
515516 handle_release_init ()
516517
517518
519+ def test_handle_release_init_fail_value_error_version (mocker ):
520+ m = mock_open ()
521+
522+ mock_release_init_request_content = {
523+ "libraries" : [
524+ {
525+ "id" : "google-cloud-language" ,
526+ "apis" : [{"path" : "google/cloud/language/v1" }],
527+ "release_triggered" : True ,
528+ "version" : "1.2.2" ,
529+ "changes" : [],
530+ },
531+ ]
532+ }
533+ with unittest .mock .patch ("cli.open" , m ):
534+ mocker .patch (
535+ "cli._get_libraries_to_prepare_for_release" ,
536+ return_value = mock_release_init_request_content ["libraries" ],
537+ )
538+ mocker .patch ("cli._get_previous_version" , return_value = "1.2.2" )
539+ mocker .patch ("cli._process_changelog" , return_value = None )
540+ mocker .patch (
541+ "cli._read_json_file" , return_value = mock_release_init_request_content
542+ )
543+ with pytest .raises (
544+ ValueError , match = "is the same as the version in state.yaml"
545+ ):
546+ handle_release_init ()
547+
548+
518549def test_read_valid_text_file (mocker ):
519550 """Tests reading a valid text file."""
520551 mock_content = "some text"
@@ -797,6 +828,26 @@ def test_determine_library_namespace_fails_not_subpath():
797828 _determine_library_namespace (gapic_parent_path , pkg_root_path )
798829
799830
831+ def test_get_library_dist_name_success (mocker ):
832+ mock_metadata = {"name" : "my-lib" , "version" : "1.0.0" }
833+ mocker .patch ("build.util.project_wheel_metadata" , return_value = mock_metadata )
834+ assert _get_library_dist_name ("my-lib" , "repo" ) == "my-lib"
835+
836+
837+ def test_verify_library_dist_name_setup_success (mocker ):
838+ """Tests success when a library distribution name in setup.py is valid."""
839+ mock_setup_file = mocker .patch ("cli._get_library_dist_name" , return_value = "my-lib" )
840+ _verify_library_dist_name ("my-lib" , "repo" )
841+ mock_setup_file .assert_called_once_with ("my-lib" , "repo" )
842+
843+
844+ def test_verify_library_dist_name_fail (mocker ):
845+ """Tests failure when a library-id does not match the libary distribution name."""
846+ mocker .patch ("cli._get_library_dist_name" , return_value = "invalid-lib" )
847+ with pytest .raises (ValueError ):
848+ _verify_library_dist_name ("my-lib" , "repo" )
849+
850+
800851def test_verify_library_namespace_success_valid (mocker , mock_path_class ):
801852 """Tests success when a single valid namespace is found."""
802853 # 1. Get the mock instance from the mock class's return_value
0 commit comments