From d1c213c23bcb8f864b6e093dd47c4df14b185bb9 Mon Sep 17 00:00:00 2001 From: alfred82santa Date: Wed, 3 Mar 2021 22:05:48 +0100 Subject: [PATCH] Fix tests 3 --- service_client/__init__.py | 2 +- service_client/formatters.py | 5 +++-- service_client/mocks.py | 4 +--- tests/__init__.py | 2 +- tests/tests_plugins.py | 2 +- tests/tests_service_client.py | 2 +- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/service_client/__init__.py b/service_client/__init__.py index 70989c6..b192636 100644 --- a/service_client/__init__.py +++ b/service_client/__init__.py @@ -4,7 +4,7 @@ try: current_task = Task.current_task -except AttributeError: +except AttributeError: # pragma: no cover from asyncio import current_task from aiohttp.client import ClientSession diff --git a/service_client/formatters.py b/service_client/formatters.py index 89f2a93..8481219 100644 --- a/service_client/formatters.py +++ b/service_client/formatters.py @@ -1,6 +1,6 @@ -from urllib.parse import urlencode from http.server import BaseHTTPRequestHandler from logging import Formatter, PercentStyle, StrFormatStyle, StringTemplateStyle +from urllib.parse import urlencode _STYLES = { '%': PercentStyle, @@ -70,7 +70,8 @@ def formatMessage(self, record): pass try: - record.exception_repr = repr(record.exception) + record.exception_repr = "{type}('{message}')".format(type=type(record.exception).__name__, + message=str(record.exception)) except AttributeError: pass diff --git a/service_client/mocks.py b/service_client/mocks.py index f593fda..c1f01b3 100644 --- a/service_client/mocks.py +++ b/service_client/mocks.py @@ -2,7 +2,6 @@ from asyncio.futures import Future from functools import wraps - from aiohttp import RequestInfo from aiohttp.client_reqrep import ClientResponse from aiohttp.helpers import TimerContext @@ -194,7 +193,7 @@ def __init__(self, endpoint_desc, session, request_params, async def __call__(self, *args, **kwargs): try: from asyncio import create_task - except IndexError: + except ImportError: # pragma: no cover create_task = self.loop.create_task args = list(args) @@ -208,7 +207,6 @@ async def __call__(self, *args, **kwargs): except KeyError: url = args.pop() - self.method = method self.url = url self.args = args diff --git a/tests/__init__.py b/tests/__init__.py index 7eb71f4..ab224de 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -10,7 +10,7 @@ async def create_fake_response(method, url, *, session, headers=None, loop=None) try: from asyncio import create_task - except ImportError: + except ImportError: # pragma: no cover create_task = loop.create_task async def writer(*args, **kwargs): diff --git a/tests/tests_plugins.py b/tests/tests_plugins.py index 3b4ac07..d324d12 100644 --- a/tests/tests_plugins.py +++ b/tests/tests_plugins.py @@ -10,7 +10,7 @@ try: all_tasks = Task.all_tasks -except AttributeError: +except AttributeError: # pragma: no cover from asyncio import all_tasks from aiohttp.client import ClientSession diff --git a/tests/tests_service_client.py b/tests/tests_service_client.py index 0f8e0e0..907f5d1 100644 --- a/tests/tests_service_client.py +++ b/tests/tests_service_client.py @@ -4,7 +4,7 @@ try: current_task = Task.current_task -except AttributeError: +except AttributeError: # pragma: no cover from asyncio import current_task from aiohttp import RequestInfo