def test_str(self): class B: def __str__(self): return "B_class" for val in [100, "str", True, B()]: future = Future() future._set_result(val) self.assertEqual(str(future), str(val))
def test_getattr(self): class A: def __init__(self, val): self.val = val def get_val(self): return self.val class B:pass for val in [100, "str", True, B()]: future = Future() future._set_result(A(val)) self.assertEqual(future.val, val) self.assertEqual(future.get_val(), val)
def test_callback(self): class A: pass self._test_callback_flag = False for result in [1, "str", True, A()]: def f(n): self._test_callback_flag = True self.assertEqual(n, result) future = Future() future.add_callback(f) future._set_result(result) self.assertTrue(self._test_callback_flag) self._test_callback_flag = False
def test_set_result(self): future = Future() future._set_result(1) self.assertTrue(future._done)
def test_wait(self): future = Future() self.assertFalse(future._wait(timeout=0.01)) future._set_result(1) self.assertTrue(future._wait())
def test_get_result(self): result = tuple(range(3)) future = Future() future._set_result(result) self.assertEqual(future._get_result(), result)