Exemple #1
0
    def test_late_attach(self):
        defer = Defer()
        promise = defer.promise

        defer.resolve(16)

        callback = mock.MagicMock()
        promise.then(callback)

        callback.assert_called_with(16)
Exemple #2
0
    def test_simple(self):
        defer = Defer()
        promise = defer.promise
        callback_1 = mock.MagicMock()
        callback_2 = mock.MagicMock()
        promise.then(callback_1)
        promise.then(callback_2)

        defer.resolve(5)

        callback_1.assert_called_with(5)
        callback_2.assert_called_with(5)
Exemple #3
0
    def test_late_attach_chained(self):
        defer = Defer()
        promise_1 = defer.promise

        defer.resolve(24)

        promise_2 = promise_1.then(lambda x: x + 2)

        callback = mock.MagicMock()
        promise_2.then(callback)

        callback.assert_called_with(26)
Exemple #4
0
    def test_chained(self):

        defer = Defer()
        promise_1 = defer.promise
        promise_2 = promise_1.then(lambda x: x + 1)
        callback = mock.MagicMock()

        promise_2.then(callback)

        defer.resolve(7)

        callback.assert_called_with(8)
Exemple #5
0
    def test_double_resolve(self):
        defer = Defer()

        defer.resolve(2)
        self.assertRaises(DuplicateResolutionError, lambda: defer.resolve(3))