lock.acquire behaviour

"Thomas Klaeger" <[email protected]> Sun, 03 Oct 2004 11:59:44 +0200
Newsgroups gmane.comp.pythin.pyds.devel
Message-ID <415FE9B0.3144.345FE9@localhost>
--Message-Boundary-27084
Content-type: text/plain; charset=US-ASCII
Content-transfer-encoding: 7BIT
Content-description: Mail message body

Hi!

To test the behaviour I wrote the attached unit tests.

My observations on win32: python 2.2.3 behaves as documented, 
while python 2.3.4 does not behave as documented (the noargs test 
will fail)

On Monday I will have the opportunity to test on SuSE Linux 9.0. 
Could you post your observations on the systems available to you?

Regards, Thomas


--Message-Boundary-27084
Content-type: text/plain; charset=US-ASCII
Content-transfer-encoding: 7BIT
Content-description: Text from file 'LockTest.py'

import thread
import unittest

class LockTest(unittest.TestCase):
	"""
	Tests for thread.lock behaviour. See the documentation at
	http://www.python.org/doc/2.2.3/lib/module-thread.html and
	http://www.python.org/doc/2.3.4/lib/module-thread.html. Search
	for acquire on the corresponding page.
	
	test_noargs() will fail on win32 with python 2.3.4
	"""

	def test_noargs(self):
		"According to the docs the following call should return None"
		lock = thread.allocate_lock()
		self.assertEquals(None, lock.acquire(), "lock.acquire does not behave as documented")

	def test_nonblocking(self):
		"According to the docs the following call should return True"
		lock = thread.allocate_lock()
		self.assert_(lock.acquire(0), "lock.acquire does not behave as documented")

	def test_blocking(self):
		"According to the docs the following call should return True"
		lock = thread.allocate_lock()
		self.assert_(lock.acquire(1), "lock.acquire does not behave as documented")

if __name__ == '__main__':
    # Run the tests.
    unittest.main()

--Message-Boundary-27084--