Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix python 3.8 tests under Windows #4513

Merged
merged 12 commits into from
Jan 18, 2020
15 changes: 15 additions & 0 deletions .azure-pipelines/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ stages:
py37 x64:
python.code: 'cp37-cp37m'
manylinux: 'manylinux_64'
py38 x64:
python.code: 'cp38-cp38'
manylinux: 'manylinux_64'
pool:
vmImage: 'ubuntu-latest'
container: manylinux
Expand Down Expand Up @@ -97,6 +100,10 @@ stages:
python.version: '3.7'
python.architecture: 'x64'
image: 'windows-latest'
Win py38 x64:
python.version: '3.8'
python.architecture: 'x64'
image: 'windows-latest'
Win py36 x86:
python.version: '3.6'
python.architecture: 'x86'
Expand All @@ -105,6 +112,10 @@ stages:
python.version: '3.7'
python.architecture: 'x86'
image: 'windows-latest'
Win py38 x86:
python.version: '3.8'
python.architecture: 'x86'
image: 'windows-latest'
Mac py36:
python.version: '3.6'
image: 'macos-latest'
Expand All @@ -113,6 +124,10 @@ stages:
python.version: '3.7'
image: 'macos-latest'
python.architecture: 'x64'
Mac py38:
python.version: '3.8'
image: 'macos-latest'
python.architecture: 'x64'
pool:
vmImage: '$(image)'
steps:
Expand Down
16 changes: 16 additions & 0 deletions .azure-pipelines/stage-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ stages:
python.version: '3.7'
no_extensions: ''
image: 'ubuntu-latest'
Py38-Cython-Linux:
python.version: '3.8'
no_extensions: ''
image: 'ubuntu-latest'
Py36-Pure-Linux:
python.version: '3.6'
no_extensions: 'Y'
Expand All @@ -22,6 +26,10 @@ stages:
python.version: '3.7'
no_extensions: 'Y'
image: 'ubuntu-latest'
Py38-Pure-Linux:
python.version: '3.8'
no_extensions: 'Y'
image: 'ubuntu-latest'
# PyPy3-Linux:
# python.version: 'pypy3'
# no_extensions: 'Y'
Expand All @@ -34,6 +42,10 @@ stages:
python.version: '3.7'
no_extensions: ''
image: 'windows-latest'
Py38-Cython-Win:
python.version: '3.8'
no_extensions: ''
image: 'windows-latest'
Py36-Cython-Mac:
python.version: '3.6'
no_extensions: ''
Expand All @@ -42,6 +54,10 @@ stages:
python.version: '3.7'
no_extensions: ''
image: 'macos-latest'
Py38-Cython-Mac:
python.version: '3.8'
no_extensions: ''
image: 'macos-latest'
pool:
vmImage: '$(image)'

Expand Down
1 change: 1 addition & 0 deletions CHANGES/4513.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pass tests on Python 3.8 for Windows.
20 changes: 20 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import os
import socket
import ssl
Expand All @@ -10,6 +11,8 @@

import pytest

from aiohttp.test_utils import loop_context

try:
import trustme
TRUSTME = True
Expand Down Expand Up @@ -174,3 +177,20 @@ def assert_sock_fits(sock_path):
assert_sock_fits(sock_path)
yield sock_path
return


@pytest.fixture
def selector_loop():
if sys.version_info < (3, 7):
policy = asyncio.get_event_loop_policy()
policy._loop_factory = asyncio.SelectorEventLoop # type: ignore
else:
if sys.version_info >= (3, 8):
policy = asyncio.WindowsSelectorEventLoopPolicy() # type: ignore
else:
policy = asyncio.DefaultEventLoopPolicy()
asyncio.set_event_loop_policy(policy)

with loop_context(policy.new_event_loop) as _loop:
asyncio.set_event_loop(_loop)
yield _loop
13 changes: 9 additions & 4 deletions tests/test_client_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import gc
import json
import re
import sys
from http.cookies import SimpleCookie
from io import BytesIO
from unittest import mock
Expand Down Expand Up @@ -593,7 +594,7 @@ async def on_response_chunk_received(session, context, params):
{'ok': True}).encode('utf8')


async def test_request_tracing_exception(loop) -> None:
async def test_request_tracing_exception() -> None:
on_request_end = mock.Mock(side_effect=make_mocked_coro(mock.Mock()))
on_request_exception = mock.Mock(
side_effect=make_mocked_coro(mock.Mock())
Expand All @@ -605,9 +606,13 @@ async def test_request_tracing_exception(loop) -> None:

with mock.patch("aiohttp.client.TCPConnector.connect") as connect_patched:
error = Exception()
f = loop.create_future()
f.set_exception(error)
connect_patched.return_value = f
if sys.version_info >= (3, 8, 1):
connect_patched.side_effect = error
else:
loop = asyncio.get_event_loop()
f = loop.create_future()
f.set_exception(error)
connect_patched.return_value = f

session = aiohttp.ClientSession(
trace_configs=[trace_config]
Expand Down
5 changes: 4 additions & 1 deletion tests/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1992,7 +1992,10 @@ async def test_unix_connector_permission(loop) -> None:

@pytest.mark.skipif(platform.system() != "Windows",
reason="Proactor Event loop present only in Windows")
async def test_named_pipe_connector_wrong_loop(pipe_name) -> None:
async def test_named_pipe_connector_wrong_loop(
selector_loop,
pipe_name
) -> None:
with pytest.raises(RuntimeError):
aiohttp.NamedPipeConnector(pipe_name)

Expand Down
25 changes: 15 additions & 10 deletions tests/test_multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import io
import json
import pathlib
import sys
import zlib
from unittest import mock

Expand Down Expand Up @@ -171,13 +172,15 @@ async def test_read_chunk_without_content_length(self, newline) -> None:
assert c3 == b''

async def test_read_incomplete_chunk(self, newline) -> None:
loop = asyncio.get_event_loop()
stream = Stream(b'')

def prepare(data):
f = loop.create_future()
f.set_result(data)
return f
if sys.version_info >= (3, 8, 1):
# Workaround for a weird behavior of patch.object
def prepare(data):
return data
else:
async def prepare(data):
return data

with mock.patch.object(stream, 'read', side_effect=[
prepare(b'Hello, '),
Expand Down Expand Up @@ -218,13 +221,15 @@ async def test_read_incomplete_body_chunked(self, newline) -> None:
assert data == result

async def test_read_boundary_with_incomplete_chunk(self, newline) -> None:
loop = asyncio.get_event_loop()
stream = Stream(b'')

def prepare(data):
f = loop.create_future()
f.set_result(data)
return f
if sys.version_info >= (3, 8, 1):
# Workaround for weird 3.8.1 patch.object() behavior
def prepare(data):
return data
else:
async def prepare(data):
return data

with mock.patch.object(stream, 'read', side_effect=[
prepare(b'Hello, World'),
Expand Down
10 changes: 8 additions & 2 deletions tests/test_web_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,10 @@ async def handler(request):
assert 413 == resp.status
resp_text = await resp.text()
assert 'Maximum request body size 1048576 exceeded, ' \
'actual body size 1048591' in resp_text
'actual body size' in resp_text
# Maximum request body size X exceeded, actual body size X
body_size = int(resp_text.split()[-1])
assert body_size >= max_size


async def test_app_max_client_size_adjusted(aiohttp_client) -> None:
Expand All @@ -1469,7 +1472,10 @@ async def handler(request):
assert 413 == resp.status
resp_text = await resp.text()
assert 'Maximum request body size 2097152 exceeded, ' \
'actual body size 2097166' in resp_text
'actual body size' in resp_text
# Maximum request body size X exceeded, actual body size X
body_size = int(resp_text.split()[-1])
assert body_size >= custom_max_size


async def test_app_max_client_size_none(aiohttp_client) -> None:
Expand Down
6 changes: 5 additions & 1 deletion tests/test_web_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ async def test_addresses(make_runner, unix_sockname) -> None:

@pytest.mark.skipif(platform.system() != "Windows",
reason="Proactor Event loop present only in Windows")
async def test_named_pipe_runner_wrong_loop(app, pipe_name) -> None:
async def test_named_pipe_runner_wrong_loop(
app,
selector_loop,
pipe_name
) -> None:
runner = web.AppRunner(app)
await runner.setup()
with pytest.raises(RuntimeError):
Expand Down