<commit_before>from tddcommit import Kind

class StateTransitionError(Exception):
    pass


class State:
    def __init__(self):
        self._current_state = None
        self._had_green = False

    def allowed(self, proposed_state):
        if not self._current_state:
            if proposed_state is Kind.initial:
                return True
        elif self._current_state is Kind.initial:
            if proposed_state is Kind.red \
            or proposed_state is Kind.merge \
            or proposed_state is Kind.beige:
                return True
        elif self._current_state is Kind.red:
            if proposed_state is Kind.green:
                return True
        elif self._current_state is Kind.green \
          or self._current_state is Kind.refactor \
          or self._current_state is Kind.merge \
          or self._current_state is Kind.beige:
            # Check to prevent refactors when there has been no green
            if self._current_state is Kind.beige \
            and proposed_state is Kind.refactor \
            and not self._had_green:
                return False
            # Otherwise allow all sensible state changes
            if proposed_state is Kind.refactor \
            or proposed_state is Kind.red \
            or proposed_state is Kind.merge \
            or proposed_state is Kind.beige:
                return True
        return False

    def change(self, to_state):
        if self.allowed(to_state):
            self._current_state = to_state
            if to_state is Kind.green:
                self._had_green = True
        else:
            raise StateTransitionError(
                'It is not valid to move from ' + str(self._current_state)
                + 'to ' + str(to_state))<commit_msg>GREEN<commit_after>from tddcommit import Kind

class StateTransitionError(Exception):
    pass


class State:
    def __init__(self):
        self._current_state = None
        self._had_green = False

    def allowed(self, proposed_state):
        if not self._current_state:
            if proposed_state is Kind.initial:
                return True
        elif self._current_state is Kind.initial:
            if proposed_state is Kind.red \
            or proposed_state is Kind.merge \
            or proposed_state is Kind.beige:
                return True
        elif self._current_state is Kind.red:
            if proposed_state is Kind.green:
                return True
        elif self._current_state is Kind.green \
          or self._current_state is Kind.refactor \
          or self._current_state is Kind.merge \
          or self._current_state is Kind.beige:
            # Check to prevent refactors when there has been no green
            if (self._current_state is Kind.beige \
            or self._current_state is Kind.merge) \
            and proposed_state is Kind.refactor \
            and not self._had_green:
                return False
            # Otherwise allow all sensible state changes
            if proposed_state is Kind.refactor \
            or proposed_state is Kind.red \
            or proposed_state is Kind.merge \
            or proposed_state is Kind.beige:
                return True
        return False

    def change(self, to_state):
        if self.allowed(to_state):
            self._current_state = to_state
            if to_state is Kind.green:
                self._had_green = True
        else:
            raise StateTransitionError(
                'It is not valid to move from ' + str(self._current_state)
                + 'to ' + str(to_state))
{'fraction_non_alphanumeric': 0.05368567454798331, 'fraction_numerical': 0.0, 'mean_word_length': 1.6656782802075611, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2926886', 'n_tokens_mistral': 921, 'n_tokens_neox': 896, 'n_words': 295}