Exemplo n.º 1
0
import re
import sys

from describe.matchers.core import MatcherBase, matcher_repository


STDOUT = sys.stdout

class TruthyMatcher(MatcherBase):
    MESSAGE = 'be true'
    METHODS = ['be_truthy']

    def match(self, actual):
        return bool(actual.evaluate())
matcher_repository.add(TruthyMatcher)


class FalsyMatcher(MatcherBase):
    MESSAGE = 'be false'
    METHODS = ['be_falsy']

    def match(self, actual):
        return not bool(actual.evaluate())
matcher_repository.add(FalsyMatcher)


class NoneMatcher(MatcherBase):
    MESSAGE = 'none'
    METHODS = ['be_none']

    def match(self, actual):
Exemplo n.º 2
0
        return self.expected_original_value is not self.UNSET

    def to(self, end_value):
        def verify_ending_value(old_value, new_value):
            return new_value == end_value

        message = ('from %d ' % self.expected_original_value if self.has_starting_value else '') + ' to %(new)r'
        tracker = Tracker(self.obj, self.name, self.invoke, self.expect, message)
        return self.add_starting_value_verifier(tracker.add_verifier(verify_ending_value))

class ToChangeMatcher(MatcherBase):
    METHODS = ['change']

    def __init__(self, value, invoke=False):
        super(ToChangeMatcher, self).__init__(value)
        self.invoke = False

    def get_postfix_message(self, actual_value):
        raise NotImplementedError()

    def asserts(self, obj, attrname):
        return Changes(obj.evaluate(), attrname, self.invoke, self._expect)

    def __enter__(self):
        raise TypeError('change needs additional methods to help verify (use by(change_amount) or to(final_value)')

    def __exit__(self, type, value, exception):
        pass

matcher_repository.add(ToChangeMatcher)
Exemplo n.º 3
0
 def add_matcher(cls, fn):
     matcher_repository.add(fn)