Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_dummy_thread.LockTests Class Reference

List of all members.

Public Member Functions

def setUp
def test_initlock
def test_release
def test_improper_release
def test_cond_acquire_success
def test_cond_acquire_fail
def test_uncond_acquire_success
def test_uncond_acquire_return_val
def test_uncond_acquire_blocking

Public Attributes

 lock

Detailed Description

Test lock objects.

Definition at line 18 of file test_dummy_thread.py.


Member Function Documentation

Definition at line 21 of file test_dummy_thread.py.

00021 
00022     def setUp(self):
00023         # Create a lock
00024         self.lock = _thread.allocate_lock()

Here is the caller graph for this function:

Definition at line 46 of file test_dummy_thread.py.

00046 
00047     def test_cond_acquire_fail(self):
00048         #Test acquiring locked lock returns False
00049         self.lock.acquire(0)
00050         self.assertTrue(not self.lock.acquire(0),
00051                         "Conditional acquiring of a locked lock incorrectly "
00052                          "succeeded.")

Here is the call graph for this function:

Definition at line 41 of file test_dummy_thread.py.

00041 
00042     def test_cond_acquire_success(self):
00043         #Make sure the conditional acquiring of the lock works.
00044         self.assertTrue(self.lock.acquire(0),
00045                         "Conditional acquiring of the lock failed.")

Here is the call graph for this function:

Definition at line 37 of file test_dummy_thread.py.

00037 
00038     def test_improper_release(self):
00039         #Make sure release of an unlocked thread raises _thread.error
00040         self.assertRaises(_thread.error, self.lock.release)

Here is the call graph for this function:

Definition at line 25 of file test_dummy_thread.py.

00025 
00026     def test_initlock(self):
00027         #Make sure locks start locked
00028         self.assertTrue(not self.lock.locked(),
00029                         "Lock object is not initialized unlocked.")

Here is the call graph for this function:

Definition at line 30 of file test_dummy_thread.py.

00030 
00031     def test_release(self):
00032         # Test self.lock.release()
00033         self.lock.acquire()
00034         self.lock.release()
00035         self.assertTrue(not self.lock.locked(),
00036                         "Lock object did not release properly.")

Here is the call graph for this function:

Definition at line 65 of file test_dummy_thread.py.

00065 
00066     def test_uncond_acquire_blocking(self):
00067         #Make sure that unconditional acquiring of a locked lock blocks.
00068         def delay_unlock(to_unlock, delay):
00069             """Hold on to lock for a set amount of time before unlocking."""
00070             time.sleep(delay)
00071             to_unlock.release()
00072 
00073         self.lock.acquire()
00074         start_time = int(time.time())
00075         _thread.start_new_thread(delay_unlock,(self.lock, DELAY))
00076         if support.verbose:
00077             print()
00078             print("*** Waiting for thread to release the lock "\
00079             "(approx. %s sec.) ***" % DELAY)
00080         self.lock.acquire()
00081         end_time = int(time.time())
00082         if support.verbose:
00083             print("done")
00084         self.assertTrue((end_time - start_time) >= DELAY,
00085                         "Blocking by unconditional acquiring failed.")

Here is the call graph for this function:

Definition at line 59 of file test_dummy_thread.py.

00059 
00060     def test_uncond_acquire_return_val(self):
00061         #Make sure that an unconditional locking returns True.
00062         self.assertTrue(self.lock.acquire(1) is True,
00063                         "Unconditional locking did not return True.")
00064         self.assertTrue(self.lock.acquire() is True)

Here is the call graph for this function:

Definition at line 53 of file test_dummy_thread.py.

00053 
00054     def test_uncond_acquire_success(self):
00055         #Make sure unconditional acquiring of a lock works.
00056         self.lock.acquire()
00057         self.assertTrue(self.lock.locked(),
00058                         "Uncondional locking failed.")

Here is the call graph for this function:


Member Data Documentation

Definition at line 23 of file test_dummy_thread.py.


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