Skip to content

Commit

Permalink
fix never run code (#3145)
Browse files Browse the repository at this point in the history
* fix never run code

* add client session timeout arguments unit test

* add change log
  • Loading branch information
FuGangqiang authored and asvetlov committed Jul 24, 2018
1 parent 2f78996 commit 7f5d206
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGES/3145.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix timeout precondition checkers
25 changes: 11 additions & 14 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,24 +146,21 @@ def __init__(self, *, connector=None, loop=None, cookies=None,
self._json_serialize = json_serialize
if timeout is not sentinel:
self._timeout = timeout
if read_timeout is not sentinel:
raise ValueError("read_timeout and timeout parameters "
"conflict, please setup "
"timeout.read")
if conn_timeout is not None:
raise ValueError("conn_timeout and timeout parameters "
"conflict, please setup "
"timeout.connect")
else:
self._timeout = DEFAULT_TIMEOUT
if read_timeout is not sentinel:
if timeout is not sentinel:
raise ValueError("read_timeout and timeout parameters "
"conflict, please setup "
"timeout.read")
else:
self._timeout = attr.evolve(self._timeout,
total=read_timeout)
self._timeout = attr.evolve(self._timeout, total=read_timeout)
if conn_timeout is not None:
if timeout is not sentinel:
raise ValueError("conn_timeout and timeout parameters "
"conflict, please setup "
"timeout.connect")
else:
self._timeout = attr.evolve(self._timeout,
connect=conn_timeout)
self._timeout = attr.evolve(self._timeout,
connect=conn_timeout)
self._raise_for_status = raise_for_status
self._auto_decompress = auto_decompress
self._trust_env = trust_env
Expand Down
21 changes: 20 additions & 1 deletion tests/test_client_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from yarl import URL

import aiohttp
from aiohttp import hdrs, web
from aiohttp import client, hdrs, web
from aiohttp.client import ClientSession
from aiohttp.client_reqrep import ClientRequest
from aiohttp.connector import BaseConnector, TCPConnector
Expand Down Expand Up @@ -646,3 +646,22 @@ def test_client_session_custom_attr(loop):
session = ClientSession(loop=loop)
with pytest.warns(DeprecationWarning):
session.custom = None


def test_client_session_timeout_args(loop):
session1 = ClientSession(loop=loop)
assert session1._timeout == client.DEFAULT_TIMEOUT

session2 = ClientSession(loop=loop, read_timeout=20*60, conn_timeout=30*60)
assert session2._timeout == client.ClientTimeout(total=20*60,
connect=30*60)

with pytest.raises(ValueError):
ClientSession(loop=loop,
timeout=client.ClientTimeout(total=10*60),
read_timeout=20*60)

with pytest.raises(ValueError):
ClientSession(loop=loop,
timeout=client.ClientTimeout(total=10 * 60),
conn_timeout=30 * 60)

0 comments on commit 7f5d206

Please sign in to comment.