コード例 #1
0
    def negative_assertion(name, prop=True):
        def method(self):
            builder = AssertionBuilder(name, negative=True)
            instance = builder(self)
            callable_args = getattr(self, '_callable_args', ())
            if callable_args:
                instance._callable_args = callable_args
            callable_kw = getattr(self, '_callable_kw', {})
            if callable_kw:
                instance._callable_kw = callable_kw
            return instance

        method.__name__ = str(name)
        return make_safe_property(method, name, prop)

    object_handler = patchable_builtin(object)

    # None does not have a tp_dict associated to its PyObject, so this
    # is the only way we could make it work like we expected.
    none = patchable_builtin(None.__class__)

    for name in POSITIVES:
        object_handler[name] = positive_assertion(name)
        none[name] = positive_assertion(name, False)

    for name in NEGATIVES:
        object_handler[name] = negative_assertion(name)
        none[name] = negative_assertion(name, False)

old_dir = dir
コード例 #2
0
ファイル: __init__.py プロジェクト: spulec/sure
        method.__name__ = name
        return make_safe_property(method, name, prop)

    def negative_assertion(name, prop=True):
        def method(self):
            builder = AssertionBuilder(name, negative=True)
            instance = builder(self)
            callable_args = getattr(self, '_callable_args', None)
            if callable_args:
                instance._callable_args = callable_args
            callable_kw = getattr(self, '_callable_kw', None)
            if callable_kw:
                instance._callable_kw = callable_kw
            return instance

        method.__name__ = name
        return make_safe_property(method, name, prop)

    object_handler = patchable_builtin(object)

    # None does not have a tp_dict associated to its PyObject, so this
    # is the only way we could make it work like we expected.
    none = patchable_builtin(None.__class__)
    for name in POSITIVES:
        object_handler[name] = positive_assertion(name)
        none[name] = positive_assertion(name, False)

    for name in NEGATIVES:
        object_handler[name] = negative_assertion(name)
        none[name] = negative_assertion(name, False)