Esempio n. 1
0
 def test_convert_to_requires_and_returns(self):
     def foo(): pass
     point = CallPoint(foo, requires='foo', returns='bar')
     self.assertTrue(isinstance(point.requires, requires))
     self.assertTrue(isinstance(point.returns, returns))
     compare(repr(foo)+" requires('foo') returns('bar')",
             repr(point))
Esempio n. 2
0
 def test_supplied_explicitly(self):
     obj = object()
     rq = requires('foo')
     rt = returns('bar')
     result = CallPoint(obj, rq, rt)(self.context)
     compare(result, self.context.extract.return_value)
     self.context.extract.assert_called_with(obj, rq, rt)
Esempio n. 3
0
 def test_repr_maximal(self):
     def foo(): pass
     point = CallPoint(foo, requires('foo'), returns('bar'))
     point.labels.add('baz')
     point.labels.add('bob')
     compare(repr(foo)+" requires('foo') returns('bar') <-- baz, bob",
             repr(point))
Esempio n. 4
0
 def test_passive_attributes(self):
     # these are managed by Modifiers
     o = object()
     point = CallPoint(o)
     compare(point.previous, None)
     compare(point.next, None)
     compare(point.labels, set())
Esempio n. 5
0
    def test_explicit_trumps_decorators(self):
        @requires('foo')
        @returns('bar')
        def foo(): pass

        rq = requires('baz')
        rt = returns('bob')

        result = CallPoint(foo, requires=rq, returns=rt)(self.context)
        compare(result, self.context.extract.return_value)
        self.context.extract.assert_called_with(foo, rq, rt)
Esempio n. 6
0
    def test_extract_from_decorations(self):
        rq = requires('foo')
        rt = returns('bar')

        @rq
        @rt
        def foo(): pass

        result = CallPoint(foo)(self.context)
        compare(result, self.context.extract.return_value)
        self.context.extract.assert_called_with(foo, rq, rt)
Esempio n. 7
0
    def test_extract_from_decorated_class(self):

        rq = requires('foo')
        rt = returns('bar')

        class Wrapper(object):
            def __init__(self, func):
                self.func = func
            def __call__(self):
                return 'the '+self.func()

        def my_dec(func):
            return update_wrapper(Wrapper(func), func)

        @my_dec
        @rq
        @rt
        def foo():
            return 'answer'

        self.context.extract.side_effect = lambda func, rq, rt: (func(), rq, rt)
        result = CallPoint(foo)(self.context)
        compare(result, expected=('the answer', rq, rt))
Esempio n. 8
0
 def test_repr_minimal(self):
     def foo(): pass
     point = CallPoint(foo)
     compare(repr(foo)+" requires() returns_result_type()", repr(point))