Skip to content

Commit

Permalink
test: add bitbucket to hvcs parameter list & bitbucket to configs
Browse files Browse the repository at this point in the history
  • Loading branch information
codejedi365 committed Mar 2, 2024
1 parent ff082fa commit d6c2106
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
15 changes: 14 additions & 1 deletion tests/fixtures/example_project.py
Expand Up @@ -14,7 +14,7 @@
ScipyCommitParser,
TagCommitParser,
)
from semantic_release.hvcs import Gitea, Github, Gitlab
from semantic_release.hvcs import Gitea, Github, Gitlab, Bitbucket

from tests.const import (
EXAMPLE_CHANGELOG_MD_CONTENT,
Expand Down Expand Up @@ -352,3 +352,16 @@ def _use_gitea_hvcs(domain: str | None = None) -> type[HvcsBase]:
return Gitea

return _use_gitea_hvcs


@pytest.fixture(scope="session")
def use_bitbucket_hvcs(update_pyproject_toml: UpdatePyprojectTomlFn) -> UseHvcsFn:
"""Modify the configuration file to use BitBucket as the HVCS."""

def _use_bitbucket_hvcs(domain: str | None = None) -> type[HvcsBase]:
update_pyproject_toml("tool.semantic_release.remote.type", "bitbucket")
if domain is not None:
update_pyproject_toml("tool.semantic_release.remote.domain", domain)
return Bitbucket

return _use_bitbucket_hvcs
3 changes: 3 additions & 0 deletions tests/fixtures/git_repo.py
Expand Up @@ -252,6 +252,7 @@ def build_configured_base_repo(
use_github_hvcs: UseHvcsFn,
use_gitlab_hvcs: UseHvcsFn,
use_gitea_hvcs: UseHvcsFn,
use_bitbucket_hvcs: UseHvcsFn,
use_angular_parser: UseParserFn,
use_emoji_parser: UseParserFn,
use_scipy_parser: UseParserFn,
Expand Down Expand Up @@ -301,6 +302,8 @@ def _build_configured_base_repo(
hvcs_class = use_gitlab_hvcs(hvcs_domain)
elif hvcs_client_name == "gitea":
hvcs_class = use_gitea_hvcs(hvcs_domain)
elif hvcs_client_name == "bitbucket":
hvcs_class = use_bitbucket_hvcs(hvcs_domain)
else:
raise ValueError(f"Unknown HVCS client name: {hvcs_client_name}")

Expand Down
14 changes: 7 additions & 7 deletions tests/unit/semantic_release/changelog/test_default_changelog.py
Expand Up @@ -16,7 +16,7 @@
from semantic_release.changelog.template import environment
from semantic_release.commit_parser import ParsedCommit
from semantic_release.enums import LevelBump
from semantic_release.hvcs import Gitea, Github, Gitlab
from semantic_release.hvcs import Gitea, Github, Gitlab, Bitbucket
from semantic_release.version.translator import Version

from tests.const import TODAY_DATE_STR
Expand Down Expand Up @@ -92,7 +92,7 @@ def artificial_release_history(commit_author: Actor):
)


@pytest.mark.parametrize("hvcs_client", [Github, Gitlab, Gitea])
@pytest.mark.parametrize("hvcs_client", [Github, Gitlab, Gitea, Bitbucket])
def test_default_changelog_template(
default_changelog_template: str,
hvcs_client: type[HvcsBase],
Expand All @@ -106,11 +106,11 @@ def test_default_changelog_template(

feat_commit_obj = artificial_release_history.released[version]["elements"]["feature"][0]
feat_commit_url = hvcs_client(example_git_https_url).commit_hash_url(feat_commit_obj.commit.hexsha)
feat_description = str.join('\n', feat_commit_obj.descriptions)
feat_description = str.join('\n', feat_commit_obj.descriptions) # type: ignore

fix_commit_obj = artificial_release_history.released[version]["elements"]["fix"][0]
fix_commit_url = hvcs_client(example_git_https_url).commit_hash_url(fix_commit_obj.commit.hexsha)
fix_description = str.join('\n', fix_commit_obj.descriptions)
fix_description = str.join('\n', fix_commit_obj.descriptions) # type: ignore

expected_changelog = str.join("\n", [
"# CHANGELOG",
Expand All @@ -131,7 +131,7 @@ def test_default_changelog_template(
assert expected_changelog == actual_changelog


@pytest.mark.parametrize("hvcs_client", [Github, Gitlab, Gitea])
@pytest.mark.parametrize("hvcs_client", [Github, Gitlab, Gitea, Bitbucket])
def test_default_changelog_template_w_unreleased_changes(
default_changelog_template: str,
hvcs_client: type[HvcsBase],
Expand All @@ -143,11 +143,11 @@ def test_default_changelog_template_w_unreleased_changes(

feat_commit_obj = artificial_release_history.released[version]["elements"]["feature"][0]
feat_commit_url = hvcs_client(example_git_https_url).commit_hash_url(feat_commit_obj.commit.hexsha)
feat_description = str.join('\n', feat_commit_obj.descriptions)
feat_description = str.join('\n', feat_commit_obj.descriptions) # type: ignore

fix_commit_obj = artificial_release_history.released[version]["elements"]["fix"][0]
fix_commit_url = hvcs_client(example_git_https_url).commit_hash_url(fix_commit_obj.commit.hexsha)
fix_description = str.join('\n', fix_commit_obj.descriptions)
fix_description = str.join('\n', fix_commit_obj.descriptions) # type: ignore

expected_changelog = str.join("\n", [
"# CHANGELOG",
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/semantic_release/changelog/test_release_notes.py
Expand Up @@ -17,7 +17,7 @@
from semantic_release.changelog.template import environment
from semantic_release.commit_parser import ParsedCommit
from semantic_release.enums import LevelBump
from semantic_release.hvcs import Gitea, Github, Gitlab
from semantic_release.hvcs import Gitea, Github, Gitlab, Bitbucket
from semantic_release.version import Version

from tests.const import TODAY_DATE_STR
Expand Down Expand Up @@ -72,7 +72,7 @@ def release_notes_template() -> str:
return version_notes_template.read_text(encoding="utf-8")


@pytest.mark.parametrize("hvcs_client", [Github, Gitlab, Gitea])
@pytest.mark.parametrize("hvcs_client", [Github, Gitlab, Gitea, Bitbucket])
def test_default_release_notes_template(
example_git_https_url: str,
hvcs_client: type[HvcsBase],
Expand All @@ -88,7 +88,7 @@ def test_default_release_notes_template(
version = Version.parse(version_str)
commit_obj = artificial_release_history.released[version]["elements"]["fix"][0]
commit_url = hvcs_client(example_git_https_url).commit_hash_url(commit_obj.commit.hexsha)
commit_description = str.join('\n', commit_obj.descriptions)
commit_description = str.join('\n', commit_obj.descriptions) # type: ignore
expected_content = str.join("\n", [
f"# v{version_str} ({TODAY_DATE_STR})",
"## Fix",
Expand Down

0 comments on commit d6c2106

Please sign in to comment.