def test_promise_on_reject(): on_resolve = Mock(wraps=lambda _: 1) on_reject = Mock(wraps=lambda _: Promise.reject(2)) p = Promise.reject(0).then(on_resolve, on_reject) p.wait() on_reject.assert_called_once_with(0) assert on_resolve.call_count == 0 assert p._value == 2 assert p._state == S.REJECTED
def test_promise_reject(): p = Promise.reject(1) assert p._state == S.REJECTED assert p._value == 1 assert p._timeout is None assert p._thread is None assert p._event.is_set()
def run(_=None): nonlocal i if i == reject_i: if error: raise error() return Promise.reject(-i) i += 1 return i
def test_promise_on_reject_2(): on_resolve = Mock(wraps=lambda _: int('x')) on_reject = Mock(wraps=lambda _: Promise.reject(2)) p = Promise.resolve(0).then(on_resolve, on_reject) p.wait() on_resolve.assert_called_once_with(0) assert on_reject.call_count == 0 assert isinstance(p._value, Exception) assert p._state == S.REJECTED
def run(_=None): nonlocal i if i == reject_i: if error: raise error() return Promise.reject(-i) i += 1 if i < length: return Promise.resolve(i).then(run) return i