Skip to content

Commit

Permalink
Py34 (#31)
Browse files Browse the repository at this point in the history
* 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
penguinolog committed Sep 5, 2018
1 parent 470899d commit a39dec2
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 89 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ sudo: false
language: python
os: linux
python:
- 3.4
- 3.5
- 3.6
- &mainstream_python 3.7-dev
Expand Down
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ Pros:

::

Python 3.4
Python 3.5
Python 3.6
Python 3.7
PyPy3 3.5+

.. note:: For python 2.7/3.4/PyPy you can use versions 1.x.x
.. note:: For python 2.7/PyPy you can use versions 1.x.x

Decorators:

Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def get_simple_vars_from_src(src):

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

'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
Expand Down Expand Up @@ -245,7 +246,7 @@ def get_simple_vars_from_src(src):
long_description=long_description,
classifiers=classifiers,
keywords=keywords,
python_requires='>=3.5',
python_requires='>=3.4',
# While setuptools cannot deal with pre-installed incompatible versions,
# setting a lower bound is not harmful - it makes error messages cleaner. DO
# NOT set an upper bound on setuptools, as that will lead to uninstallable
Expand Down
7 changes: 7 additions & 0 deletions test/async_syntax/conftest.py
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)
38 changes: 38 additions & 0 deletions test/async_syntax/test_gevent_threadpooled_async.py
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)
99 changes: 99 additions & 0 deletions test/async_syntax/test_pooled_async.py
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')
12 changes: 2 additions & 10 deletions test/test_gevent_threadpooled.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.

from os import cpu_count
import os
import threading
import unittest

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

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)

def test_thread_pooled_construct(self):
@threaded.gthreadpooled()
def test():
Expand All @@ -60,7 +52,7 @@ def test_thread_pooled_config(self):

self.assertEqual(
thread_pooled.executor.maxsize,
(cpu_count() or 1) * 5
(os.cpu_count() or 1) * 5
)

thread_pooled.configure(max_workers=2)
Expand Down
68 changes: 0 additions & 68 deletions test/test_pooled_async.py → test/test_pooled_coroutine.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ def test():
pooled_name = concurrent.futures.wait([test()])
self.assertNotEqual(pooled_name, threading.current_thread().name)

def test_thread_pooled_default_a(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()
@asyncio.coroutine
Expand All @@ -50,14 +42,6 @@ def test():
pooled_name = concurrent.futures.wait([test()])
self.assertNotEqual(pooled_name, threading.current_thread().name)

def test_thread_pooled_construct_a(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()

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

def test_thread_pooled_loop_a(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()

Expand All @@ -90,16 +64,6 @@ def test():
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_a(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()

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

def test_thread_pooled_loop_getter_context_a(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):
Expand All @@ -149,26 +95,12 @@ def test():
res = loop.run_until_complete(asyncio.wait_for(test(), 1))
self.assertEqual(res, 'test')

def test_default_a(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()
@asyncio.coroutine
def test():
return 'test'

def test_construct_a(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')
2 changes: 1 addition & 1 deletion threaded/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""threaded module."""

import typing # noqa # pylint: disable=unused-import
import typing

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

0 comments on commit a39dec2

Please sign in to comment.