<commit_before>from doubles.verifying_double import VerifyingDouble

_any = object()


class MessageAllowance(object):
    def __init__(self, obj, method_name):
        self._obj = obj
        self._method_name = method_name
        self._return_value = None
        self.args = _any
        self.kwargs = _any
        self._is_callable_return = False
        self._is_satisfied = True

    def and_return(self, return_value):
        self._return_value = return_value
        self._is_callable_return = False
        return self

    def and_return_result_of(self, return_value):
        self._return_value = return_value
        self._is_callable_return = True
        return self

    def is_satisfied(self):
        return self._is_satisfied

    def with_args(self, *args, **kwargs):
        self.args = args
        self.kwargs = kwargs
        self._verify_arguments()
        return self

    def with_no_args(self):
        self.args = ()
        self.kwargs = {}
        self._verify_arguments()
        return self

    def satisfy_any_args_match(self):
        return self.args is _any and self.kwargs is _any

    def satisfy_exact_match(self, args, kwargs):
        return self.args == args and self.kwargs == kwargs

    @property
    def return_value(self):
        if self._is_callable_return:
            return self._return_value()
        else:
            return self._return_value

    def _verify_arguments(self):
        if not isinstance(self._obj, VerifyingDouble):
            return

        self._obj._verify_arguments(self._method_name, self.args, self.kwargs)
<commit_msg>Simplifying return value logic.<commit_after>from doubles.verifying_double import VerifyingDouble

_any = object()


class MessageAllowance(object):
    def __init__(self, obj, method_name):
        self._obj = obj
        self._method_name = method_name
        self.args = _any
        self.kwargs = _any
        self._is_satisfied = True

        self.and_return(None)

    def and_return(self, return_value):
        self._return_value = lambda: return_value
        return self

    def and_return_result_of(self, return_value):
        self._return_value = return_value
        return self

    def is_satisfied(self):
        return self._is_satisfied

    def with_args(self, *args, **kwargs):
        self.args = args
        self.kwargs = kwargs
        self._verify_arguments()
        return self

    def with_no_args(self):
        self.args = ()
        self.kwargs = {}
        self._verify_arguments()
        return self

    def satisfy_any_args_match(self):
        return self.args is _any and self.kwargs is _any

    def satisfy_exact_match(self, args, kwargs):
        return self.args == args and self.kwargs == kwargs

    @property
    def return_value(self):
        return self._return_value()

    def _verify_arguments(self):
        if not isinstance(self._obj, VerifyingDouble):
            return

        self._obj._verify_arguments(self._method_name, self.args, self.kwargs)

{'fraction_non_alphanumeric': 0.07863304578633046, 'fraction_numerical': 0.0, 'mean_word_length': 2.4261363636363638, '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': '1334213', 'n_tokens_mistral': 884, 'n_tokens_neox': 856, 'n_words': 204}