Skip to content

Commit

Permalink
Merge pull request #186 from pnuckowski/bugfix/version-parsing
Browse files Browse the repository at this point in the history
fix version parsing
  • Loading branch information
pnuckowski authored Mar 9, 2021
2 parents c30d4a5 + af1ddfe commit ceab0a5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
7 changes: 3 additions & 4 deletions aioresponses/compat.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
# -*- coding: utf-8 -*-
import asyncio # noqa: F401
import sys
from distutils.version import StrictVersion
from typing import Dict, Optional, Tuple, Union # noqa
from urllib.parse import parse_qsl, urlencode

from aiohttp import __version__ as aiohttp_version, StreamReader
from multidict import MultiDict
from yarl import URL

from pkg_resources import parse_version
if sys.version_info < (3, 7):
from re import _pattern_type as Pattern
else:
from re import Pattern

AIOHTTP_VERSION = StrictVersion(aiohttp_version)
AIOHTTP_VERSION = parse_version(aiohttp_version)

if AIOHTTP_VERSION >= StrictVersion('3.0.0'):
if AIOHTTP_VERSION >= parse_version('3.0.0'):
from aiohttp.client_proto import ResponseHandler


Expand Down
8 changes: 4 additions & 4 deletions aioresponses/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import inspect
import json
from collections import namedtuple
from distutils.version import StrictVersion
from functools import wraps
from typing import Callable, Dict, Tuple, Union, Optional, List # noqa
from unittest.mock import Mock, patch
Expand All @@ -19,6 +18,7 @@
)
from aiohttp.helpers import TimerNoop
from multidict import CIMultiDict, CIMultiDictProxy
from pkg_resources import parse_version

from .compat import (
AIOHTTP_VERSION,
Expand Down Expand Up @@ -132,7 +132,7 @@ def _build_response(self, url: 'Union[URL, str]',
if request_headers is None:
request_headers = {}
kwargs = {}
if AIOHTTP_VERSION >= StrictVersion('3.1.0'):
if AIOHTTP_VERSION >= parse_version('3.1.0'):
loop = Mock()
loop.get_debug = Mock()
loop.get_debug.return_value = True
Expand All @@ -144,7 +144,7 @@ def _build_response(self, url: 'Union[URL, str]',
kwargs['writer'] = Mock()
kwargs['continue100'] = None
kwargs['timer'] = TimerNoop()
if AIOHTTP_VERSION < StrictVersion('3.3.0'):
if AIOHTTP_VERSION < parse_version('3.3.0'):
kwargs['auto_decompress'] = True
kwargs['traces'] = []
kwargs['loop'] = loop
Expand All @@ -161,7 +161,7 @@ def _build_response(self, url: 'Union[URL, str]',
for hdr in _headers.getall(hdrs.SET_COOKIE, ()):
resp.cookies.load(hdr)

if AIOHTTP_VERSION >= StrictVersion('3.3.0'):
if AIOHTTP_VERSION >= parse_version('3.3.0'):
# Reified attributes
resp._headers = _headers
resp._raw_headers = raw_headers
Expand Down
9 changes: 5 additions & 4 deletions tests/test_aioresponses.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from aiohttp.client import ClientSession
from aiohttp.client_reqrep import ClientResponse
from ddt import ddt, data
from pkg_resources import parse_version

try:
from aiohttp.errors import (
Expand Down Expand Up @@ -117,7 +118,7 @@ async def test_raise_for_status(self, m):
self.assertEqual(cm.exception.message, http.RESPONSES[400][0])

@aioresponses()
@skipIf(condition=AIOHTTP_VERSION < '3.4.0',
@skipIf(condition=AIOHTTP_VERSION < parse_version('3.4.0'),
reason='aiohttp<3.4.0 does not support raise_for_status '
'arguments for requests')
async def test_request_raise_for_status(self, m):
Expand Down Expand Up @@ -524,7 +525,7 @@ async def test_raise_for_status(self, m):
self.assertEqual(cm.exception.message, http.RESPONSES[400][0])

@aioresponses()
@skipIf(condition=AIOHTTP_VERSION < '3.4.0',
@skipIf(condition=AIOHTTP_VERSION < parse_version('3.4.0'),
reason='aiohttp<3.4.0 does not support raise_for_status '
'arguments for requests')
async def test_do_not_raise_for_status(self, m):
Expand Down Expand Up @@ -602,7 +603,7 @@ async def test_redirect_missing_location_header(self, rsps):
self.assertEqual(str(response.url), self.url)

@aioresponses()
@skipIf(condition=AIOHTTP_VERSION < '3.1.0',
@skipIf(condition=AIOHTTP_VERSION < parse_version('3.1.0'),
reason='aiohttp<3.1.0 does not add request info on response')
async def test_request_info(self, rsps):
rsps.get(self.url, status=200)
Expand All @@ -614,7 +615,7 @@ async def test_request_info(self, rsps):
assert request_info.headers == {}

@aioresponses()
@skipIf(condition=AIOHTTP_VERSION < '3.1.0',
@skipIf(condition=AIOHTTP_VERSION < parse_version('3.1.0'),
reason='aiohttp<3.1.0 does not add request info on response')
async def test_request_info_with_original_request_headers(self, rsps):
headers = {"Authorization": "Bearer access-token"}
Expand Down

0 comments on commit ceab0a5

Please sign in to comment.