- Notifications
You must be signed in to change notification settings - Fork262
test(cmd-version): add fixture to reproduce issue with empty changelog#1268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
codejedi365 merged 1 commit intopython-semantic-release:masterfromdzmitrysliaptsou:test/add-fixtures-merge-to-feature-after-releaseJun 20, 2025
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletionstests/const.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletionstests/e2e/cmd_version/bump_version/github_flow/test_repo_1_channel_branch_update_merge.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| from __future__ import annotations | ||
| from typing import TYPE_CHECKING | ||
| import pytest | ||
| import tomlkit | ||
| from flatdict import FlatDict | ||
| from freezegun import freeze_time | ||
| from tests.const import ( | ||
| DEFAULT_BRANCH_NAME, | ||
| ) | ||
| from tests.fixtures.repos.github_flow import ( | ||
| repo_w_github_flow_w_default_release_n_branch_update_merge_conventional_commits, | ||
| repo_w_github_flow_w_default_release_n_branch_update_merge_emoji_commits, | ||
| repo_w_github_flow_w_default_release_n_branch_update_merge_scipy_commits, | ||
| ) | ||
| from tests.util import temporary_working_directory | ||
| if TYPE_CHECKING: | ||
| from pathlib import Path | ||
| from unittest.mock import MagicMock | ||
| from requests_mock import Mocker | ||
| from tests.e2e.cmd_version.bump_version.conftest import ( | ||
| InitMirrorRepo4RebuildFn, | ||
| RunPSReleaseFn, | ||
| ) | ||
| from tests.e2e.conftest import GetSanitizedChangelogContentFn | ||
| from tests.fixtures.example_project import ExProjectDir | ||
| from tests.fixtures.git_repo import ( | ||
| BuildRepoFromDefinitionFn, | ||
| BuildSpecificRepoFn, | ||
| CommitConvention, | ||
| GetGitRepo4DirFn, | ||
| RepoActionConfigure, | ||
| RepoActionRelease, | ||
| RepoActions, | ||
| SplitRepoActionsByReleaseTagsFn, | ||
| ) | ||
| @pytest.mark.xfail( | ||
| reason="Should pass after [#1252](https://github.com/python-semantic-release/python-semantic-release/issues/1252) is fixed", | ||
| ) | ||
| @pytest.mark.parametrize( | ||
| "repo_fixture_name", | ||
| [ | ||
| pytest.param(repo_fixture_name, marks=pytest.mark.comprehensive) | ||
| for repo_fixture_name in [ | ||
| repo_w_github_flow_w_default_release_n_branch_update_merge_conventional_commits.__name__, | ||
| repo_w_github_flow_w_default_release_n_branch_update_merge_emoji_commits.__name__, | ||
| repo_w_github_flow_w_default_release_n_branch_update_merge_scipy_commits.__name__, | ||
| ] | ||
| ], | ||
| ) | ||
| def test_github_flow_repo_w_default_release_n_branch_update_merge( | ||
| repo_fixture_name: str, | ||
| run_psr_release: RunPSReleaseFn, | ||
| build_github_flow_repo_w_default_release_n_branch_update_merge: BuildSpecificRepoFn, | ||
| split_repo_actions_by_release_tags: SplitRepoActionsByReleaseTagsFn, | ||
| init_mirror_repo_for_rebuild: InitMirrorRepo4RebuildFn, | ||
| example_project_dir: ExProjectDir, | ||
| git_repo_for_directory: GetGitRepo4DirFn, | ||
| build_repo_from_definition: BuildRepoFromDefinitionFn, | ||
| mocked_git_push: MagicMock, | ||
| post_mocker: Mocker, | ||
| default_tag_format_str: str, | ||
| version_py_file: Path, | ||
| get_sanitized_md_changelog_content: GetSanitizedChangelogContentFn, | ||
| get_sanitized_rst_changelog_content: GetSanitizedChangelogContentFn, | ||
| ): | ||
| # build target repo into a temporary directory | ||
| target_repo_dir = example_project_dir / repo_fixture_name | ||
| commit_type: CommitConvention = ( | ||
| repo_fixture_name.split("commits", 1)[0].split("_")[-2] # type: ignore[assignment] | ||
| ) | ||
| target_repo_definition = ( | ||
| build_github_flow_repo_w_default_release_n_branch_update_merge( | ||
| repo_name=repo_fixture_name, | ||
| commit_type=commit_type, | ||
| dest_dir=target_repo_dir, | ||
| ) | ||
| ) | ||
| target_git_repo = git_repo_for_directory(target_repo_dir) | ||
| target_repo_pyproject_toml = FlatDict( | ||
| tomlkit.loads((target_repo_dir / "pyproject.toml").read_text(encoding="utf-8")), | ||
| delimiter=".", | ||
| ) | ||
| tag_format_str: str = target_repo_pyproject_toml.get( # type: ignore[assignment] | ||
| "tool.semantic_release.tag_format", | ||
| default_tag_format_str, | ||
| ) | ||
| # split repo actions by release actions | ||
| releasetags_2_steps: dict[str, list[RepoActions]] = ( | ||
| split_repo_actions_by_release_tags(target_repo_definition, tag_format_str) | ||
| ) | ||
| configuration_step: RepoActionConfigure = releasetags_2_steps.pop("")[0] # type: ignore[assignment] | ||
| # Create the mirror repo directory | ||
| mirror_repo_dir = init_mirror_repo_for_rebuild( | ||
| mirror_repo_dir=(example_project_dir / "mirror"), | ||
| configuration_step=configuration_step, | ||
| ) | ||
| mirror_git_repo = git_repo_for_directory(mirror_repo_dir) | ||
| # rebuild repo from scratch stopping before each release tag | ||
| for curr_release_tag, steps in releasetags_2_steps.items(): | ||
| # make sure mocks are clear | ||
| mocked_git_push.reset_mock() | ||
| post_mocker.reset_mock() | ||
| # Extract expected result from target repo | ||
| head_reference_name = ( | ||
| curr_release_tag | ||
| if curr_release_tag != "Unreleased" | ||
| else DEFAULT_BRANCH_NAME | ||
| ) | ||
| target_git_repo.git.checkout(head_reference_name, detach=True) | ||
| expected_md_changelog_content = get_sanitized_md_changelog_content( | ||
| repo_dir=target_repo_dir | ||
| ) | ||
| expected_rst_changelog_content = get_sanitized_rst_changelog_content( | ||
| repo_dir=target_repo_dir | ||
| ) | ||
| expected_pyproject_toml_content = ( | ||
| target_repo_dir / "pyproject.toml" | ||
| ).read_text() | ||
| expected_version_file_content = (target_repo_dir / version_py_file).read_text() | ||
| expected_release_commit_text = target_git_repo.head.commit.message | ||
| # In our repo env, start building the repo from the definition | ||
| build_repo_from_definition( | ||
| dest_dir=mirror_repo_dir, | ||
| repo_construction_steps=steps[:-1], # stop before the release step | ||
| ) | ||
| release_action_step: RepoActionRelease = steps[-1] # type: ignore[assignment] | ||
| # Act: run PSR on the repo instead of the RELEASE step | ||
| with freeze_time( | ||
| release_action_step["details"]["datetime"] | ||
| ), temporary_working_directory(mirror_repo_dir): | ||
| run_psr_release( | ||
| next_version_str=release_action_step["details"]["version"], | ||
| git_repo=mirror_git_repo, | ||
| ) | ||
| # take measurement after running the version command | ||
| actual_release_commit_text = mirror_git_repo.head.commit.message | ||
| actual_pyproject_toml_content = (mirror_repo_dir / "pyproject.toml").read_text() | ||
| actual_version_file_content = (mirror_repo_dir / version_py_file).read_text() | ||
| actual_md_changelog_content = get_sanitized_md_changelog_content( | ||
| repo_dir=mirror_repo_dir | ||
| ) | ||
| actual_rst_changelog_content = get_sanitized_rst_changelog_content( | ||
| repo_dir=mirror_repo_dir | ||
| ) | ||
| # Evaluate (normal release actions should have occurred as expected) | ||
| # ------------------------------------------------------------------ | ||
| # Make sure version file is updated | ||
| assert expected_pyproject_toml_content == actual_pyproject_toml_content | ||
| assert expected_version_file_content == actual_version_file_content | ||
| # Make sure changelog is updated | ||
| assert expected_md_changelog_content == actual_md_changelog_content | ||
| assert expected_rst_changelog_content == actual_rst_changelog_content | ||
| # Make sure commit is created | ||
| assert expected_release_commit_text == actual_release_commit_text | ||
| # Make sure tag is created | ||
| assert curr_release_tag in [tag.name for tag in mirror_git_repo.tags] | ||
| assert mocked_git_push.call_count == 2 # 1 for commit, 1 for tag | ||
| assert post_mocker.call_count == 1 # vcs release creation occured |
13 changes: 10 additions & 3 deletionstests/fixtures/git_repo.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionstests/fixtures/repos/github_flow/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| from tests.fixtures.repos.github_flow.repo_w_default_release import * | ||
| from tests.fixtures.repos.github_flow.repo_w_default_release_w_branch_update_merge import * | ||
| from tests.fixtures.repos.github_flow.repo_w_release_channels import * |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.