Mercurial > pygame
changeset 3151:7cec8bcc2b75
Make pygame.threads Python 3.x compatible, as per issue #146
| author | Lenard Lindstrom <len-l@telus.net> |
|---|---|
| date | Tue, 16 Oct 2012 21:52:11 -0700 |
| parents | ae2160cc5b0e |
| children | 73cefe45328a |
| files | lib/threads/__init__.py test/threads_tags.py test/threads_test.py |
| diffstat | 3 files changed, 12 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/threads/__init__.py Mon Oct 15 20:55:33 2012 -0700 +++ b/lib/threads/__init__.py Tue Oct 16 21:52:11 2012 -0700 @@ -17,7 +17,7 @@ from pygame.compat import geterror if sys.version_info[0] == 3: - from multiprocessing import JoinableQueue as Queue + from queue import Queue from queue import Empty elif (sys.version_info[0] == 2 and sys.version_info[1] < 5): from Py25Queue import Queue @@ -301,7 +301,7 @@ # TODO: the traceback doesn't show up nicely. # NOTE: TODO: we might want to return the results anyway? This should be an option. if stop_on_error: - error_ones = filter(lambda x:x.exception, results) + error_ones = list(filter(lambda x:x.exception, results)) if error_ones: raise error_ones[0].exception
--- a/test/threads_tags.py Mon Oct 15 20:55:33 2012 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -__tags__ = [] - -import sys -if sys.version_info >= (3, 0, 0): - __tags__.extend(('ignore', 'subprocess_ignore')) -
--- a/test/threads_test.py Mon Oct 15 20:55:33 2012 -0700 +++ b/test/threads_test.py Tue Oct 16 21:52:11 2012 -0700 @@ -18,6 +18,7 @@ from test.test_utils import test_not_implemented, unittest from pygame.threads import FuncResult, tmap, WorkerQueue, Empty, STOP from pygame import threads +from pygame.compat import xrange_ import time @@ -40,7 +41,7 @@ wq.stop() self.assert_(fr.result == 2) - self.assert_(fr2.result == 3) + self.assertEqual(fr2.result, 3) def test_do(self): @@ -62,7 +63,7 @@ self.assert_(len(wq.pool) > 0) for t in wq.pool: self.assert_(t.isAlive()) - for i in xrange(200): wq.do(lambda x: x+1, i) + for i in xrange_(200): wq.do(lambda x: x+1, i) wq.stop() for t in wq.pool: self.assert_(not t.isAlive()) @@ -85,7 +86,7 @@ wq = WorkerQueue() - for i in xrange(2000): wq.do(lambda x: x+1, i) + for i in xrange_(2000): wq.do(lambda x: x+1, i) wq.wait() self.assertRaises(Empty, wq.queue.get_nowait) @@ -148,12 +149,12 @@ # results, is returned as a list of FuncResult instances. # stop_on_error - - func, data = lambda x:x+1, xrange(100) + func, data = lambda x:x+1, xrange_(100) - tmapped = tmap(func, data) - mapped = map(func, data) + tmapped = list(tmap(func, data)) + mapped = list(map(func, data)) - self.assert_(tmapped == mapped) + self.assertEqual(tmapped, mapped) def test_tmap__None_func_and_multiple_sequences(self): return #TODO @@ -178,7 +179,7 @@ wq, results = tmap(lambda x:x, r, num_workers = 5, wait=False) wq.wait() r2 = map(lambda x:x.result, results) - self.assert_(r == r2) + self.assertEqual(list(r), list(r2)) def test_FuncResult(self): # as of 2008-06-28 @@ -196,7 +197,7 @@ # Results are stored in result attribute fr = FuncResult(lambda x:x+1) fr(2) - self.assert_(fr.result == 3) + self.assertEqual(fr.result, 3) # Exceptions are store in exception attribute self.assert_(fr.exception is None, "when no exception raised")
