Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

see if there is a better way to structure multiple parameterized fixtures #100

Open
github-actions bot opened this issue Apr 4, 2022 · 0 comments
Labels

Comments

@github-actions
Copy link
Contributor

github-actions bot commented Apr 4, 2022

see if there is a better way to structure multiple parameterized fixtures

that actually resolve to the same value

# TODO: see if there is a better way to structure multiple parameterized fixtures

from enum import Enum
from typing import List, Final

import pytest
from git import Repo

from flexlate.ext_git import delete_local_branch
from tests.gitutils import reset_n_commits_without_checkout


class LocalBranchSituation(str, Enum):
    UP_TO_DATE = "up to date"
    DELETED = "deleted"
    OUT_OF_DATE = "out of date"

    def apply(self, repo: Repo, branch_name: str):
        apply_local_branch_situation(repo, branch_name, self)


all_local_branch_situations: Final[List[LocalBranchSituation]] = list(
    LocalBranchSituation
)


@pytest.fixture(scope="module", params=all_local_branch_situations)
def local_branch_situation(request) -> LocalBranchSituation:
    return request.param


# TODO: see if there is a better way to structure multiple parameterized fixtures
#  that actually resolve to the same value
@pytest.fixture(scope="module", params=all_local_branch_situations)
def template_branch_situation(request) -> LocalBranchSituation:
    return request.param


@pytest.fixture(scope="module", params=all_local_branch_situations)
def output_branch_situation(request) -> LocalBranchSituation:
    return request.param


def apply_local_branch_situation(
    repo: Repo, branch_name: str, situation: LocalBranchSituation
):
    if situation == LocalBranchSituation.UP_TO_DATE:
        return
    if situation == LocalBranchSituation.DELETED:
        return delete_local_branch(repo, branch_name)
    if situation == LocalBranchSituation.OUT_OF_DATE:
        return reset_n_commits_without_checkout(repo, branch_name)
    raise NotImplementedError(f"no handling for local branch situation {situation}")

7f058873b21c67c2af09f64137c33b4d0d58bbf9

@github-actions github-actions bot added the todo label Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

0 participants