コード例 #1
0
    def test_load_history_NotInitialized_HistoryExceptionIsRaised(self):
        history = History()

        with pytest.raises(
            HistoryException,
            match='PyHist is not initialized. Please, type "pyhist --init"',
        ):
            history.load_history()
コード例 #2
0
    def test_load_history_FromInitializedFile_VersionsAreLoaded(
        self, pyhist_items: List[PyHistItem]
    ):
        history = History()

        history.load_history()

        assert history.pyhist_items == history.pyhist_items
コード例 #3
0
    def assert_version_update(
        current_version: Version,
        added_commits: List[Commit],
        removed_commits: List[Commit],
        expected_version: Version,
    ):
        git_history = GitHistory()
        history = History()
        version_parser = MagicMock()

        semantic_versioning = SemanticVersioning(git_history=git_history,
                                                 history=history)
        semantic_versioning.version = current_version

        # act
        semantic_versioning.update_version(added_commits=added_commits,
                                           removed_commits=removed_commits)

        # assert
        assert version_parser.persist_current_version.called_once_with(
            version=expected_version.get_version())
コード例 #4
0
ファイル: test_pyhist.py プロジェクト: jgoodman8/pyhist
    def assert_version_update(
        cls,
        current_version: str,
        git_commits: List[str],
        git_commits_messages: List[str],
        pyhist_commits: List[str],
        pyhist_commits_messages: List[str],
        expected_version: str,
    ):

        git_history = GitHistory()
        git_history.git_commits = cls.build_commits(
            commits=git_commits, messages=git_commits_messages)

        history = History()
        history.pyhist_items = [
            PyHistItem(commit=commit, version=None, is_version=False)
            for commit in cls.build_commits(commits=pyhist_commits,
                                            messages=pyhist_commits_messages)
        ]
        if current_version is not None:
            history.pyhist_items.insert(
                0,
                PyHistItem(
                    commit=None,
                    version=Version().create_from_str_version(current_version),
                    is_version=False,
                ),
            )

        setup_parser = SetupParser()
        current_version_parts = ([0, 0, 0] if current_version is None else [
            int(part) for part in current_version.split(".")
        ])
        changelog_generator = ChangelogGenerator(history=history)
        semantic_versioning = SemanticVersioning(git_history=git_history,
                                                 history=history)

        pyhist = PyHist(
            git_history=git_history,
            history=history,
            semantic_versioning=semantic_versioning,
            changelog_generator=changelog_generator,
            setup_parser=setup_parser,
        )

        # act
        with patch.object(
                setup_parser,
                "persist_version") as patch_persist_version, patch.object(
                    setup_parser,
                    "get_current_version_parts",
                    return_value=current_version_parts,
                ) as patch_get_current_version_parts, patch.object(
                    git_history, "add_versioning_commit"
                ) as patch_add_versioning_commit, patch.object(
                    history, "load_history", side_effect=lambda: None
                ) as patch_load_history, patch.object(
                    history, "save_history", side_effect=lambda: None
                ) as patch_save_history, patch.object(
                    changelog_generator,
                    "generate_changelog",
                    side_effect=lambda: None) as patch_generate_changelog:
            pyhist.update()

        # assert
        assert patch_add_versioning_commit.called_once_with(
            version=expected_version, is_release=False)
        assert patch_save_history.called
        assert patch_load_history.called
        assert patch_generate_changelog.called
        assert patch_get_current_version_parts.called
        assert patch_persist_version.called_once_with(version=expected_version)
コード例 #5
0
    def test_save_history_RemoveCommitAndSave_FileUpdatedWithoutCommit(
        self, pyhist_items: List[PyHistItem]
    ):
        # arrange
        history = History()
        history.load_history()

        # act
        history.remove_commit(history.pyhist_items[0].commit)
        history.save_history()

        # assert
        new_history = History()
        new_history.load_history()
        assert len(new_history.pyhist_items) == 1
        assert new_history.pyhist_items == history.pyhist_items
コード例 #6
0
    def test_is_initialized_FileExists_ReturnsTrue(
        self, pyhist_items: List[PyHistItem]
    ):
        history = History()

        assert history.is_initialized()
コード例 #7
0
    def test_is_initialized_FileNotExists_ReturnsFalse(self):
        history = History()

        assert not history.is_initialized()