Skip to content

Commit

Permalink
Merge pull request #87 from pquentin/smurfix-upstream
Browse files Browse the repository at this point in the history
Updates for Trio 0.15
  • Loading branch information
oremanj authored Jun 25, 2020
2 parents 2440c92 + f677d95 commit 39f79e3
Show file tree
Hide file tree
Showing 21 changed files with 171 additions and 82 deletions.
10 changes: 7 additions & 3 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ os: Visual Studio 2015

environment:
matrix:
#- PYTHON: "C:\\Python35"
#- PYTHON: "C:\\Python35-x64"
- PYTHON: "C:\\Python36"
- PYTHON: "C:\\Python36-x64"
- PYTHON: "C:\\Python37"
- PYTHON: "C:\\Python37-x64"
# The Windows Python 3.8 tests currently fail on
# test_asyncio.test_windows_events.ProactorLoopCtrlC where `get_event_loop`
# fails to start a new loop
# https://ci.appveyor.com/project/smurfix/trio-asyncio/builds/33592418/job/06yddkw8wy9y6j1h
# - PYTHON: "C:\\Python38"
# - PYTHON: "C:\\Python38-x64"

build_script:
- "git --no-pager log -n2"
Expand All @@ -26,5 +30,5 @@ test_script:
- "cd empty"
# Make sure it's being imported from where we expect
- "python -c \"import os, trio_asyncio; print(os.path.dirname(trio_asyncio.__file__))\""
- "python -u -m pytest -W error -ra -v -s --cov=trio_asyncio --cov-config=../.coveragerc ../tests"
- "python -u -m pytest -ra -v -s --cov=trio_asyncio --cov-config=../.coveragerc ../tests"
- "codecov"
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ dist: xenial

matrix:
include:
- python: 3.5
- python: 3.6
- python: 3.7
- python: 3.7-dev
Expand All @@ -12,7 +11,13 @@ matrix:
- python: nightly
- os: osx
language: generic
env: MACPYTHON=3.6.3
env: MACPYTHON=3.6.8 # last binary release
- os: osx
language: generic
env: MACPYTHON=3.7.7 # last binary release
- os: osx
language: generic
env: MACPYTHON=3.8.3
- python: 3.6
env: CHECK_DOCS=1
- python: 3.6
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
**trio-asyncio** is a re-implementation of the ``asyncio`` mainloop on top of
Trio.

trio-asyncio requires at least Python 3.5.3. It is tested on recent versions of
3.5, 3.6, 3.7, 3.8, and nightly.
Trio-Asyncio requires at least Python 3.6. It is tested on recent versions of
3.6, 3.7, 3.8, and nightly.

+++++++++++
Rationale
Expand Down
2 changes: 1 addition & 1 deletion ci/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -ex
YAPF_VERSION=0.20.0

if [ "$TRAVIS_OS_NAME" = "osx" ]; then
curl -Lo macpython.pkg https://www.python.org/ftp/python/${MACPYTHON}/python-${MACPYTHON}-macosx10.6.pkg
curl -Lo macpython.pkg https://www.python.org/ftp/python/${MACPYTHON}/python-${MACPYTHON}-macosx10.9.pkg
sudo installer -pkg macpython.pkg -target /
ls /Library/Frameworks/Python.framework/Versions/*/bin/
PYTHON_EXE=/Library/Frameworks/Python.framework/Versions/*/bin/python3
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ asyncio libraries such as ``home-assistant``.
Helpful facts:

* Supported environments: Linux, MacOS, or Windows running some kind of Python
3.5.3-or-better (either CPython or PyPy3 is fine). \*BSD and illumOS likely
3.6-or-better (either CPython or PyPy3 is fine). \*BSD and illumOS likely
work too, but are untested.

* Install: ``python3 -m pip install -U trio-asyncio`` (or on Windows, maybe
Expand Down
2 changes: 1 addition & 1 deletion docs/source/principles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Most *synchronous* asyncio or Trio functions (:meth:`trio.Event.set`,
asyncio or Trio context, and work equally well regardless of the
flavor of function calling them. The exceptions are functions that
access the current task (:func:`asyncio.current_task`,
:func:`trio.hazmat.current_task`, and anything that calls them),
:func:`trio.lowlevel.current_task`, and anything that calls them),
because there's only a meaningful concept of the current *foo* task
when a *foo*-flavored function is executing. For example, this means
context managers that set a timeout on their body (``with
Expand Down
3 changes: 3 additions & 0 deletions newsfragments/82.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
``trio-asyncio`` now requires Trio 0.15.

Support for Python < 3.6 has been removed.
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ max-line-length=99
ignore=E402,E731,E127,E502,E123,W503
[tool:pytest]
addopts = -p no:asyncio
filterwarnings =
error
ignore:The loop argument is deprecated*:DeprecationWarning
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
code (asyncio: ~8000) but passes the complete Python 3.6 test suite with no
errors.
``trio_asyncio`` requires Python 3.5.3 or better.
``trio_asyncio`` requires Python 3.6 or better.
Author
======
Expand All @@ -53,12 +53,12 @@
"""

install_requires = [
"trio >= 0.12.0",
"async_generator >= 1.6",
"trio >= 0.15.0",
"outcome",
]
if sys.version_info < (3, 7):
install_requires.append("contextvars >= 2.1")
install_requires.append("async_generator >= 1.6")

setup(
name="trio_asyncio",
Expand All @@ -74,10 +74,10 @@
# This means, just install *everything* you see under trio/, even if it
# doesn't look like a source file, so long as it appears in MANIFEST.in:
include_package_data=True,
python_requires=">=3.5.2", # temporary, for RTD
python_requires=">=3.6", # temporary, for RTD
keywords=["async", "io", "trio", "asyncio", "trio-asyncio"],
setup_requires=['pytest-runner'],
tests_require=['pytest', 'outcome'],
tests_require=['pytest >= 5.4', 'pytest-trio >= 0.6', 'outcome'],
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
Expand Down
3 changes: 1 addition & 2 deletions tests/aiotest/test_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ async def test_close(self, loop, config):
await loop.stop().wait()
loop.close()

@config.asyncio.coroutine
def test():
async def test():
pass

func = lambda: False
Expand Down
4 changes: 1 addition & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import asyncio
import trio_asyncio
import inspect
from async_generator import async_generator, yield_

# Hacks for <3.7
if not hasattr(asyncio, 'run'):
Expand Down Expand Up @@ -45,11 +44,10 @@ def create_task(coro):


@pytest.fixture
@async_generator
async def loop():
async with trio_asyncio.open_loop() as loop:
try:
await yield_(loop)
yield loop
finally:
await loop.stop().wait()

Expand Down
22 changes: 10 additions & 12 deletions tests/interop/test_adapter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
from async_generator import async_generator, yield_
from trio_asyncio import aio_as_trio, trio_as_aio, allow_asyncio
from trio_asyncio import aio2trio, trio2aio
import asyncio
Expand All @@ -8,7 +7,10 @@
from tests import aiotest
import sys
import warnings
from async_generator import asynccontextmanager
try:
from contextlib import asynccontextmanager
except ImportError:
from async_generator import asynccontextmanager
from .. import utils as test_utils
from trio_asyncio import TrioAsyncioDeprecationWarning

Expand Down Expand Up @@ -74,43 +76,39 @@ async def dly_asyncio(self, do_test=True):
self.flag |= 1
return 4

@async_generator
async def iter_asyncio(self, do_test=True):
if do_test and sys.version_info >= (3, 7):
assert sniffio.current_async_library() == "asyncio"
await asyncio.sleep(0.01, loop=self.loop)
await yield_(1)
yield 1
await asyncio.sleep(0.01, loop=self.loop)
await yield_(2)
yield 2
await asyncio.sleep(0.01, loop=self.loop)
self.flag |= 1

@async_generator
async def iter_trio(self):
if sys.version_info >= (3, 7):
assert sniffio.current_async_library() == "trio"
await trio.sleep(0.01)
await yield_(1)
yield 1
await trio.sleep(0.01)
await yield_(2)
yield 2
await trio.sleep(0.01)
self.flag |= 1

@asynccontextmanager
@async_generator
async def ctx_asyncio(self):
await asyncio.sleep(0.01, loop=self.loop)
self.flag |= 1
await yield_(self)
yield self
await asyncio.sleep(0.01, loop=self.loop)
self.flag |= 2

@asynccontextmanager
@async_generator
async def ctx_trio(self):
await trio.sleep(0.01)
self.flag |= 1
await yield_(self)
yield self
await trio.sleep(0.01)
self.flag |= 2

Expand Down
22 changes: 8 additions & 14 deletions tests/interop/test_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import asyncio
import trio
import sniffio
from async_generator import async_generator, yield_
from trio_asyncio import aio_as_trio, trio_as_aio
from tests import aiotest
from functools import partial
Expand Down Expand Up @@ -303,7 +302,7 @@ async def test_asyncio_trio_cancel_out(self, loop):
async def cancelled_trio(seen):
seen.flag |= 1
await trio.sleep(0.01)
scope = trio.hazmat.current_task()._cancel_status._scope
scope = trio.lowlevel.current_task()._cancel_status._scope
scope.cancel()
seen.flag |= 2
await trio.sleep(0.01)
Expand Down Expand Up @@ -526,23 +525,21 @@ def err_asyncio():

@pytest.mark.trio
async def test_trio_asyncio_generator(self, loop):
@async_generator
async def dly_asyncio():
await yield_(1)
yield 1
await asyncio.sleep(0.01, loop=loop)
await yield_(2)
yield 2

with test_utils.deprecate(self):
res = await async_gen_to_list(loop.wrap_generator(dly_asyncio))
assert res == [1, 2]

@pytest.mark.trio
async def test_trio_asyncio_generator_with_error(self, loop):
@async_generator
async def dly_asyncio():
await yield_(1)
yield 1
raise RuntimeError("I has an owie")
await yield_(2)
yield 2

with test_utils.deprecate(self):
with pytest.raises(RuntimeError) as err:
Expand All @@ -551,9 +548,8 @@ async def dly_asyncio():

@pytest.mark.trio
async def test_trio_asyncio_generator_with_cancellation(self, loop):
@async_generator
async def dly_asyncio(hold, seen):
await yield_(1)
yield 1
seen.flag |= 1
await hold.wait()

Expand All @@ -573,11 +569,10 @@ async def cancel_soon(nursery):

@pytest.mark.trio
async def test_trio_asyncio_iterator(self, loop):
@async_generator
async def slow_nums():
for n in range(1, 6):
await asyncio.sleep(0.01, loop=loop)
await yield_(n)
yield n

sum = 0
async for n in aio_as_trio(slow_nums()):
Expand All @@ -586,11 +581,10 @@ async def slow_nums():

@pytest.mark.trio
async def test_trio_asyncio_iterator_depr(self, loop):
@async_generator
async def slow_nums():
for n in range(1, 6):
await asyncio.sleep(0.01, loop=loop)
await yield_(n)
yield n

sum = 0
# with test_utils.deprecate(self): ## not yet
Expand Down
8 changes: 6 additions & 2 deletions tests/python/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
# to the event loop in the testsuite class, because
# SyncTrioEventLoop spawns a thread that only exits when the
# loop is closed. Nerf it.
from test.support import threading_cleanup
try:
from test.support import threading_cleanup
except ImportError:
# Python 3.10+
from test.support.threading_helper import threading_cleanup

def threading_no_cleanup(*original_values):
pass
Expand Down Expand Up @@ -124,7 +128,7 @@ def skip(rel_id):

# These fail with ConnectionResetError on Pythons <= 3.7.x
# for some unknown x. (3.7.1 fails, 3.7.5 and 3.7.6 pass;
# older 3.6.x also affected, and older-or-all 3.5.x)
# older 3.6.x also affected)
if sys.platform != "win32" and sys.version_info < (3, 8):
import selectors

Expand Down
4 changes: 2 additions & 2 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def close_no_stop():
async def test_too_many_stops(self):
with trio.move_on_after(1) as scope:
async with trio_asyncio.open_loop() as loop:
await trio.hazmat.checkpoint()
await trio.lowlevel.checkpoint()
loop.stop()
assert not scope.cancelled_caught, \
"Possible deadlock after manual call to loop.stop"
Expand Down Expand Up @@ -167,7 +167,7 @@ async def nest(x):
with pytest.raises(RuntimeError):
trio_asyncio.run_trio_task(nest, 100)

with pytest.raises(RuntimeError):
with pytest.raises((AttributeError, RuntimeError)):
with trio_asyncio.open_loop():
nest(1000)

Expand Down
38 changes: 38 additions & 0 deletions tests/test_trio_asyncio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pytest
import sys
import asyncio
from async_generator import async_generator, yield_
import trio_asyncio


async def use_asyncio():
await trio_asyncio.aio_as_trio(asyncio.sleep)(0)


@pytest.fixture()
async def asyncio_fixture_with_fixtured_loop(loop):
await use_asyncio()
yield None


@pytest.fixture()
async def asyncio_fixture_own_loop():
async with trio_asyncio.open_loop():
await use_asyncio()
yield None


@pytest.mark.trio
async def test_no_fixture():
async with trio_asyncio.open_loop():
await use_asyncio()


@pytest.mark.trio
async def test_half_fixtured_asyncpg_conn(asyncio_fixture_own_loop):
await use_asyncio()


@pytest.mark.trio
async def test_fixtured_asyncpg_conn(asyncio_fixture_with_fixtured_loop):
await use_asyncio()
Loading

0 comments on commit 39f79e3

Please sign in to comment.