[py-svn] r10773 - in py/dist/py: test test/testing test/tkinter test/tkinter/testing thread
hpk at codespeak.net
hpk at codespeak.net
Sun Apr 17 14:35:57 CEST 2005
Author: hpk
Date: Sun Apr 17 14:35:57 2005
New Revision: 10773
Modified:
py/dist/py/test/collect.py
py/dist/py/test/testing/test_collect.py
py/dist/py/test/tkinter/repository.py
py/dist/py/test/tkinter/testing/test_util.py
py/dist/py/test/tkinter/util.py
py/dist/py/thread/pool.py
Log:
some python2.2 compatibility changes
Modified: py/dist/py/test/collect.py
==============================================================================
--- py/dist/py/test/collect.py (original)
+++ py/dist/py/test/collect.py Sun Apr 17 14:35:57 2005
@@ -1,4 +1,3 @@
-
"""
Collect test items at filesystem and python module levels.
@@ -29,6 +28,7 @@
...
"""
+from __future__ import generators
import py
isclass = py.std.inspect.isclass
@@ -306,7 +306,8 @@
def _getobj(self):
return self.parent.obj()
def Function(self):
- return getattr(self.obj, 'Function', super(Instance, self).Function)
+ return getattr(self.obj, 'Function',
+ Collector.Function.__get__(self)) # XXX for python 2.2
Function = property(Function)
class Generator(Collector):
Modified: py/dist/py/test/testing/test_collect.py
==============================================================================
--- py/dist/py/test/testing/test_collect.py (original)
+++ py/dist/py/test/testing/test_collect.py Sun Apr 17 14:35:57 2005
@@ -108,6 +108,7 @@
o = tmpdir.ensure('generativetest', dir=1)
tfile = o.join('test_generative.py')
tfile.write(py.code.Source("""
+ from __future__ import generators # python2.2!
def func1(arg, arg2):
assert arg == arg2
Modified: py/dist/py/test/tkinter/repository.py
==============================================================================
--- py/dist/py/test/tkinter/repository.py (original)
+++ py/dist/py/test/tkinter/repository.py Sun Apr 17 14:35:57 2005
@@ -91,7 +91,7 @@
return [(key, self.find(key)) for key in self.keys(startkey)]
-class OrderedDict(UserDict.DictMixin):
+class OrderedDict(UserDict.DictMixin):
'''like a normal dict, but keys are ordered by time of setting'''
def __init__(self, *args, **kwargs):
self._dict = dict(*args, **kwargs)
Modified: py/dist/py/test/tkinter/testing/test_util.py
==============================================================================
--- py/dist/py/test/tkinter/testing/test_util.py (original)
+++ py/dist/py/test/tkinter/testing/test_util.py Sun Apr 17 14:35:57 2005
@@ -1,4 +1,4 @@
-
+from __future__ import generators
from py.__impl__.test.tkinter import util
from py.__impl__.test.tkinter.util import Status, TestReport, OutBuffer
import py
Modified: py/dist/py/test/tkinter/util.py
==============================================================================
--- py/dist/py/test/tkinter/util.py (original)
+++ py/dist/py/test/tkinter/util.py Sun Apr 17 14:35:57 2005
@@ -79,9 +79,7 @@
def update(self, status):
'''merge self and status, self will be set to the "higher" status
in ordered_list'''
- name_int_map = dict(
- py.std.itertools.izip(self.ordered_list,
- py.std.itertools.count()))
+ name_int_map = dict(zip(self.ordered_list, range(len(self.ordered_list))))
self.str = self.ordered_list[max([name_int_map[i]
for i in (str(status), self.str)])]
Modified: py/dist/py/thread/pool.py
==============================================================================
--- py/dist/py/thread/pool.py (original)
+++ py/dist/py/thread/pool.py Sun Apr 17 14:35:57 2005
@@ -5,7 +5,7 @@
class WorkerThread(threading.Thread):
def __init__(self, pool):
- super(WorkerThread, self).__init__()
+ threading.Thread.__init__(self)
self._queue = Queue.Queue()
self._pool = pool
self.setDaemon(1)
@@ -52,11 +52,26 @@
self._excinfo = excinfo
self._queue.put(None)
+ def _get_with_timeout(self, timeout):
+ # taken from python2.3's Queue.get()
+ # we want to run on python2.2 here
+ delay = 0.0005 # 500 us -> initial delay of 1 ms
+ endtime = time.time() + timeout
+ while 1:
+ try:
+ return self._queue.get_nowait()
+ except Queue.Empty:
+ remaining = endtime - time.time()
+ if remaining <= 0: #time is over and no element arrived
+ raise IOError("timeout waiting for task %r" %(self.task,))
+ delay = min(delay * 2, remaining, .05)
+ time.sleep(delay) #reduce CPU usage by using a sleep
+
def get(self, timeout=None):
- try:
- result = self._queue.get(timeout=timeout)
- except Queue.Empty:
- raise IOError("timeout waiting for task %r" %(self.task,))
+ if timeout is not None:
+ result = self._get_with_timeout(timeout)
+ else:
+ result = self._queue.get()
excinfo = self._excinfo
if excinfo:
self._excinfo = None
More information about the pytest-commit
mailing list