Movatterモバイル変換


[0]ホーム

URL:


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

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

Commit0c72cb0

Browse files
committed
Making the test to run.
1 parentaae7869 commit0c72cb0

File tree

6 files changed

+47
-34
lines changed

6 files changed

+47
-34
lines changed

‎async/test/mod/test_zlib.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ def test_constants(self):
2222
asserthasattr(zlib,"Z_MEM_ERROR")
2323
asserthasattr(zlib,"Z_BUF_ERROR")
2424
asserthasattr(zlib,"Z_VERSION_ERROR")
25-
26-
25+
26+
2727
deftest_status(self):
2828
# test the newly introduced status code
2929
data=struct.pack(">L", (1<<31)+ (1<<15)+ (1<<2))
3030
assertlen(data)==4
31-
31+
3232
# compress
3333
cobj=zlib.compressobj(zlib.Z_BEST_SPEED)
3434
assertcobj.status==zlib.Z_STATUS_UNSET
35-
35+
3636
cchunk=''
3737
forcindata:
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
assertcobj.status==zlib.Z_STREAM_END
44-
44+
4545
# zip should have added a few bytes of info
4646
assertlen(cchunk)>len(data)
47-
48-
47+
48+
4949
# decompress - need status to determine decompession finished
5050
dcobj=zlib.decompressobj()
5151
idata=''# inflated data
5252
fori,cinenumerate(cchunk):
5353
idata+=dcobj.decompress(c)
5454
assertdcobj.status==zlib.Z_OK
55-
55+
5656
# break if we have it
5757
iflen(idata)==len(data):
5858
break
5959
# END for each character
6060
assertidata==data
61-
61+
6262
# we should still have some bytes left
6363
asserti<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
whiledcobj.status==zlib.Z_OK:
6868
i+=1
6969
assertlen(dcobj.decompress(cchunk[i]))==0
7070
# END deplete compressed stream
71-
71+
7272
# now we are done
7373
assertdcobj.status==zlib.Z_STREAM_END
7474
asserti==len(cchunk)-1

‎async/test/task.py

Lines 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
returnself
5656

5757

58-
classTestThreadTask(_TestTaskBase,IteratorThreadTask):
58+
classFixtureThreadTask(_TestTaskBase,IteratorThreadTask):
5959
pass
6060

6161

62-
classTestFailureThreadTask(TestThreadTask):
62+
classFixtureFailureThreadTask(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
defdo_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
returnitem
7979

8080

81-
classTestChannelThreadTask(_TestTaskBase,ChannelThreadTask):
81+
classFixtureChannelThreadTask(_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
defdo_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
ifself.fail_after:
@@ -106,22 +106,22 @@ def do_fun(self, item):
106106
# END handle tuple
107107

108108

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

113113
defdo_fun(self,item):
114114
returnitem
115115

116116

117-
classTestVerifyChannelThreadTask(_TestTaskBase,ChannelThreadTask):
117+
classFixtureVerifyChannelThreadTask(_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
defdo_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
assertisinstance(item,tuple),"input was no tuple: %s"%item
@@ -141,7 +141,7 @@ def make_proxy_method(t):
141141
returnlambdaitem:wt.do_fun(item)
142142

143143
defadd_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
ifinclude_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
returntasks,rcs
196196

197-
defmake_iterator_task(ni,taskcls=TestThreadTask,**kwargs):
197+
defmake_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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_base(self):
3131
forread_modeinrange(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

Lines 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
assertlen(rc.read())==nri
208208
asserttask.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
assertp.num_tasks()==2
@@ -433,7 +433,7 @@ def test_base(self):
433433
assertp.num_tasks()==0
434434
assertsys.getrefcount(t2)==2
435435

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

‎async/test/test_thread.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
exceptImportError:
1212
fromQueueimportQueue
1313

14+
importsys
1415
importtime
1516

16-
classTestWorker(WorkerThread):
17+
classFixtureWorker(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
deffun(self,arg):
@@ -37,12 +38,18 @@ class TestThreads(TestBase):
3738

3839
@terminate_threads
3940
deftest_worker_thread(self):
40-
worker=TestWorker()
41+
worker=FixtureWorker()
4142
assertisinstance(worker.start(),WorkerThread)
4243

4344
# test different method types
4445
standalone_func=lambda*args,**kwargs:worker.fun(*args,**kwargs)
45-
forfunctionin (TestWorker.fun,worker.fun,standalone_func):
46+
functions= (worker.fun,standalone_func,)
47+
ifsys.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+
forfunctioninfunctions:
4653
worker.inq.put((function,1))
4754
time.sleep(0.01)
4855
worker.make_assertion()

‎async/thread.py

Lines 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__importprint_function
9+
710
__docformat__="restructuredtext"
811
importthreading
912
importinspect
@@ -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
exceptStopProcessing:
195199
break
196200
exceptExceptionase:
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)

[8]ページ先頭

©2009-2025 Movatter.jp