예제 #1
0
파일: test_promise.py 프로젝트: c0b/py-amqp
 def test_reverse(self):
     callback = Mock()
     x = barrier(self.ps, callback=promise(callback))
     for p in self.ps:
         p()
     self.assertTrue(x.ready)
     callback.assert_called_with()
예제 #2
0
파일: test_promise.py 프로젝트: c0b/py-amqp
 def test_apply(self):
     m = Mock()
     p = ppartial(m, 1)
     p()
     m.assert_called_with(1)
     p = ppartial(m, z=2)
     p()
     m.assert_called_with(z=2)
예제 #3
0
 def test_basic_nack(self, delivery_tag=3172312312):
     self.args.write_longlong(delivery_tag)
     self.args.write_bit(0)
     self.args.write_bit(0)
     with self.assertRaises(NotConfirmed):
         self.channel._basic_nack(AMQPReader(self.args.getvalue()))
     callback = Mock(name='callback')
     self.channel.events['basic_nack'].add(callback)
     self.channel._basic_nack(AMQPReader(self.args.getvalue()))
     callback.assert_called_with(delivery_tag, False, False)
예제 #4
0
 def test_basic_nack(self, delivery_tag=3172312312):
     self.args.write_longlong(delivery_tag)
     self.args.write_bit(0)
     self.args.write_bit(0)
     with self.assertRaises(NotConfirmed):
         self.channel._basic_nack(AMQPReader(self.args.getvalue()))
     callback = Mock(name='callback')
     self.channel.events['basic_nack'].add(callback)
     self.channel._basic_nack(AMQPReader(self.args.getvalue()))
     callback.assert_called_with(delivery_tag, False, False)
예제 #5
0
    def test_svpending_raises(self):
        p = promise()
        a_on_error = promise(Mock(name='a_on_error'))
        a = promise(Mock(name='a'), on_error=a_on_error)
        p.then(a)
        exc = KeyError()
        a.fun.side_effect = exc

        p(42)
        a_on_error.fun.assert_called_with(exc)
예제 #6
0
파일: test_promise.py 프로젝트: c0b/py-amqp
 def test_wrap(self):
     cb1 = Mock()
     cb2 = Mock()
     x = wrap(promise(cb1))
     x(1, y=2)
     cb1.assert_called_with(1, y=2)
     p2 = promise(cb2)
     x(p2)
     p2()
     cb1.assert_called_with(cb2())
예제 #7
0
파일: test_promise.py 프로젝트: c0b/py-amqp
    def test_transform(self):
        callback = Mock()

        def filter_key_value(key, filter_, mapping):
            return filter_(mapping[key])

        x = transform(filter_key_value, promise(callback), 'Value', int)
        x({'Value': 303})
        callback.assert_called_with(303)

        with self.assertRaises(KeyError):
            x({})
예제 #8
0
    def test_shallow_filter(self):
        a, b = promise(Mock(name='a')), promise(Mock(name='b'))
        p = promise(a, callback=b)
        self.assertIsNotNone(p._svpending)
        self.assertIsNone(p._lvpending)
        p(30)
        self.assertIsNone(p._svpending)
        a.fun.assert_called_with(30)
        b.fun.assert_called_with(a.fun.return_value)

        c, d = Mock(name='c'), Mock(name='d')
        promise(c, callback=d)(1)
        c.assert_called_with(1)
        d.assert_called_with(c.return_value)
예제 #9
0
    def test_chained_filter(self):
        a = promise(Mock(name='a'))
        b = promise(Mock(name='b'))
        c = promise(Mock(name='c'))
        d = promise(Mock(name='d'))

        p = promise(a)
        p.then(b).then(c).then(d)

        p(42, kw=300)

        a.fun.assert_called_with(42, kw=300)
        b.fun.assert_called_with(a.fun.return_value)
        c.fun.assert_called_with(b.fun.return_value)
        d.fun.assert_called_with(c.fun.return_value)
예제 #10
0
    def test_cancel_sv(self):
        p = promise()
        a = promise(Mock(name='a'))
        p.then(a)
        p.cancel()
        self.assertTrue(p.cancelled)
        self.assertTrue(a.cancelled)

        p.throw(KeyError())
예제 #11
0
    def test_deep_filter(self):
        a = promise(Mock(name='a'))
        b1, b2, b3 = (
            promise(Mock(name='a1')),
            promise(Mock(name='a2')),
            promise(Mock(name='a3')),
        )
        p = promise(a)
        p.then(b1)
        self.assertIsNone(p._lvpending)
        self.assertIsNotNone(p._svpending)
        p.then(b2)
        self.assertIsNotNone(p._lvpending)
        self.assertIsNone(p._svpending)
        p.then(b3)

        p(42)
        a.fun.assert_called_with(42)
        b1.fun.assert_called_with(a.fun.return_value)
        b2.fun.assert_called_with(a.fun.return_value)
        b3.fun.assert_called_with(a.fun.return_value)
예제 #12
0
    def test_shallow_filter(self):
        a, b = promise(Mock(name='a')), promise(Mock(name='b'))
        p = promise(a, callback=b)
        self.assertIsNotNone(p._svpending)
        self.assertIsNone(p._lvpending)
        p(30)
        self.assertIsNone(p._svpending)
        a.fun.assert_called_with(30)
        b.fun.assert_called_with(a.fun.return_value)

        c, d = Mock(name='c'), Mock(name='d')
        promise(c, callback=d)(1)
        c.assert_called_with(1)
        d.assert_called_with(c.return_value)
예제 #13
0
    def test_throw_from_cb(self):
        ae = promise(Mock(name='ae'))
        a = Mock(name='a')
        be = promise(Mock(name='be'))
        b = promise(Mock(name='b'), on_error=be)
        ce = promise(Mock(name='ce'))
        c = promise(Mock(name='c'), on_error=ce)

        exc = a.side_effect = KeyError()
        p1 = promise(a, on_error=ae)
        p1.then(b)
        self.assertTrue(p1._svpending)
        p1(42)
        p1.on_error.fun.assert_called_with(exc)

        p2 = promise(a)
        p2.then(b).then(c)
        p2(42)

        de = promise(Mock(name='de'))
        d = promise(Mock(name='d'), on_error=de)
        p2.then(d)
        de.fun.assert_called_with(exc)
예제 #14
0
    def test_lvpending_raises(self):
        p = promise()
        a_on_error = promise(Mock(name='a_on_error'))
        a = promise(Mock(name='a'), on_error=a_on_error)
        b_on_error = promise(Mock(name='b_on_error'))
        b = promise(Mock(name='a'), on_error=b_on_error)
        p.then(a)
        p.then(b)
        exc = KeyError()
        a.fun.side_effect = exc

        a.then(Mock(name='foobar'))
        a.then(Mock(name='foozi'))

        p(42)
        a_on_error.fun.assert_called_with(exc)
        b.fun.assert_called_with(42)
예제 #15
0
    def test_cancel(self):
        on_error = promise(Mock(name='on_error'))
        p = promise(on_error=on_error)
        a, b, c = (
            promise(Mock(name='a')),
            promise(Mock(name='b')),
            promise(Mock(name='c')),
        )
        a2 = promise(Mock(name='a1'))
        p.then(a).then(b).then(c)
        p.then(a2)

        p.cancel()
        p(42)
        self.assertTrue(p.cancelled)
        self.assertTrue(a.cancelled)
        self.assertTrue(a2.cancelled)
        self.assertTrue(b.cancelled)
        self.assertTrue(c.cancelled)
        self.assertTrue(on_error.cancelled)
        d = promise(Mock(name='d'))
        p.then(d)
        self.assertTrue(d.cancelled)
예제 #16
0
 def test_signal(self):
     callback = Mock(name='callback')
     a = promise()
     a.then(callback)
     a(42)
     callback.assert_called_with(42)
예제 #17
0
파일: test_promise.py 프로젝트: c0b/py-amqp
 def test_apply(self):
     m = Mock()
     p = starpromise(m, 1, 2, z=3)
     p()
     m.assert_called_with(1, 2, z=3)
예제 #18
0
 def test_with_partial_args_and_args(self):
     m = Mock(name='m')
     p = promise(m, (1, 2, 3), {'foobar': 2})
     p(4, 5, bazbar=3)
     m.assert_called_with(1, 2, 3, 4, 5, foobar=2, bazbar=3)
예제 #19
0
 def test_with_partial_args(self):
     m = Mock(name='m')
     p = promise(m, (1, 2, 3), {'foobar': 2})
     p()
     m.assert_called_with(1, 2, 3, foobar=2)
예제 #20
0
 def test_empty_promise(self):
     p = promise()
     p(42)
     x = Mock(name='x')
     p.then(x)
     x.assert_called_with(42)
예제 #21
0
파일: test_promise.py 프로젝트: c0b/py-amqp
 def test_apply(self):
     m = Mock()
     p = ready_promise(m, 1, 2, 3)
     m.assert_called_with(1, 2, 3)
     self.assertTrue(p.ready)
예제 #22
0
파일: test_promise.py 프로젝트: c0b/py-amqp
 def test_preplace(self):
     m = Mock()
     p = promise(m)
     p2 = preplace(p, 1, 2, z=3)
     p2(4, 5, x=3)
     m.assert_called_with(1, 2, z=3)
예제 #23
0
 def setUp(self):
     self.args = AMQPWriter()
     self.connection = Mock(name='connection')
     self.connection.channels = defaultdict(lambda: None)
     self.channel = NoOpenChannel(self.connection, channel_id=1)
예제 #24
0
 def test_empty_promise(self):
     p = promise()
     p(42)
     x = Mock(name='x')
     p.then(x)
     x.assert_called_with(42)
예제 #25
0
 def test_with_partial_args(self):
     m = Mock(name='m')
     p = promise(m, (1, 2, 3), {'foobar': 2})
     p()
     m.assert_called_with(1, 2, 3, foobar=2)
예제 #26
0
 def test_with_partial_args_and_args(self):
     m = Mock(name='m')
     p = promise(m, (1, 2, 3), {'foobar': 2})
     p(4, 5, bazbar=3)
     m.assert_called_with(1, 2, 3, 4, 5, foobar=2, bazbar=3)
예제 #27
0
 def test_signal(self):
     callback = Mock(name='callback')
     a = promise()
     a.then(callback)
     a(42)
     callback.assert_called_with(42)
예제 #28
0
    def test_chained(self):

        def add(x, y):
            return x + y

        def pow2(x):
            return x ** 2

        adder = Mock(name='adder')
        adder.side_effect = add

        power = Mock(name='multiplier')
        power.side_effect = pow2

        final = Mock(name='final')

        p = promise()
        p.then(adder).then(power).then(final)

        p(42, 42)
        self.assertEqual(p.value, ((42, 42), {}))
        adder.assert_called_with(42, 42)
        power.assert_called_with(84)
        final.assert_called_with(7056)
예제 #29
0
    def test_chained(self):

        def add(x, y):
            return x + y

        def pow2(x):
            return x ** 2

        adder = Mock(name='adder')
        adder.side_effect = add

        power = Mock(name='multiplier')
        power.side_effect = pow2

        final = Mock(name='final')

        p = promise()
        p.then(adder).then(power).then(final)

        p(42, 42)
        self.assertEqual(p.value, ((42, 42), {}))
        adder.assert_called_with(42, 42)
        power.assert_called_with(84)
        final.assert_called_with(7056)