Back to index

python3.2  3.2.2
Public Member Functions
test.test_concurrent_futures.FutureTests Class Reference

List of all members.

Public Member Functions

def test_done_callback_with_result
def test_done_callback_with_exception
def test_done_callback_with_cancel
def test_done_callback_raises
def test_done_callback_already_successful
def test_done_callback_already_failed
def test_done_callback_already_cancelled
def test_repr
def test_cancel
def test_cancelled
def test_done
def test_running
def test_result_with_timeout
def test_result_with_success
def test_result_with_cancel
def test_exception_with_timeout
def test_exception_with_success

Detailed Description

Definition at line 379 of file test_concurrent_futures.py.


Member Function Documentation

Definition at line 485 of file test_concurrent_futures.py.

00485 
00486     def test_cancel(self):
00487         f1 = create_future(state=PENDING)
00488         f2 = create_future(state=RUNNING)
00489         f3 = create_future(state=CANCELLED)
00490         f4 = create_future(state=CANCELLED_AND_NOTIFIED)
00491         f5 = create_future(state=FINISHED, exception=IOError())
00492         f6 = create_future(state=FINISHED, result=5)
00493 
00494         self.assertTrue(f1.cancel())
00495         self.assertEqual(f1._state, CANCELLED)
00496 
00497         self.assertFalse(f2.cancel())
00498         self.assertEqual(f2._state, RUNNING)
00499 
00500         self.assertTrue(f3.cancel())
00501         self.assertEqual(f3._state, CANCELLED)
00502 
00503         self.assertTrue(f4.cancel())
00504         self.assertEqual(f4._state, CANCELLED_AND_NOTIFIED)
00505 
00506         self.assertFalse(f5.cancel())
00507         self.assertEqual(f5._state, FINISHED)
00508 
00509         self.assertFalse(f6.cancel())
00510         self.assertEqual(f6._state, FINISHED)

Here is the call graph for this function:

Definition at line 511 of file test_concurrent_futures.py.

00511 
00512     def test_cancelled(self):
00513         self.assertFalse(PENDING_FUTURE.cancelled())
00514         self.assertFalse(RUNNING_FUTURE.cancelled())
00515         self.assertTrue(CANCELLED_FUTURE.cancelled())
00516         self.assertTrue(CANCELLED_AND_NOTIFIED_FUTURE.cancelled())
00517         self.assertFalse(EXCEPTION_FUTURE.cancelled())
00518         self.assertFalse(SUCCESSFUL_FUTURE.cancelled())

Here is the call graph for this function:

Definition at line 519 of file test_concurrent_futures.py.

00519 
00520     def test_done(self):
00521         self.assertFalse(PENDING_FUTURE.done())
00522         self.assertFalse(RUNNING_FUTURE.done())
00523         self.assertTrue(CANCELLED_FUTURE.done())
00524         self.assertTrue(CANCELLED_AND_NOTIFIED_FUTURE.done())
00525         self.assertTrue(EXCEPTION_FUTURE.done())
00526         self.assertTrue(SUCCESSFUL_FUTURE.done())

Here is the call graph for this function:

Definition at line 457 of file test_concurrent_futures.py.

00457 
00458     def test_done_callback_already_cancelled(self):
00459         was_cancelled = None
00460         def fn(callback_future):
00461             nonlocal was_cancelled
00462             was_cancelled = callback_future.cancelled()
00463 
00464         f = Future()
00465         self.assertTrue(f.cancel())
00466         f.add_done_callback(fn)
00467         self.assertTrue(was_cancelled)

Here is the call graph for this function:

Definition at line 446 of file test_concurrent_futures.py.

00446 
00447     def test_done_callback_already_failed(self):
00448         callback_exception = None
00449         def fn(callback_future):
00450             nonlocal callback_exception
00451             callback_exception = callback_future.exception()
00452 
00453         f = Future()
00454         f.set_exception(Exception('test'))
00455         f.add_done_callback(fn)
00456         self.assertEqual(('test',), callback_exception.args)

Here is the call graph for this function:

Definition at line 435 of file test_concurrent_futures.py.

00435 
00436     def test_done_callback_already_successful(self):
00437         callback_result = None
00438         def fn(callback_future):
00439             nonlocal callback_result
00440             callback_result = callback_future.result()
00441 
00442         f = Future()
00443         f.set_result(5)
00444         f.add_done_callback(fn)
00445         self.assertEqual(5, callback_result)

Here is the call graph for this function:

Definition at line 413 of file test_concurrent_futures.py.

00413 
00414     def test_done_callback_raises(self):
00415         with test.support.captured_stderr() as stderr:
00416             raising_was_called = False
00417             fn_was_called = False
00418 
00419             def raising_fn(callback_future):
00420                 nonlocal raising_was_called
00421                 raising_was_called = True
00422                 raise Exception('doh!')
00423 
00424             def fn(callback_future):
00425                 nonlocal fn_was_called
00426                 fn_was_called = True
00427 
00428             f = Future()
00429             f.add_done_callback(raising_fn)
00430             f.add_done_callback(fn)
00431             f.set_result(5)
00432             self.assertTrue(raising_was_called)
00433             self.assertTrue(fn_was_called)
00434             self.assertIn('Exception: doh!', stderr.getvalue())

Here is the call graph for this function:

Definition at line 402 of file test_concurrent_futures.py.

00402 
00403     def test_done_callback_with_cancel(self):
00404         was_cancelled = None
00405         def fn(callback_future):
00406             nonlocal was_cancelled
00407             was_cancelled = callback_future.cancelled()
00408 
00409         f = Future()
00410         f.add_done_callback(fn)
00411         self.assertTrue(f.cancel())
00412         self.assertTrue(was_cancelled)

Here is the call graph for this function:

Definition at line 391 of file test_concurrent_futures.py.

00391 
00392     def test_done_callback_with_exception(self):
00393         callback_exception = None
00394         def fn(callback_future):
00395             nonlocal callback_exception
00396             callback_exception = callback_future.exception()
00397 
00398         f = Future()
00399         f.add_done_callback(fn)
00400         f.set_exception(Exception('test'))
00401         self.assertEqual(('test',), callback_exception.args)

Here is the call graph for this function:

Definition at line 380 of file test_concurrent_futures.py.

00380 
00381     def test_done_callback_with_result(self):
00382         callback_result = None
00383         def fn(callback_future):
00384             nonlocal callback_result
00385             callback_result = callback_future.result()
00386 
00387         f = Future()
00388         f.add_done_callback(fn)
00389         f.set_result(5)
00390         self.assertEqual(5, callback_result)

Here is the call graph for this function:

Definition at line 586 of file test_concurrent_futures.py.

00586 
00587     def test_exception_with_success(self):
00588         def notification():
00589             # Wait until the main thread is waiting for the exception.
00590             time.sleep(1)
00591             with f1._condition:
00592                 f1._state = FINISHED
00593                 f1._exception = IOError()
00594                 f1._condition.notify_all()
00595 
00596         f1 = create_future(state=PENDING)
00597         t = threading.Thread(target=notification)
00598         t.start()
00599 
00600         self.assertTrue(isinstance(f1.exception(timeout=5), IOError))
00601 
@test.support.reap_threads

Here is the call graph for this function:

Definition at line 573 of file test_concurrent_futures.py.

00573 
00574     def test_exception_with_timeout(self):
00575         self.assertRaises(futures.TimeoutError,
00576                           PENDING_FUTURE.exception, timeout=0)
00577         self.assertRaises(futures.TimeoutError,
00578                           RUNNING_FUTURE.exception, timeout=0)
00579         self.assertRaises(futures.CancelledError,
00580                           CANCELLED_FUTURE.exception, timeout=0)
00581         self.assertRaises(futures.CancelledError,
00582                           CANCELLED_AND_NOTIFIED_FUTURE.exception, timeout=0)
00583         self.assertTrue(isinstance(EXCEPTION_FUTURE.exception(timeout=0),
00584                                    IOError))
00585         self.assertEqual(SUCCESSFUL_FUTURE.exception(timeout=0), None)

Here is the call graph for this function:

Definition at line 468 of file test_concurrent_futures.py.

00468 
00469     def test_repr(self):
00470         self.assertRegex(repr(PENDING_FUTURE),
00471                          '<Future at 0x[0-9a-f]+ state=pending>')
00472         self.assertRegex(repr(RUNNING_FUTURE),
00473                          '<Future at 0x[0-9a-f]+ state=running>')
00474         self.assertRegex(repr(CANCELLED_FUTURE),
00475                          '<Future at 0x[0-9a-f]+ state=cancelled>')
00476         self.assertRegex(repr(CANCELLED_AND_NOTIFIED_FUTURE),
00477                          '<Future at 0x[0-9a-f]+ state=cancelled>')
00478         self.assertRegex(
00479                 repr(EXCEPTION_FUTURE),
00480                 '<Future at 0x[0-9a-f]+ state=finished raised IOError>')
00481         self.assertRegex(
00482                 repr(SUCCESSFUL_FUTURE),
00483                 '<Future at 0x[0-9a-f]+ state=finished returned int>')
00484 

Here is the call graph for this function:

Definition at line 560 of file test_concurrent_futures.py.

00560 
00561     def test_result_with_cancel(self):
00562         # TODO(brian@sweetapp.com): This test is timing dependant.
00563         def notification():
00564             # Wait until the main thread is waiting for the result.
00565             time.sleep(1)
00566             f1.cancel()
00567 
00568         f1 = create_future(state=PENDING)
00569         t = threading.Thread(target=notification)
00570         t.start()
00571 
00572         self.assertRaises(futures.CancelledError, f1.result, timeout=5)

Here is the call graph for this function:

Definition at line 547 of file test_concurrent_futures.py.

00547 
00548     def test_result_with_success(self):
00549         # TODO(brian@sweetapp.com): This test is timing dependant.
00550         def notification():
00551             # Wait until the main thread is waiting for the result.
00552             time.sleep(1)
00553             f1.set_result(42)
00554 
00555         f1 = create_future(state=PENDING)
00556         t = threading.Thread(target=notification)
00557         t.start()
00558 
00559         self.assertEqual(f1.result(timeout=5), 42)

Here is the call graph for this function:

Definition at line 535 of file test_concurrent_futures.py.

00535 
00536     def test_result_with_timeout(self):
00537         self.assertRaises(futures.TimeoutError,
00538                           PENDING_FUTURE.result, timeout=0)
00539         self.assertRaises(futures.TimeoutError,
00540                           RUNNING_FUTURE.result, timeout=0)
00541         self.assertRaises(futures.CancelledError,
00542                           CANCELLED_FUTURE.result, timeout=0)
00543         self.assertRaises(futures.CancelledError,
00544                           CANCELLED_AND_NOTIFIED_FUTURE.result, timeout=0)
00545         self.assertRaises(IOError, EXCEPTION_FUTURE.result, timeout=0)
00546         self.assertEqual(SUCCESSFUL_FUTURE.result(timeout=0), 42)

Here is the call graph for this function:

Definition at line 527 of file test_concurrent_futures.py.

00527 
00528     def test_running(self):
00529         self.assertFalse(PENDING_FUTURE.running())
00530         self.assertTrue(RUNNING_FUTURE.running())
00531         self.assertFalse(CANCELLED_FUTURE.running())
00532         self.assertFalse(CANCELLED_AND_NOTIFIED_FUTURE.running())
00533         self.assertFalse(EXCEPTION_FUTURE.running())
00534         self.assertFalse(SUCCESSFUL_FUTURE.running())

Here is the call graph for this function:


The documentation for this class was generated from the following file: