-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ssupport python 3.4 (and allow to limit legacy branch to py27 only) * split tests by python 3.4 compatible and 3.5+ compatible
- Loading branch information
1 parent
470899d
commit a39dec2
Showing
12 changed files
with
187 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ sudo: false | |
language: python | ||
os: linux | ||
python: | ||
- 3.4 | ||
- 3.5 | ||
- 3.6 | ||
- &mainstream_python 3.7-dev | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"""Test rules.""" | ||
import sys | ||
|
||
|
||
def pytest_ignore_collect(path, config): | ||
"""Ignore sources for python 3.4.""" | ||
return sys.version_info < (3, 5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright 2017 Alexey Stepanov aka penguinolog | ||
## | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import threading | ||
import unittest | ||
|
||
try: | ||
import gevent | ||
import gevent.threadpool | ||
except ImportError: | ||
gevent = None | ||
|
||
import threaded | ||
|
||
|
||
@unittest.skipIf(gevent is None, 'No gevent') | ||
class TestThreadPooled(unittest.TestCase): | ||
def tearDown(self): | ||
threaded.GThreadPooled.shutdown() | ||
|
||
def test_thread_pooled_default_async(self): | ||
@threaded.gthreadpooled | ||
async def test(): | ||
return threading.current_thread().name | ||
|
||
pooled_name = test().wait() | ||
self.assertNotEqual(pooled_name, threading.current_thread().name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# Copyright 2017 Alexey Stepanov aka penguinolog | ||
## | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import asyncio | ||
import concurrent.futures | ||
import threading | ||
import unittest | ||
|
||
import threaded | ||
|
||
|
||
class TestThreadPooled(unittest.TestCase): | ||
def tearDown(self): | ||
threaded.ThreadPooled.shutdown() | ||
|
||
def test_thread_pooled_default(self): | ||
@threaded.threadpooled | ||
async def test(): | ||
return threading.current_thread().name | ||
|
||
pooled_name = concurrent.futures.wait([test()]) | ||
self.assertNotEqual(pooled_name, threading.current_thread().name) | ||
|
||
def test_thread_pooled_construct(self): | ||
@threaded.threadpooled() | ||
async def test(): | ||
return threading.current_thread().name | ||
|
||
pooled_name = concurrent.futures.wait([test()]) | ||
self.assertNotEqual(pooled_name, threading.current_thread().name) | ||
|
||
def test_thread_pooled_loop(self): | ||
loop = asyncio.get_event_loop() | ||
|
||
@threaded.threadpooled(loop_getter=loop) | ||
async def test(): | ||
return threading.current_thread().name | ||
|
||
pooled_name = loop.run_until_complete(asyncio.wait_for(test(), 1)) | ||
self.assertNotEqual(pooled_name, threading.current_thread().name) | ||
|
||
def test_thread_pooled_loop_getter(self): | ||
loop = asyncio.get_event_loop() | ||
|
||
@threaded.threadpooled(loop_getter=asyncio.get_event_loop) | ||
async def test(): | ||
return threading.current_thread().name | ||
|
||
pooled_name = loop.run_until_complete(asyncio.wait_for(test(), 1)) | ||
self.assertNotEqual(pooled_name, threading.current_thread().name) | ||
|
||
def test_thread_pooled_loop_getter_context(self): | ||
loop = asyncio.get_event_loop() | ||
|
||
def loop_getter(target): | ||
return target | ||
|
||
@threaded.threadpooled( | ||
loop_getter=loop_getter, | ||
loop_getter_need_context=True | ||
) | ||
async def test(*args, **kwargs): | ||
return threading.current_thread().name | ||
|
||
pooled_name = loop.run_until_complete( | ||
asyncio.wait_for(test(loop), 1) | ||
) | ||
self.assertNotEqual(pooled_name, threading.current_thread().name) | ||
|
||
|
||
class TestAsyncIOTask(unittest.TestCase): | ||
def test_default(self): | ||
@threaded.asynciotask | ||
async def test(): | ||
return 'test' | ||
|
||
loop = asyncio.get_event_loop() | ||
res = loop.run_until_complete(asyncio.wait_for(test(), 1)) | ||
self.assertEqual(res, 'test') | ||
|
||
def test_construct(self): | ||
@threaded.asynciotask() | ||
async def test(): | ||
return 'test' | ||
|
||
loop = asyncio.get_event_loop() | ||
res = loop.run_until_complete(asyncio.wait_for(test(), 1)) | ||
self.assertEqual(res, 'test') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.