|
37 | 37 | _copy_files_needed_for_post_processing, |
38 | 38 | _create_main_version_header, |
39 | 39 | _determine_bazel_rule, |
| 40 | + _get_library_dist_name, |
40 | 41 | _determine_library_namespace, |
41 | 42 | _get_library_id, |
42 | 43 | _get_libraries_to_prepare_for_release, |
43 | 44 | _get_previous_version, |
44 | | - _get_setup_dist_name, |
45 | | - _get_toml_dist_name, |
46 | 45 | _locate_and_extract_artifact, |
47 | 46 | _process_changelog, |
48 | 47 | _process_version_file, |
@@ -926,66 +925,22 @@ def test_determine_library_namespace_fails_not_subpath(): |
926 | 925 | _determine_library_namespace(gapic_parent_path, pkg_root_path) |
927 | 926 |
|
928 | 927 |
|
929 | | -def test_get_setup_dist_name_exists(mocker): |
930 | | - """Tests that a valid library distribution name exists in `pyproject.toml`.""" |
931 | | - mock_dist = MagicMock() |
932 | | - mock_dist.get_name.return_value = "my-lib" |
933 | | - mocker.patch("cli.run_setup", return_value=mock_dist) |
934 | | - assert _get_setup_dist_name("my-lib", "repo") == "my-lib" |
935 | | - |
936 | | - |
937 | | -def test_get_setup_dist_name_file_not_found(caplog): |
938 | | - """Tests that distribution name is None if `setup.py` does not exist.""" |
939 | | - caplog.set_level(logging.DEBUG) |
940 | | - assert _get_setup_dist_name("my-lib", "repo") is None |
941 | | - assert len(caplog.records) == 1 |
942 | | - |
943 | | - |
944 | | -def test_get_toml_dist_name_exists(mocker): |
945 | | - """Tests that a valid library distribution name exists in `pyproject.toml`.""" |
946 | | - mock_data = {"project": {"name": "my-lib"}} |
947 | | - mocker.patch("tomli.load", return_value=mock_data) |
948 | | - mocker.patch("builtins.open", mocker.mock_open(read_data=b"fake toml data")) |
949 | | - assert _get_toml_dist_name("my-lib", "repo") == "my-lib" |
950 | | - |
951 | | - |
952 | | -def test_get_toml_dist_name_file_not_found(caplog): |
953 | | - """Tests that distribution name is None if `pyproject.toml` does not exist.""" |
954 | | - caplog.set_level(logging.DEBUG) |
955 | | - assert _get_toml_dist_name("my-lib", "repo") is None |
956 | | - assert len(caplog.records) == 1 |
| 928 | +def test_get_library_dist_name_success(mocker): |
| 929 | + mock_metadata = {"name": "my-lib", "version": "1.0.0"} |
| 930 | + mocker.patch("build.util.project_wheel_metadata", return_value=mock_metadata) |
| 931 | + assert _get_library_dist_name("my-lib", "repo") == "my-lib" |
957 | 932 |
|
958 | 933 |
|
959 | 934 | def test_verify_library_dist_name_setup_success(mocker): |
960 | 935 | """Tests success when a library distribution name in setup.py is valid.""" |
961 | | - mock_setup_file = mocker.patch("cli._get_setup_dist_name", return_value="my-lib") |
| 936 | + mock_setup_file = mocker.patch("cli._get_library_dist_name", return_value="my-lib") |
962 | 937 | _verify_library_dist_name("my-lib", "repo") |
963 | 938 | mock_setup_file.assert_called_once_with("my-lib", "repo") |
964 | 939 |
|
965 | 940 |
|
966 | | -def test_verify_library_dist_name_setup_success(mocker): |
967 | | - """Tests success when a library distribution name in toml is valid.""" |
968 | | - mock_toml_file = mocker.patch("cli._get_toml_dist_name", return_value="my-lib") |
969 | | - _verify_library_dist_name("my-lib", "repo") |
970 | | - mock_toml_file.assert_called_once_with("my-lib", "repo") |
971 | | - |
972 | | - |
973 | | -def test_verify_library_dist_name_fail(): |
974 | | - """Tests failure when a library does not have a `setup.py` or `pyproject.toml`.""" |
975 | | - with pytest.raises(ValueError): |
976 | | - _verify_library_dist_name("my-lib", "repo") |
977 | | - |
978 | | - |
979 | | -def test_verify_library_dist_name_setup_fail(mocker): |
980 | | - """Tests failure when a library has an invalid distribution name in `setup.py`.""" |
981 | | - mocker.patch("cli._get_setup_dist_name", return_value="invalid-lib-name") |
982 | | - with pytest.raises(ValueError): |
983 | | - _verify_library_dist_name("my-lib", "repo") |
984 | | - |
985 | | - |
986 | | -def test_verify_library_dist_name_toml_fail(mocker): |
987 | | - """Tests failure when a library has an invalid distribution name in `pyproject.toml`.""" |
988 | | - mocker.patch("cli._get_toml_dist_name", return_value="invalid-lib-name") |
| 941 | +def test_verify_library_dist_name_fail(mocker): |
| 942 | + """Tests failure when a library-id does not match the libary distribution name.""" |
| 943 | + mocker.patch("cli._get_library_dist_name", return_value="invalid-lib") |
989 | 944 | with pytest.raises(ValueError): |
990 | 945 | _verify_library_dist_name("my-lib", "repo") |
991 | 946 |
|
|
0 commit comments