Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Apr 14, 2024. It is now read-only.

Commit 0c72cb0

Browse filesBrowse files
committed
Making the test to run.
1 parent aae7869 commit 0c72cb0
Copy full SHA for 0c72cb0

File tree

6 files changed

+47
-34
lines changed
Filter options

6 files changed

+47
-34
lines changed

‎async/test/mod/test_zlib.py

Copy file name to clipboardExpand all lines: async/test/mod/test_zlib.py
+11-11Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ def test_constants(self):
2222
assert hasattr(zlib, "Z_MEM_ERROR")
2323
assert hasattr(zlib, "Z_BUF_ERROR")
2424
assert hasattr(zlib, "Z_VERSION_ERROR")
25-
26-
25+
26+
2727
def test_status(self):
2828
# test the newly introduced status code
2929
data = struct.pack(">L", (1<<31) + (1<<15) + (1<<2))
3030
assert len(data) == 4
31-
31+
3232
# compress
3333
cobj = zlib.compressobj(zlib.Z_BEST_SPEED)
3434
assert cobj.status == zlib.Z_STATUS_UNSET
35-
35+
3636
cchunk = ''
3737
for c in data:
3838
cchunk += cobj.compress(c)
@@ -41,34 +41,34 @@ def test_status(self):
4141
# its not yet done, but soon it will
4242
cchunk += cobj.flush()
4343
assert cobj.status == zlib.Z_STREAM_END
44-
44+
4545
# zip should have added a few bytes of info
4646
assert len(cchunk) > len(data)
47-
48-
47+
48+
4949
# decompress - need status to determine decompession finished
5050
dcobj = zlib.decompressobj()
5151
idata = '' # inflated data
5252
for i, c in enumerate(cchunk):
5353
idata += dcobj.decompress(c)
5454
assert dcobj.status == zlib.Z_OK
55-
55+
5656
# break if we have it
5757
if len(idata) == len(data):
5858
break
5959
# END for each character
6060
assert idata == data
61-
61+
6262
# we should still have some bytes left
6363
assert i < len(cchunk) - 1
64-
64+
6565
# feed the remaining data, we don't expect to decompress anything, but
6666
# want to see the status change
6767
while dcobj.status == zlib.Z_OK:
6868
i += 1
6969
assert len(dcobj.decompress(cchunk[i])) == 0
7070
# END deplete compressed stream
71-
71+
7272
# now we are done
7373
assert dcobj.status == zlib.Z_STREAM_END
7474
assert i == len(cchunk) - 1

‎async/test/task.py

Copy file name to clipboardExpand all lines: async/test/task.py
+13-13Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,18 @@ def _assert(self, pc, fc, check_scheduled=False):
5555
return self
5656

5757

58-
class TestThreadTask(_TestTaskBase, IteratorThreadTask):
58+
class FixtureThreadTask(_TestTaskBase, IteratorThreadTask):
5959
pass
6060

6161

62-
class TestFailureThreadTask(TestThreadTask):
62+
class FixtureFailureThreadTask(FixtureThreadTask):
6363
"""Fails after X items"""
6464
def __init__(self, *args, **kwargs):
6565
self.fail_after = kwargs.pop('fail_after')
66-
super(TestFailureThreadTask, self).__init__(*args, **kwargs)
66+
super(FixtureFailureThreadTask, self).__init__(*args, **kwargs)
6767

6868
def do_fun(self, item):
69-
item = TestThreadTask.do_fun(self, item)
69+
item = FixtureThreadTask.do_fun(self, item)
7070

7171
self.lock.acquire()
7272
try:
@@ -78,15 +78,15 @@ def do_fun(self, item):
7878
return item
7979

8080

81-
class TestChannelThreadTask(_TestTaskBase, ChannelThreadTask):
81+
class FixtureChannelThreadTask(_TestTaskBase, ChannelThreadTask):
8282
"""Apply a transformation on items read from an input channel"""
8383
def __init__(self, *args, **kwargs):
8484
self.fail_after = kwargs.pop('fail_after', 0)
85-
super(TestChannelThreadTask, self).__init__(*args, **kwargs)
85+
super(FixtureChannelThreadTask, self).__init__(*args, **kwargs)
8686

8787
def do_fun(self, item):
8888
"""return tuple(i, i*2)"""
89-
item = super(TestChannelThreadTask, self).do_fun(item)
89+
item = super(FixtureChannelThreadTask, self).do_fun(item)
9090

9191
# fail after support
9292
if self.fail_after:
@@ -106,22 +106,22 @@ def do_fun(self, item):
106106
# END handle tuple
107107

108108

109-
class TestPerformanceThreadTask(ChannelThreadTask):
109+
class FixturePerformanceThreadTask(ChannelThreadTask):
110110
"""Applies no operation to the item, and does not lock, measuring
111111
the actual throughput of the system"""
112112

113113
def do_fun(self, item):
114114
return item
115115

116116

117-
class TestVerifyChannelThreadTask(_TestTaskBase, ChannelThreadTask):
117+
class FixtureVerifyChannelThreadTask(_TestTaskBase, ChannelThreadTask):
118118
"""An input channel task, which verifies the result of its input channels,
119119
should be last in the chain.
120120
Id must be int"""
121121

122122
def do_fun(self, item):
123123
"""return tuple(i, i*2)"""
124-
item = super(TestVerifyChannelThreadTask, self).do_fun(item)
124+
item = super(FixtureVerifyChannelThreadTask, self).do_fun(item)
125125

126126
# make sure the computation order matches
127127
assert isinstance(item, tuple), "input was no tuple: %s" % item
@@ -141,7 +141,7 @@ def make_proxy_method(t):
141141
return lambda item: wt.do_fun(item)
142142

143143
def add_task_chain(p, ni, count=1, fail_setup=list(), feeder_channel=None, id_offset=0,
144-
feedercls=TestThreadTask, transformercls=TestChannelThreadTask,
144+
feedercls=FixtureThreadTask, transformercls=FixtureChannelThreadTask,
145145
include_verifier=True):
146146
"""Create a task chain of feeder, count transformers and order verifcator
147147
to the pool p, like t1 -> t2 -> t3
@@ -183,7 +183,7 @@ def add_task_chain(p, ni, count=1, fail_setup=list(), feeder_channel=None, id_of
183183
# END setup failure
184184

185185
if include_verifier:
186-
verifier = TestVerifyChannelThreadTask(inrc, 'verifier', None)
186+
verifier = FixtureVerifyChannelThreadTask(inrc, 'verifier', None)
187187
#verifier.fun = verifier.do_fun
188188
verifier.fun = make_proxy_method(verifier)
189189
vrc = p.add_task(verifier)
@@ -194,7 +194,7 @@ def add_task_chain(p, ni, count=1, fail_setup=list(), feeder_channel=None, id_of
194194
# END handle include verifier
195195
return tasks, rcs
196196

197-
def make_iterator_task(ni, taskcls=TestThreadTask, **kwargs):
197+
def make_iterator_task(ni, taskcls=FixtureThreadTask, **kwargs):
198198
""":return: task which yields ni items
199199
:param taskcls: the actual iterator type to use
200200
:param kwargs: additional kwargs to be passed to the task"""

‎async/test/test_performance.py

Copy file name to clipboardExpand all lines: async/test/test_performance.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_base(self):
3131
for read_mode in range(2):
3232
ts, rcs = add_task_chain(pool, ni, count=num_transformers,
3333
feedercls=IteratorThreadTask,
34-
transformercls=TestPerformanceThreadTask,
34+
transformercls=FixturePerformanceThreadTask,
3535
include_verifier=False)
3636

3737
mode_info = "read(0)"

‎async/test/test_pool.py

Copy file name to clipboardExpand all lines: async/test/test_pool.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def _assert_single_task(self, p, async=False):
202202
# test failure after ni / 2 items
203203
# This makes sure it correctly closes the channel on failure to prevent blocking
204204
nri = ni/2
205-
task = make_task(TestFailureThreadTask, fail_after=ni/2)
205+
task = make_task(FixtureFailureThreadTask, fail_after=ni/2)
206206
rc = p.add_task(task)
207207
assert len(rc.read()) == nri
208208
assert task.is_done()
@@ -412,7 +412,7 @@ def test_base(self):
412412
# SINGLE TASK SERIAL SYNC MODE
413413
##############################
414414
# put a few unrelated tasks that we forget about - check ref counts and cleanup
415-
t1, t2 = TestThreadTask(iter(list()), "nothing1", None), TestThreadTask(iter(list()), "nothing2", None)
415+
t1, t2 = FixtureThreadTask(iter(list()), "nothing1", None), FixtureThreadTask(iter(list()), "nothing2", None)
416416
urc1 = p.add_task(t1)
417417
urc2 = p.add_task(t2)
418418
assert p.num_tasks() == 2
@@ -433,7 +433,7 @@ def test_base(self):
433433
assert p.num_tasks() == 0
434434
assert sys.getrefcount(t2) == 2
435435

436-
t3 = TestChannelThreadTask(urc2, "channel", None)
436+
t3 = FixtureChannelThreadTask(urc2, "channel", None)
437437
urc3 = p.add_task(t3)
438438
assert p.num_tasks() == 1
439439
del(urc3)

‎async/test/test_thread.py

Copy file name to clipboardExpand all lines: async/test/test_thread.py
+11-4Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
except ImportError:
1212
from Queue import Queue
1313

14+
import sys
1415
import time
1516

16-
class TestWorker(WorkerThread):
17+
class FixtureWorker(WorkerThread):
1718
def __init__(self, *args, **kwargs):
18-
super(TestWorker, self).__init__(*args, **kwargs)
19+
super(FixtureWorker, self).__init__(*args, **kwargs)
1920
self.reset()
2021

2122
def fun(self, arg):
@@ -37,12 +38,18 @@ class TestThreads(TestBase):
3738

3839
@terminate_threads
3940
def test_worker_thread(self):
40-
worker = TestWorker()
41+
worker = FixtureWorker()
4142
assert isinstance(worker.start(), WorkerThread)
4243

4344
# test different method types
4445
standalone_func = lambda *args, **kwargs: worker.fun(*args, **kwargs)
45-
for function in (TestWorker.fun, worker.fun, standalone_func):
46+
functions = (worker.fun, standalone_func,)
47+
if sys.version_info < (3, 0):
48+
# unbound methods are gone from Python 3, it's not possible to
49+
# reconstruct the `self` from it.
50+
functions = functions + (FixtureWorker.fun,)
51+
52+
for function in functions:
4653
worker.inq.put((function, 1))
4754
time.sleep(0.01)
4855
worker.make_assertion()

‎async/thread.py

Copy file name to clipboardExpand all lines: async/thread.py
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
55
# -*- coding: utf-8 -*-
66
"""Module with threading utilities"""
7+
8+
from __future__ import print_function
9+
710
__docformat__ = "restructuredtext"
811
import threading
912
import inspect
@@ -182,7 +185,8 @@ def run(self):
182185
rval = routine(arg)
183186
else:
184187
# ignore unknown items
185-
sys.stderr.write("%s: task %s was not understood - terminating\n" % (self.getName(), str(tasktuple)))
188+
print("%s: task %s was not understood - terminating" % (self.getName(), str(tasktuple)),
189+
file=sys.stderr)
186190
break
187191
# END make routine call
188192
finally:
@@ -194,7 +198,9 @@ def run(self):
194198
except StopProcessing:
195199
break
196200
except Exception as e:
197-
sys.stderr.write("%s: Task %s raised unhandled exception: %s - this really shouldn't happen !\n" % (self.getName(), str(tasktuple), str(e)))
201+
print("%s: Task %s raised unhandled exception: %s - this really shouldn't happen !"
202+
% (self.getName(), str(tasktuple), str(e)),
203+
file=sys.stderr)
198204
continue # just continue
199205
# END routine exception handling
200206

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.