Skip to content

Commit a39dec2

Browse files
authored
Py34 (#31)
* ssupport python 3.4 (and allow to limit legacy branch to py27 only) * split tests by python 3.4 compatible and 3.5+ compatible
1 parent 470899d commit a39dec2

12 files changed

+187
-89
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ sudo: false
22
language: python
33
os: linux
44
python:
5+
- 3.4
56
- 3.5
67
- 3.6
78
- &mainstream_python 3.7-dev

README.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ Pros:
3737

3838
::
3939

40+
Python 3.4
4041
Python 3.5
4142
Python 3.6
4243
Python 3.7
4344
PyPy3 3.5+
4445

45-
.. note:: For python 2.7/3.4/PyPy you can use versions 1.x.x
46+
.. note:: For python 2.7/PyPy you can use versions 1.x.x
4647

4748
Decorators:
4849

setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ def get_simple_vars_from_src(src):
213213

214214
'License :: OSI Approved :: Apache Software License',
215215

216+
'Programming Language :: Python :: 3.4',
216217
'Programming Language :: Python :: 3.5',
217218
'Programming Language :: Python :: 3.6',
218219
'Programming Language :: Python :: 3.7',
@@ -245,7 +246,7 @@ def get_simple_vars_from_src(src):
245246
long_description=long_description,
246247
classifiers=classifiers,
247248
keywords=keywords,
248-
python_requires='>=3.5',
249+
python_requires='>=3.4',
249250
# While setuptools cannot deal with pre-installed incompatible versions,
250251
# setting a lower bound is not harmful - it makes error messages cleaner. DO
251252
# NOT set an upper bound on setuptools, as that will lead to uninstallable

test/async_syntax/conftest.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""Test rules."""
2+
import sys
3+
4+
5+
def pytest_ignore_collect(path, config):
6+
"""Ignore sources for python 3.4."""
7+
return sys.version_info < (3, 5)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2017 Alexey Stepanov aka penguinolog
2+
##
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
import threading
16+
import unittest
17+
18+
try:
19+
import gevent
20+
import gevent.threadpool
21+
except ImportError:
22+
gevent = None
23+
24+
import threaded
25+
26+
27+
@unittest.skipIf(gevent is None, 'No gevent')
28+
class TestThreadPooled(unittest.TestCase):
29+
def tearDown(self):
30+
threaded.GThreadPooled.shutdown()
31+
32+
def test_thread_pooled_default_async(self):
33+
@threaded.gthreadpooled
34+
async def test():
35+
return threading.current_thread().name
36+
37+
pooled_name = test().wait()
38+
self.assertNotEqual(pooled_name, threading.current_thread().name)
+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Copyright 2017 Alexey Stepanov aka penguinolog
2+
##
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
import asyncio
16+
import concurrent.futures
17+
import threading
18+
import unittest
19+
20+
import threaded
21+
22+
23+
class TestThreadPooled(unittest.TestCase):
24+
def tearDown(self):
25+
threaded.ThreadPooled.shutdown()
26+
27+
def test_thread_pooled_default(self):
28+
@threaded.threadpooled
29+
async def test():
30+
return threading.current_thread().name
31+
32+
pooled_name = concurrent.futures.wait([test()])
33+
self.assertNotEqual(pooled_name, threading.current_thread().name)
34+
35+
def test_thread_pooled_construct(self):
36+
@threaded.threadpooled()
37+
async def test():
38+
return threading.current_thread().name
39+
40+
pooled_name = concurrent.futures.wait([test()])
41+
self.assertNotEqual(pooled_name, threading.current_thread().name)
42+
43+
def test_thread_pooled_loop(self):
44+
loop = asyncio.get_event_loop()
45+
46+
@threaded.threadpooled(loop_getter=loop)
47+
async def test():
48+
return threading.current_thread().name
49+
50+
pooled_name = loop.run_until_complete(asyncio.wait_for(test(), 1))
51+
self.assertNotEqual(pooled_name, threading.current_thread().name)
52+
53+
def test_thread_pooled_loop_getter(self):
54+
loop = asyncio.get_event_loop()
55+
56+
@threaded.threadpooled(loop_getter=asyncio.get_event_loop)
57+
async def test():
58+
return threading.current_thread().name
59+
60+
pooled_name = loop.run_until_complete(asyncio.wait_for(test(), 1))
61+
self.assertNotEqual(pooled_name, threading.current_thread().name)
62+
63+
def test_thread_pooled_loop_getter_context(self):
64+
loop = asyncio.get_event_loop()
65+
66+
def loop_getter(target):
67+
return target
68+
69+
@threaded.threadpooled(
70+
loop_getter=loop_getter,
71+
loop_getter_need_context=True
72+
)
73+
async def test(*args, **kwargs):
74+
return threading.current_thread().name
75+
76+
pooled_name = loop.run_until_complete(
77+
asyncio.wait_for(test(loop), 1)
78+
)
79+
self.assertNotEqual(pooled_name, threading.current_thread().name)
80+
81+
82+
class TestAsyncIOTask(unittest.TestCase):
83+
def test_default(self):
84+
@threaded.asynciotask
85+
async def test():
86+
return 'test'
87+
88+
loop = asyncio.get_event_loop()
89+
res = loop.run_until_complete(asyncio.wait_for(test(), 1))
90+
self.assertEqual(res, 'test')
91+
92+
def test_construct(self):
93+
@threaded.asynciotask()
94+
async def test():
95+
return 'test'
96+
97+
loop = asyncio.get_event_loop()
98+
res = loop.run_until_complete(asyncio.wait_for(test(), 1))
99+
self.assertEqual(res, 'test')

test/test_gevent_threadpooled.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414

15-
from os import cpu_count
15+
import os
1616
import threading
1717
import unittest
1818

@@ -38,14 +38,6 @@ def test():
3838
pooled_name = test().wait()
3939
self.assertNotEqual(pooled_name, threading.current_thread().name)
4040

41-
def test_thread_pooled_default_async(self):
42-
@threaded.gthreadpooled
43-
async def test():
44-
return threading.current_thread().name
45-
46-
pooled_name = test().wait()
47-
self.assertNotEqual(pooled_name, threading.current_thread().name)
48-
4941
def test_thread_pooled_construct(self):
5042
@threaded.gthreadpooled()
5143
def test():
@@ -60,7 +52,7 @@ def test_thread_pooled_config(self):
6052

6153
self.assertEqual(
6254
thread_pooled.executor.maxsize,
63-
(cpu_count() or 1) * 5
55+
(os.cpu_count() or 1) * 5
6456
)
6557

6658
thread_pooled.configure(max_workers=2)

test/test_pooled_async.py renamed to test/test_pooled_coroutine.py

-68
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,6 @@ def test():
3333
pooled_name = concurrent.futures.wait([test()])
3434
self.assertNotEqual(pooled_name, threading.current_thread().name)
3535

36-
def test_thread_pooled_default_a(self):
37-
@threaded.threadpooled
38-
async def test():
39-
return threading.current_thread().name
40-
41-
pooled_name = concurrent.futures.wait([test()])
42-
self.assertNotEqual(pooled_name, threading.current_thread().name)
43-
4436
def test_thread_pooled_construct(self):
4537
@threaded.threadpooled()
4638
@asyncio.coroutine
@@ -50,14 +42,6 @@ def test():
5042
pooled_name = concurrent.futures.wait([test()])
5143
self.assertNotEqual(pooled_name, threading.current_thread().name)
5244

53-
def test_thread_pooled_construct_a(self):
54-
@threaded.threadpooled()
55-
async def test():
56-
return threading.current_thread().name
57-
58-
pooled_name = concurrent.futures.wait([test()])
59-
self.assertNotEqual(pooled_name, threading.current_thread().name)
60-
6145
def test_thread_pooled_loop(self):
6246
loop = asyncio.get_event_loop()
6347

@@ -69,16 +53,6 @@ def test():
6953
pooled_name = loop.run_until_complete(asyncio.wait_for(test(), 1))
7054
self.assertNotEqual(pooled_name, threading.current_thread().name)
7155

72-
def test_thread_pooled_loop_a(self):
73-
loop = asyncio.get_event_loop()
74-
75-
@threaded.threadpooled(loop_getter=loop)
76-
async def test():
77-
return threading.current_thread().name
78-
79-
pooled_name = loop.run_until_complete(asyncio.wait_for(test(), 1))
80-
self.assertNotEqual(pooled_name, threading.current_thread().name)
81-
8256
def test_thread_pooled_loop_getter(self):
8357
loop = asyncio.get_event_loop()
8458

@@ -90,16 +64,6 @@ def test():
9064
pooled_name = loop.run_until_complete(asyncio.wait_for(test(), 1))
9165
self.assertNotEqual(pooled_name, threading.current_thread().name)
9266

93-
def test_thread_pooled_loop_getter_a(self):
94-
loop = asyncio.get_event_loop()
95-
96-
@threaded.threadpooled(loop_getter=asyncio.get_event_loop)
97-
async def test():
98-
return threading.current_thread().name
99-
100-
pooled_name = loop.run_until_complete(asyncio.wait_for(test(), 1))
101-
self.assertNotEqual(pooled_name, threading.current_thread().name)
102-
10367
def test_thread_pooled_loop_getter_context(self):
10468
loop = asyncio.get_event_loop()
10569

@@ -119,24 +83,6 @@ def test(*args, **kwargs):
11983
)
12084
self.assertNotEqual(pooled_name, threading.current_thread().name)
12185

122-
def test_thread_pooled_loop_getter_context_a(self):
123-
loop = asyncio.get_event_loop()
124-
125-
def loop_getter(target):
126-
return target
127-
128-
@threaded.threadpooled(
129-
loop_getter=loop_getter,
130-
loop_getter_need_context=True
131-
)
132-
async def test(*args, **kwargs):
133-
return threading.current_thread().name
134-
135-
pooled_name = loop.run_until_complete(
136-
asyncio.wait_for(test(loop), 1)
137-
)
138-
self.assertNotEqual(pooled_name, threading.current_thread().name)
139-
14086

14187
class TestAsyncIOTask(unittest.TestCase):
14288
def test_default(self):
@@ -149,26 +95,12 @@ def test():
14995
res = loop.run_until_complete(asyncio.wait_for(test(), 1))
15096
self.assertEqual(res, 'test')
15197

152-
def test_default_a(self):
153-
@threaded.asynciotask
154-
async def test():
155-
return 'test'
156-
157-
loop = asyncio.get_event_loop()
158-
res = loop.run_until_complete(asyncio.wait_for(test(), 1))
159-
self.assertEqual(res, 'test')
160-
16198
def test_construct(self):
16299
@threaded.asynciotask()
163100
@asyncio.coroutine
164101
def test():
165102
return 'test'
166103

167-
def test_construct_a(self):
168-
@threaded.asynciotask()
169-
async def test():
170-
return 'test'
171-
172104
loop = asyncio.get_event_loop()
173105
res = loop.run_until_complete(asyncio.wait_for(test(), 1))
174106
self.assertEqual(res, 'test')

threaded/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
"""threaded module."""
1616

17-
import typing # noqa # pylint: disable=unused-import
17+
import typing
1818

1919
# pylint: disable=no-name-in-module
2020
from ._asynciotask import AsyncIOTask, asynciotask

0 commit comments

Comments
 (0)