コード例 #1
0
    def test_real_world_example(self):
        def cb(res, _):
            with open(os.path.join(os.path.dirname(__file__),
                                   'data.json')) as f:
                res(f.read())

        call = Call(cb) \
            .then(lambda data: json.loads(data)) \
            .then(lambda data: data['app-id']) \
            .catch(lambda err: 'Whoops')
        call.then(print)
        try:
            value = call.wait()
        except Exception:
            self.fail(
                'Call.wait shouldn\'t throw as it is being caught in the chain'
            )

        self.assertEqual(value, 'Whoops')
コード例 #2
0
    def test_chains(self):
        call = Call(
            self.callback_resolves_delay).then(lambda val: val + ' appended')
        result = call.wait()

        self.assertEqual(result, 'Data appended')
コード例 #3
0
 def test_chains_fail(self):
     call = Call(self.callback_rejects_delay).catch(lambda err: err)
     res = call.wait()
     self.assertEqual(res, 'Fail')
コード例 #4
0
 def test_callback(self):
     call = Call(self.callback_resolves_delay)
     result = call.wait()
     self.assertEqual(result, 'Data')