Skip to content

Commit

Permalink
fix compatibility with latest aiohttp (#223)
Browse files Browse the repository at this point in the history
* fix compatibility with latest aiohttp

* update HISTORY.rst

* upgrade aiohttp in travis

* fix warnings
  • Loading branch information
samuelcolvin authored Jan 31, 2019
1 parent 1375114 commit a2db359
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 17 deletions.
16 changes: 9 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@ services:
matrix:
include:
- python: '3.5'
env: 'AIOHTTP_VERSION=aiohttp==3.4.4'
env: 'AIOHTTP_VERSION=aiohttp==3.5.4' # WARNING: if you change this, change it in deploy too
- python: '3.6'
env: 'AIOHTTP_VERSION=aiohttp==3.4.4' # WARNING: if you change this, change it in deploy too
- python: '3.6'
env: 'AIOHTTP_VERSION=https://github.com/aio-libs/aiohttp/archive/master.zip'
env: 'AIOHTTP_VERSION=aiohttp==3.5.4'
- python: '3.7'
dist: xenial
sudo: required
env: 'AIOHTTP_VERSION=aiohttp==3.5.4'
- python: '3.7'
dist: xenial
sudo: required
env: 'AIOHTTP_VERSION=aiohttp==3.4.4'
env: 'AIOHTTP_VERSION=https://github.com/aio-libs/aiohttp/archive/master.zip'
- python: '3.8-dev'
dist: xenial
sudo: required
env: 'AIOHTTP_VERSION=aiohttp==3.4.4'
env: 'AIOHTTP_VERSION=aiohttp==3.5.4'

allow_failures:
- python: '3.8-dev'
Expand Down Expand Up @@ -53,4 +55,4 @@ deploy:
on:
tags: true
python: 3.6
condition: "$AIOHTTP_VERSION = aiohttp==3.4.4"
condition: "$AIOHTTP_VERSION = aiohttp==3.5.4"
3 changes: 2 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
History
-------

0.11.1 (upreleased)
0.12.0 (upreleased)
-------------------
* fix tests for python 3.7, #218
* fix tests for aiohttp >= 3.5, #223

0.11.0 (2018-12-07)
-------------------
Expand Down
3 changes: 2 additions & 1 deletion aiohttp_devtools/runserver/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ class AppTask(WatchTask):
def __init__(self, config: Config, loop: asyncio.AbstractEventLoop):
self._config = config
self._reloads = 0
self._session = ClientSession(loop=loop)
self._session = None
self._runner = None
super().__init__(self._config.watch_path, loop)

async def _run(self, live_checks=20):
self._session = ClientSession()
try:
self._start_dev_server()

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ filterwarnings =
ignore::DeprecationWarning:aiohttp_debugtoolbar.tbtools.tbtools
ignore::UserWarning:psycopg2
ignore::DeprecationWarning:aiopg
ignore::DeprecationWarning:jinja2

[flake8]
max-line-length = 120
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
aiohttp-devtools=aiohttp_devtools.cli:cli
""",
install_requires=[
'aiohttp>=3.2.0',
'aiohttp>=3.5.0',
'click>=6.6',
'isort>=4.3.3',
'Jinja2>=2.10',
Expand Down
14 changes: 7 additions & 7 deletions tests/test_runserver_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import aiohttp
import pytest
from aiohttp import ClientTimeout
from aiohttp.web import Application
from pytest_toolbox import mktree

Expand All @@ -21,15 +22,15 @@
if_boxed = get_if_boxed(pytest)


async def check_server_running(loop, check_callback):
async def check_server_running(check_callback):
port_open = False
async with aiohttp.ClientSession(loop=loop, conn_timeout=1) as session:
async with aiohttp.ClientSession(timeout=ClientTimeout(total=1)) as session:
for i in range(50):
try:
async with session.get('http://localhost:8000/'):
pass
except OSError:
await asyncio.sleep(0.1, loop=loop)
await asyncio.sleep(0.1)
else:
port_open = True
break
Expand Down Expand Up @@ -78,7 +79,7 @@ async def check_callback(session):
assert 'raise ValueError()' in (await r.text())

try:
loop.run_until_complete(check_server_running(loop, check_callback))
loop.run_until_complete(check_server_running(check_callback))
finally:
for shutdown in aux_app.on_shutdown:
loop.run_until_complete(shutdown(aux_app))
Expand All @@ -103,7 +104,6 @@ async def hello(request):
app.router.add_get('/', hello)
"""
})
asyncio.set_event_loop(loop)
aux_app, aux_port, _ = runserver(app_path='app.py', host='foobar.com')
assert isinstance(aux_app, aiohttp.web.Application)
assert aux_port == 8001
Expand Down Expand Up @@ -216,7 +216,7 @@ async def test_websocket_info(aux_cli, loop):
ws = await aux_cli.session.ws_connect(aux_cli.make_url('/livereload'))
try:
await ws.send_json({'command': 'info', 'url': 'foobar', 'plugins': 'bang'})
await asyncio.sleep(0.05, loop=loop)
await asyncio.sleep(0.05)
assert len(aux_cli.server.app['websockets']) == 1
finally:
await ws.close()
Expand Down Expand Up @@ -247,7 +247,7 @@ async def test_websocket_reload(aux_cli, loop):
'url': 'foobar',
'plugins': 'bang',
})
await asyncio.sleep(0.05, loop=loop)
await asyncio.sleep(0.05)
reloads = await src_reload(aux_cli.server.app, 'foobar')
assert reloads == 1
finally:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_runserver_watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest.mock import MagicMock, call

import pytest
from aiohttp import ClientSession
from aiohttp.web import Application

from aiohttp_devtools.runserver.watch import AppTask, LiveReloadTask
Expand Down Expand Up @@ -99,6 +100,7 @@ async def test_reload_server_running(loop, aiohttp_client, mocker):

app_task = AppTask(config, loop)
app_task._app = app
app_task._session = ClientSession() # match behaviour of _run()
await app_task._src_reload_when_live(2)
mock_src_reload.assert_called_once_with(app)
await app_task._session.close()
Expand Down

0 comments on commit a2db359

Please sign in to comment.