Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .generator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ def _get_new_library_config(request_data: Dict) -> Dict:
return {}


def _add_new_library_version(
library_config: Dict
) -> None:
"""Adds the library version to the configuration if it's not present.

Args:
library_config(Dict): The library configuration.
"""
if "version" not in library_config or not library_config["version"]:
library_config["version"] = "0.0.0"


def _prepare_new_library_config(library_config: Dict) -> Dict:
"""
Prepares the new library's configuration by removing temporary keys and
Expand All @@ -209,6 +221,7 @@ def _prepare_new_library_config(library_config: Dict) -> Dict:
_add_new_library_preserve_regex(library_config, library_id)
_add_new_library_remove_regex(library_config, library_id)
_add_new_library_tag_format(library_config)
_add_new_library_version(library_config)

return library_config

Expand Down
24 changes: 22 additions & 2 deletions .generator/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
_get_libraries_to_prepare_for_release,
_get_new_library_config,
_get_previous_version,
_add_new_library_version,
_prepare_new_library_config,
_process_changelog,
_process_version_file,
Expand Down Expand Up @@ -171,6 +172,7 @@ def mock_configure_request_data():
{
"id": "google-cloud-language",
"apis": [{"path": "google/cloud/language/v1", "status": "new"}],
"version": "",
}
]
}
Expand Down Expand Up @@ -317,14 +319,15 @@ def test_get_new_library_config_empty_input():
assert config == {}


def test_prepare_new_library_config():
def test_prepare_new_library_config(mocker):
"""Tests the preparation of a new library's configuration."""
raw_config = {
"id": "google-cloud-language",
"apis": [{"path": "google/cloud/language/v1", "status": "new"}],
"source_roots": None,
"preserve_regex": None,
"remove_regex": None,
"version": "",
}

prepared_config = _prepare_new_library_config(raw_config)
Expand All @@ -336,9 +339,10 @@ def test_prepare_new_library_config():
assert "packages/google-cloud-language/CHANGELOG.md" in prepared_config["preserve_regex"]
assert prepared_config["remove_regex"] == ["packages/google-cloud-language"]
assert prepared_config["tag_format"] == "{{id}}-v{{version}}"
assert prepared_config["version"] == "0.0.0"


def test_prepare_new_library_config_preserves_existing_values():
def test_prepare_new_library_config_preserves_existing_values(mocker):
"""Tests that existing values in the config are not overwritten."""
raw_config = {
"id": "google-cloud-language",
Expand All @@ -347,6 +351,7 @@ def test_prepare_new_library_config_preserves_existing_values():
"preserve_regex": ["custom/regex"],
"remove_regex": ["custom/remove"],
"tag_format": "custom-format-{{version}}",
"version": "4.5.6",
}

prepared_config = _prepare_new_library_config(raw_config)
Expand All @@ -358,6 +363,21 @@ def test_prepare_new_library_config_preserves_existing_values():
assert prepared_config["preserve_regex"] == ["custom/regex"]
assert prepared_config["remove_regex"] == ["custom/remove"]
assert prepared_config["tag_format"] == "custom-format-{{version}}"
assert prepared_config["version"] == "4.5.6"


def test_add_new_library_version_populates_version(mocker):
"""Tests that the version is populated if it's missing."""
config = {"version": ""}
_add_new_library_version(config)
assert config["version"] == "0.0.0"


def test_add_new_library_version_preserves_version():
"""Tests that an existing version is preserved."""
config = {"version": "4.5.6"}
_add_new_library_version(config)
assert config["version"] == "4.5.6"


def test_get_library_id_success():
Expand Down
Loading