diff --git a/sdk/core/azure-core/samples/example_tracing_async.py b/sdk/core/azure-core/samples/example_tracing_async.py index 9a5395d3d146..49e9e24283a3 100644 --- a/sdk/core/azure-core/samples/example_tracing_async.py +++ b/sdk/core/azure-core/samples/example_tracing_async.py @@ -1,3 +1,8 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- """ FILE: example_async_tracing.py DESCRIPTION: diff --git a/sdk/core/azure-core/samples/test_example_async.py b/sdk/core/azure-core/samples/test_example_async.py index 423e9f2f3fa6..e6f496bdf8be 100644 --- a/sdk/core/azure-core/samples/test_example_async.py +++ b/sdk/core/azure-core/samples/test_example_async.py @@ -23,7 +23,7 @@ # THE SOFTWARE. # # -------------------------------------------------------------------------- -# pylint: disable=non-abstract-transport-import,networking-import-outside-azure-core-transport +# pylint: disable=non-abstract-transport-import,networking-import-outside-azure-core-transport,protected-access from typing import Iterable, MutableSequence, Union import pytest diff --git a/sdk/core/azure-core/samples/test_example_sansio.py b/sdk/core/azure-core/samples/test_example_sansio.py index f7f5aed5ddc0..addc60949862 100644 --- a/sdk/core/azure-core/samples/test_example_sansio.py +++ b/sdk/core/azure-core/samples/test_example_sansio.py @@ -23,6 +23,7 @@ # THE SOFTWARE. # # -------------------------------------------------------------------------- +# pylint: disable=protected-access from azure.core.pipeline import PipelineRequest from azure.core.rest import HttpRequest, HttpResponse diff --git a/sdk/core/azure-core/samples/test_example_sync.py b/sdk/core/azure-core/samples/test_example_sync.py index c9496b249369..9b213fafb28e 100644 --- a/sdk/core/azure-core/samples/test_example_sync.py +++ b/sdk/core/azure-core/samples/test_example_sync.py @@ -23,7 +23,7 @@ # THE SOFTWARE. # # -------------------------------------------------------------------------- -# pylint: disable=non-abstract-transport-import +# pylint: disable=non-abstract-transport-import,protected-access from typing import Iterable, MutableSequence, Union from azure.core.pipeline import Pipeline from azure.core import PipelineClient diff --git a/sdk/core/azure-core/tests/async_tests/test_base_polling_async.py b/sdk/core/azure-core/tests/async_tests/test_base_polling_async.py index 3e4582059f82..ead8d8995357 100644 --- a/sdk/core/azure-core/tests/async_tests/test_base_polling_async.py +++ b/sdk/core/azure-core/tests/async_tests/test_base_polling_async.py @@ -40,6 +40,8 @@ from azure.core.exceptions import DecodeError, HttpResponseError from azure.core import AsyncPipelineClient from azure.core.pipeline import PipelineResponse, AsyncPipeline, PipelineContext + +# pylint: disable=no-name-in-module from azure.core.pipeline.transport import AsyncioRequestsTransportResponse, AsyncHttpTransport from azure.core.polling.base_polling import LROBasePolling from azure.core.polling.async_base_polling import ( @@ -196,12 +198,11 @@ async def send(request, **kwargs): return TestBasePolling.mock_send( http_request, http_response, "GET", 200, body={"location_result": True} ).http_response - elif request.url == "http://example.org/async_monitor": + if request.url == "http://example.org/async_monitor": return TestBasePolling.mock_send( http_request, http_response, "GET", 200, body={"status": "Succeeded"} ).http_response - else: - pytest.fail("No other query allowed") + pytest.fail("No other query allowed") client = async_pipeline_client_builder(send) @@ -217,12 +218,11 @@ async def send(request, **kwargs): if request.url == "http://example.org/location": return TestBasePolling.mock_send(http_request, http_response, "GET", 200, body=None).http_response - elif request.url == "http://example.org/async_monitor": + if request.url == "http://example.org/async_monitor": return TestBasePolling.mock_send( http_request, http_response, "GET", 200, body={"status": "Succeeded"} ).http_response - else: - pytest.fail("No other query allowed") + pytest.fail("No other query allowed") client = async_pipeline_client_builder(send) @@ -258,7 +258,7 @@ async def send(request, **kwargs): return TestBasePolling.mock_send( http_request, http_response, "GET", 200, body={"location_result": True} ).http_response - elif request.url == "http://example.org/async_monitor": + if request.url == "http://example.org/async_monitor": return TestBasePolling.mock_send( http_request, http_response, @@ -266,8 +266,7 @@ async def send(request, **kwargs): 200, body={"status": "Succeeded", "resourceLocation": "http://example.org/resource_location"}, ).http_response - else: - pytest.fail("No other query allowed") + pytest.fail("No other query allowed") client = async_pipeline_client_builder(send) @@ -727,12 +726,11 @@ async def send(request, **kwargs): return TestBasePolling.mock_send( http_request, http_response, "GET", 200, body={"location_result": True} ).http_response - elif request.url == "http://example.org/async_monitor": + if request.url == "http://example.org/async_monitor": return TestBasePolling.mock_send( http_request, http_response, "GET", 200, body={"status": "Succeeded"} ).http_response - else: - pytest.fail("No other query allowed") + pytest.fail("No other query allowed") client = async_pipeline_client_builder(send) @@ -768,12 +766,11 @@ async def send(request, **kwargs): if request.url == "http://example.org/location": return TestBasePolling.mock_send(http_request, http_response, "GET", 200, body=None).http_response - elif request.url == "http://example.org/async_monitor": + if request.url == "http://example.org/async_monitor": return TestBasePolling.mock_send( http_request, http_response, "GET", 200, body={"status": "Succeeded"} ).http_response - else: - pytest.fail("No other query allowed") + pytest.fail("No other query allowed") client = async_pipeline_client_builder(send) @@ -829,12 +826,11 @@ async def send(request, **kwargs): return TestBasePolling.mock_send( rest_http[0], rest_http[1], "GET", 200, body={"success": True} ).http_response - elif request.url == "http://example.org/async_monitor": + if request.url == "http://example.org/async_monitor": return TestBasePolling.mock_send( rest_http[0], rest_http[1], "GET", 200, body={"status": "Succeeded"} ).http_response - else: - pytest.fail("No other query allowed") + pytest.fail("No other query allowed") client = async_pipeline_client_builder(send) diff --git a/sdk/core/azure-core/tests/async_tests/test_basic_transport_async.py b/sdk/core/azure-core/tests/async_tests/test_basic_transport_async.py index 2498b8aace03..7037669524d4 100644 --- a/sdk/core/azure-core/tests/async_tests/test_basic_transport_async.py +++ b/sdk/core/azure-core/tests/async_tests/test_basic_transport_async.py @@ -14,6 +14,7 @@ import aiohttp from utils import HTTP_REQUESTS, request_and_responses_product +# pylint: disable=no-name-in-module from azure.core.pipeline.transport import ( AsyncHttpResponse as PipelineTransportAsyncHttpResponse, AsyncHttpTransport, @@ -1092,7 +1093,7 @@ async def test_aiohttp_timeout_request(http_request): async with AioHttpTransport() as transport: transport.session._connector.connect = mock.Mock(side_effect=asyncio.TimeoutError("Too slow!")) - request = http_request("GET", f"http://localhost:12345/basic/string") + request = http_request("GET", "http://localhost:12345/basic/string") # aiohttp 3.10 introduced separate connection timeout if Version(aiohttp.__version__) >= Version("3.10"): @@ -1102,7 +1103,7 @@ async def test_aiohttp_timeout_request(http_request): with pytest.raises(ServiceRequestError) as err: await transport.send(request) - stream_request = http_request("GET", f"http://localhost:12345/streams/basic") + stream_request = http_request("GET", "http://localhost:12345/streams/basic") with pytest.raises(ServiceRequestTimeoutError) as err: await transport.send(stream_request, stream=True) @@ -1113,6 +1114,6 @@ async def test_aiohttp_timeout_request(http_request): with pytest.raises(ServiceResponseError) as err: await transport.send(request) - stream_request = http_request("GET", f"http://localhost:12345/streams/basic") + stream_request = http_request("GET", "http://localhost:12345/streams/basic") with pytest.raises(ServiceResponseTimeoutError) as err: await transport.send(stream_request, stream=True) diff --git a/sdk/core/azure-core/tests/async_tests/test_http_logging_policy_async.py b/sdk/core/azure-core/tests/async_tests/test_http_logging_policy_async.py index 4c4d62d751bc..905795a67de1 100644 --- a/sdk/core/azure-core/tests/async_tests/test_http_logging_policy_async.py +++ b/sdk/core/azure-core/tests/async_tests/test_http_logging_policy_async.py @@ -19,7 +19,7 @@ @pytest.mark.parametrize("http_request,http_response", request_and_responses_product(HTTP_RESPONSES)) -def test_http_logger(http_request, http_response): +def test_http_logger(http_request, http_response): # pylint: disable=too-many-statements class MockHandler(logging.Handler): def __init__(self): super(MockHandler, self).__init__() @@ -133,7 +133,7 @@ def emit(self, record): @pytest.mark.parametrize("http_request,http_response", request_and_responses_product(HTTP_RESPONSES)) -def test_http_logger_operation_level(http_request, http_response): +def test_http_logger_operation_level(http_request, http_response): # pylint: disable=too-many-statements class MockHandler(logging.Handler): def __init__(self): super(MockHandler, self).__init__() diff --git a/sdk/core/azure-core/tests/async_tests/test_paging_async.py b/sdk/core/azure-core/tests/async_tests/test_paging_async.py index a535faea7831..567661d1c390 100644 --- a/sdk/core/azure-core/tests/async_tests/test_paging_async.py +++ b/sdk/core/azure-core/tests/async_tests/test_paging_async.py @@ -54,8 +54,7 @@ async def get_next(continuation_token=None): """Simplify my life and return JSON and not response, but should be response.""" if not continuation_token: return {"nextLink": "page2", "value": ["value1.0", "value1.1"]} - else: - return {"nextLink": None, "value": ["value2.0", "value2.1"]} + return {"nextLink": None, "value": ["value2.0", "value2.1"]} async def extract_data(response): return response["nextLink"], AsyncList(response["value"]) @@ -71,8 +70,7 @@ async def get_next(continuation_token=None): """Simplify my life and return JSON and not response, but should be response.""" if not continuation_token: return {"nextLink": "page2", "value": ["value1.0", "value1.1"]} - else: - return {"nextLink": None, "value": ["value2.0", "value2.1"]} + return {"nextLink": None, "value": ["value2.0", "value2.1"]} async def extract_data(response): return response["nextLink"], AsyncList(response["value"]) @@ -106,8 +104,7 @@ async def test_paging_continue_on_error(self): async def get_next(continuation_token=None): if not continuation_token: return {"nextLink": "foo", "value": ["bar"]} - else: - raise HttpResponseError() + raise HttpResponseError() async def extract_data(response): return response["nextLink"], iter(response["value"] or []) diff --git a/sdk/core/azure-core/tests/async_tests/test_pipeline_async.py b/sdk/core/azure-core/tests/async_tests/test_pipeline_async.py index 9fd7ced0c600..4588bbed8c42 100644 --- a/sdk/core/azure-core/tests/async_tests/test_pipeline_async.py +++ b/sdk/core/azure-core/tests/async_tests/test_pipeline_async.py @@ -44,6 +44,8 @@ HttpLoggingPolicy, SensitiveHeaderCleanupPolicy, ) + +# pylint: disable=no-name-in-module from azure.core.pipeline.transport import ( AsyncHttpTransport, AsyncioRequestsTransport, diff --git a/sdk/core/azure-core/tests/async_tests/test_request_asyncio.py b/sdk/core/azure-core/tests/async_tests/test_request_asyncio.py index 84543324a153..90e58d433d08 100644 --- a/sdk/core/azure-core/tests/async_tests/test_request_asyncio.py +++ b/sdk/core/azure-core/tests/async_tests/test_request_asyncio.py @@ -8,6 +8,7 @@ import pytest from utils import HTTP_REQUESTS +# pylint: disable=no-name-in-module from azure.core.pipeline.transport import AsyncioRequestsTransport from azure.core.pipeline._tools import is_rest diff --git a/sdk/core/azure-core/tests/async_tests/test_request_trio.py b/sdk/core/azure-core/tests/async_tests/test_request_trio.py index 678de9aef187..bdad819c3ef5 100644 --- a/sdk/core/azure-core/tests/async_tests/test_request_trio.py +++ b/sdk/core/azure-core/tests/async_tests/test_request_trio.py @@ -8,6 +8,7 @@ import pytest from utils import HTTP_REQUESTS +# pylint: disable=no-name-in-module from azure.core.pipeline.transport import TrioRequestsTransport from azure.core.pipeline._tools import is_rest @@ -25,8 +26,8 @@ def __aiter__(self): async def __anext__(self): try: return next(self._range) - except StopIteration: - raise StopAsyncIteration + except StopIteration as exc: + raise StopAsyncIteration from exc async with TrioRequestsTransport() as transport: req = http_request("GET", "http://localhost:{}/basic/anything".format(port), data=AsyncGen()) diff --git a/sdk/core/azure-core/tests/async_tests/test_rest_asyncio_transport.py b/sdk/core/azure-core/tests/async_tests/test_rest_asyncio_transport.py index 539ead5b2c8a..6b1d463313ca 100644 --- a/sdk/core/azure-core/tests/async_tests/test_rest_asyncio_transport.py +++ b/sdk/core/azure-core/tests/async_tests/test_rest_asyncio_transport.py @@ -8,6 +8,7 @@ from rest_client_async import AsyncMockRestClient from utils import readonly_checks +# pylint: disable=no-name-in-module from azure.core.pipeline.transport import AsyncioRequestsTransport from azure.core.rest import HttpRequest from azure.core.rest._requests_asyncio import RestAsyncioRequestsTransportResponse diff --git a/sdk/core/azure-core/tests/async_tests/test_rest_headers_async.py b/sdk/core/azure-core/tests/async_tests/test_rest_headers_async.py index b911b242d084..2326a8868cc6 100644 --- a/sdk/core/azure-core/tests/async_tests/test_rest_headers_async.py +++ b/sdk/core/azure-core/tests/async_tests/test_rest_headers_async.py @@ -128,7 +128,7 @@ async def test_headers_response_items_mutability(get_response_headers): @pytest.mark.asyncio async def test_header_mutations(get_response_headers): h = await get_response_headers(HttpRequest("GET", "/headers/empty")) - assert dict(h) == {} + assert not dict(h) h["a"] = "1" assert dict(h) == {"a": "1"} h["a"] = "2" diff --git a/sdk/core/azure-core/tests/async_tests/test_rest_http_request_async.py b/sdk/core/azure-core/tests/async_tests/test_rest_http_request_async.py index 483399a05200..22fa110638f0 100644 --- a/sdk/core/azure-core/tests/async_tests/test_rest_http_request_async.py +++ b/sdk/core/azure-core/tests/async_tests/test_rest_http_request_async.py @@ -54,7 +54,7 @@ async def __aiter__(self): yield b"test 123" request = HttpRequest("POST", "http://example.org", content=Content()) - assert request.headers == {} + assert not request.headers await assert_aiterator_body(request, b"test 123") @@ -68,7 +68,7 @@ async def hello_world(): assert not isinstance(request._data, collections.abc.Iterable) assert isinstance(request._data, collections.abc.AsyncIterable) - assert request.headers == {} + assert not request.headers await assert_aiterator_body(request, b"Hello, world!") # Support 'data' for compat with requests. @@ -76,7 +76,7 @@ async def hello_world(): assert not isinstance(request._data, collections.abc.Iterable) assert isinstance(request._data, collections.abc.AsyncIterable) - assert request.headers == {} + assert not request.headers await assert_aiterator_body(request, b"Hello, world!") # transfer encoding should not be set for GET requests @@ -84,7 +84,7 @@ async def hello_world(): assert not isinstance(request._data, collections.abc.Iterable) assert isinstance(request._data, collections.abc.AsyncIterable) - assert request.headers == {} + assert not request.headers await assert_aiterator_body(request, b"Hello, world!") diff --git a/sdk/core/azure-core/tests/async_tests/test_rest_http_response_async.py b/sdk/core/azure-core/tests/async_tests/test_rest_http_response_async.py index 0c9df36a9e63..b54a8726b510 100644 --- a/sdk/core/azure-core/tests/async_tests/test_rest_http_response_async.py +++ b/sdk/core/azure-core/tests/async_tests/test_rest_http_response_async.py @@ -12,6 +12,8 @@ from utils import readonly_checks from azure.core.rest import HttpRequest, AsyncHttpResponse + +# pylint: disable=no-name-in-module from azure.core.rest._aiohttp import RestAioHttpTransportResponse from azure.core.exceptions import HttpResponseError diff --git a/sdk/core/azure-core/tests/async_tests/test_rest_response_backcompat_async.py b/sdk/core/azure-core/tests/async_tests/test_rest_response_backcompat_async.py index 4fcd204ccf6d..d2653f86212e 100644 --- a/sdk/core/azure-core/tests/async_tests/test_rest_response_backcompat_async.py +++ b/sdk/core/azure-core/tests/async_tests/test_rest_response_backcompat_async.py @@ -12,6 +12,8 @@ from azure.core.pipeline.transport import HttpRequest as PipelineTransportHttpRequest from azure.core.rest import HttpRequest as RestHttpRequest from azure.core.pipeline import Pipeline + +# pylint: disable=no-name-in-module from azure.core.pipeline.transport import AioHttpTransport, AsyncioRequestsTransport, TrioRequestsTransport TRANSPORTS = [AioHttpTransport, AsyncioRequestsTransport] diff --git a/sdk/core/azure-core/tests/async_tests/test_rest_stream_responses_async.py b/sdk/core/azure-core/tests/async_tests/test_rest_stream_responses_async.py index 2b9187c83546..4932feb1154e 100644 --- a/sdk/core/azure-core/tests/async_tests/test_rest_stream_responses_async.py +++ b/sdk/core/azure-core/tests/async_tests/test_rest_stream_responses_async.py @@ -78,9 +78,7 @@ async def test_iter_text(client): request = HttpRequest("GET", "/basic/string") async with client.send_request(request, stream=True) as response: - content = "" - async for part in response.iter_text(): - content += part + content = "".join([part async for part in response.iter_text()]) assert content == "Hello, world!" diff --git a/sdk/core/azure-core/tests/async_tests/test_rest_trio_transport.py b/sdk/core/azure-core/tests/async_tests/test_rest_trio_transport.py index ee16675cb2aa..8d82b83b4628 100644 --- a/sdk/core/azure-core/tests/async_tests/test_rest_trio_transport.py +++ b/sdk/core/azure-core/tests/async_tests/test_rest_trio_transport.py @@ -7,6 +7,7 @@ from rest_client_async import AsyncMockRestClient from utils import readonly_checks +# pylint: disable=no-name-in-module from azure.core.pipeline.transport import TrioRequestsTransport from azure.core.rest import HttpRequest from azure.core.rest._requests_trio import RestTrioRequestsTransportResponse diff --git a/sdk/core/azure-core/tests/async_tests/test_retry_policy_async.py b/sdk/core/azure-core/tests/async_tests/test_retry_policy_async.py index 1a39ea769e4b..6b115f9a8517 100644 --- a/sdk/core/azure-core/tests/async_tests/test_retry_policy_async.py +++ b/sdk/core/azure-core/tests/async_tests/test_retry_policy_async.py @@ -231,9 +231,8 @@ async def send(self, request, **kwargs): # type: (PipelineRequest, Any) -> Pipe response.status_code = 400 return response - file = tempfile.NamedTemporaryFile(delete=False) - file.write(b"Lots of dataaaa") - file.close() + with tempfile.NamedTemporaryFile(delete=False) as file: + file.write(b"Lots of dataaaa") http_request = http_request("GET", "http://localhost/") headers = {"Content-Type": "multipart/form-data"} http_request.headers = headers @@ -345,7 +344,7 @@ def test_configure_retries_uses_constructor_values(): assert retry_settings["max_backoff"] == 60 assert retry_settings["timeout"] == 300 assert retry_settings["methods"] == frozenset(["HEAD", "GET", "PUT", "DELETE", "OPTIONS", "TRACE"]) - assert retry_settings["history"] == [] + assert not retry_settings["history"] def test_configure_retries_options_override_constructor(): @@ -383,7 +382,7 @@ def test_configure_retries_options_override_constructor(): assert retry_settings["max_backoff"] == 180 assert retry_settings["timeout"] == 600 assert retry_settings["methods"] == frozenset(["GET", "POST"]) - assert retry_settings["history"] == [] + assert not retry_settings["history"] # Verify options dict was modified (values were popped) assert "retry_total" not in options @@ -413,4 +412,4 @@ def test_configure_retries_default_values(): assert retry_settings["max_backoff"] == 120 # default retry_backoff_max (BACKOFF_MAX) assert retry_settings["timeout"] == 604800 # default timeout assert retry_settings["methods"] == frozenset(["HEAD", "GET", "PUT", "DELETE", "OPTIONS", "TRACE"]) - assert retry_settings["history"] == [] + assert not retry_settings["history"] diff --git a/sdk/core/azure-core/tests/async_tests/test_stream_generator_async.py b/sdk/core/azure-core/tests/async_tests/test_stream_generator_async.py index 0cb6a8630191..3f5aa0d86ceb 100644 --- a/sdk/core/azure-core/tests/async_tests/test_stream_generator_async.py +++ b/sdk/core/azure-core/tests/async_tests/test_stream_generator_async.py @@ -8,6 +8,7 @@ import pytest from utils import request_and_responses_product, ASYNC_HTTP_RESPONSES, create_http_response +# pylint: disable=no-name-in-module from azure.core.pipeline.transport import ( AsyncHttpTransport, AsyncioRequestsTransportResponse, diff --git a/sdk/core/azure-core/tests/async_tests/test_testserver_async.py b/sdk/core/azure-core/tests/async_tests/test_testserver_async.py index e25e2f433e83..7b9f1312f49a 100644 --- a/sdk/core/azure-core/tests/async_tests/test_testserver_async.py +++ b/sdk/core/azure-core/tests/async_tests/test_testserver_async.py @@ -26,6 +26,7 @@ import pytest from utils import HTTP_REQUESTS +# pylint: disable=no-name-in-module from azure.core.pipeline.transport import AioHttpTransport """This file does a simple call to the testserver to make sure we can use the testserver""" diff --git a/sdk/core/azure-core/tests/async_tests/test_universal_http_async.py b/sdk/core/azure-core/tests/async_tests/test_universal_http_async.py index 93dd0b9c0ecc..33652704575c 100644 --- a/sdk/core/azure-core/tests/async_tests/test_universal_http_async.py +++ b/sdk/core/azure-core/tests/async_tests/test_universal_http_async.py @@ -28,6 +28,7 @@ import pytest from utils import HTTP_REQUESTS, AIOHTTP_TRANSPORT_RESPONSES, create_transport_response +# pylint: disable=no-name-in-module from azure.core.pipeline.transport import ( AioHttpTransport, AsyncioRequestsTransport, @@ -90,7 +91,6 @@ async def do(): request = http_request("GET", "http://localhost:{}/basic/string".format(port)) async with TrioRequestsTransport() as sender: return await sender.send(request) - assert response.body() is not None response = trio.run(do) assert isinstance(response.status_code, int) diff --git a/sdk/core/azure-core/tests/perf_tests/_test_base.py b/sdk/core/azure-core/tests/perf_tests/_test_base.py index bf1df70535b9..3daf66717384 100644 --- a/sdk/core/azure-core/tests/perf_tests/_test_base.py +++ b/sdk/core/azure-core/tests/perf_tests/_test_base.py @@ -12,6 +12,8 @@ from azure.core import PipelineClient, AsyncPipelineClient from azure.core.pipeline import Pipeline, AsyncPipeline + +# pylint: disable=no-name-in-module from azure.core.pipeline.transport import ( RequestsTransport, AioHttpTransport, diff --git a/sdk/core/azure-core/tests/specs_sdk/modeltypes/modeltypes/_utils/model_base.py b/sdk/core/azure-core/tests/specs_sdk/modeltypes/modeltypes/_utils/model_base.py index 03f85ddfbddd..939119f8e6ac 100644 --- a/sdk/core/azure-core/tests/specs_sdk/modeltypes/modeltypes/_utils/model_base.py +++ b/sdk/core/azure-core/tests/specs_sdk/modeltypes/modeltypes/_utils/model_base.py @@ -18,6 +18,7 @@ import re import typing import enum +import types import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder @@ -903,16 +904,18 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: - if any(a for a in annotation.__args__ if a == type(None)): # pyright: ignore + if any(a for a in annotation.__args__ if a == types.NoneType): if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( - next(a for a in annotation.__args__ if a != type(None)), module, rf # pyright: ignore + next(a for a in annotation.__args__ if a != types.NoneType), + module, + rf, ) return functools.partial(_deserialize_with_optional, if_obj_deserializer) # the type is Optional[Union[...]], we need to remove the None type from the Union annotation_copy = copy.copy(annotation) - annotation_copy.__args__ = [a for a in annotation_copy.__args__ if a != type(None)] # pyright: ignore + annotation_copy.__args__ = [a for a in annotation_copy.__args__ if a != types.NoneType] return _get_deserialize_callable_from_annotation(annotation_copy, module, rf) except AttributeError: pass diff --git a/sdk/core/azure-core/tests/test_base_polling.py b/sdk/core/azure-core/tests/test_base_polling.py index 9351f9c68585..a0abe95a9c7a 100644 --- a/sdk/core/azure-core/tests/test_base_polling.py +++ b/sdk/core/azure-core/tests/test_base_polling.py @@ -288,12 +288,11 @@ def send(request, **kwargs): return TestBasePolling.mock_send( http_request, http_response, "GET", 200, body={"location_result": True} ).http_response - elif request.url == "http://example.org/async_monitor": + if request.url == "http://example.org/async_monitor": return TestBasePolling.mock_send( http_request, http_response, "GET", 200, body={"status": "Succeeded"} ).http_response - else: - pytest.fail("No other query allowed") + pytest.fail("No other query allowed") client = pipeline_client_builder(send) @@ -310,12 +309,11 @@ def send(request, **kwargs): if request.url == "http://example.org/location": response = TestBasePolling.mock_send(http_request, http_response, "GET", 200, body=None).http_response return response - elif request.url == "http://example.org/async_monitor": + if request.url == "http://example.org/async_monitor": return TestBasePolling.mock_send( http_request, http_response, "GET", 200, body={"status": "Succeeded"} ).http_response - else: - pytest.fail("No other query allowed") + pytest.fail("No other query allowed") client = pipeline_client_builder(send) @@ -348,7 +346,7 @@ def send(request, **kwargs): return TestBasePolling.mock_send( http_request, http_response, "GET", 200, body={"location_result": True} ).http_response - elif request.url == "http://example.org/async_monitor": + if request.url == "http://example.org/async_monitor": return TestBasePolling.mock_send( http_request, http_response, @@ -356,8 +354,7 @@ def send(request, **kwargs): 200, body={"status": "Succeeded", "resourceLocation": "http://example.org/resource_location"}, ).http_response - else: - pytest.fail("No other query allowed") + pytest.fail("No other query allowed") client = pipeline_client_builder(send) @@ -811,12 +808,11 @@ def send(request, **kwargs): return TestBasePolling.mock_send( http_request, http_response, "GET", 200, body={"location_result": True} ).http_response - elif request.url == "http://example.org/async_monitor": + if request.url == "http://example.org/async_monitor": return TestBasePolling.mock_send( http_request, http_response, "GET", 200, body={"status": "Succeeded"} ).http_response - else: - pytest.fail("No other query allowed") + pytest.fail("No other query allowed") client = pipeline_client_builder(send) @@ -849,12 +845,11 @@ def send(request, **kwargs): if request.url == "http://example.org/location": return TestBasePolling.mock_send(http_request, http_response, "GET", 200, body=None).http_response - elif request.url == "http://example.org/async_monitor": + if request.url == "http://example.org/async_monitor": return TestBasePolling.mock_send( http_request, http_response, "GET", 200, body={"status": "Succeeded"} ).http_response - else: - pytest.fail("No other query allowed") + pytest.fail("No other query allowed") client = pipeline_client_builder(send) diff --git a/sdk/core/azure-core/tests/test_basic_transport.py b/sdk/core/azure-core/tests/test_basic_transport.py index d57000da18ba..ffb9200a2234 100644 --- a/sdk/core/azure-core/tests/test_basic_transport.py +++ b/sdk/core/azure-core/tests/test_basic_transport.py @@ -23,6 +23,8 @@ from azure.core.rest._http_response_impl import HttpResponseImpl as RestHttpResponseImpl from azure.core.pipeline._tools import is_rest + +# pylint: disable=no-name-in-module from azure.core.pipeline.transport import HttpResponse as PipelineTransportHttpResponse, RequestsTransport from azure.core.pipeline.transport._base import HttpTransport, _deserialize_response, _urljoin from azure.core.pipeline.policies import HeadersPolicy diff --git a/sdk/core/azure-core/tests/test_exceptions.py b/sdk/core/azure-core/tests/test_exceptions.py index 72e9d928027d..a33ef08fe544 100644 --- a/sdk/core/azure-core/tests/test_exceptions.py +++ b/sdk/core/azure-core/tests/test_exceptions.py @@ -38,6 +38,8 @@ SerializationError, DeserializationError, ) + +# pylint: disable=no-name-in-module from azure.core.pipeline.transport import RequestsTransportResponse from azure.core.pipeline.transport._base import _HttpResponseBase as PipelineTransportHttpResponseBase from azure.core.rest._http_response_impl import _HttpResponseBaseImpl as RestHttpResponseBase @@ -241,8 +243,8 @@ def test_odata_v4_minimal(self, mock_response): assert exp.code == "501" assert exp.message == "Unsupported functionality" assert exp.target is None - assert exp.details == [] - assert exp.innererror == {} + assert not exp.details + assert not exp.innererror @pytest.mark.parametrize("mock_response", MOCK_RESPONSES) def test_broken_odata_details(self, mock_response): diff --git a/sdk/core/azure-core/tests/test_paging.py b/sdk/core/azure-core/tests/test_paging.py index 5a11bee3f32c..39df9c173100 100644 --- a/sdk/core/azure-core/tests/test_paging.py +++ b/sdk/core/azure-core/tests/test_paging.py @@ -36,8 +36,7 @@ def get_next(continuation_token=None): """Simplify my life and return JSON and not response, but should be response.""" if not continuation_token: return {"nextLink": "page2", "value": ["value1.0", "value1.1"]} - else: - return {"nextLink": None, "value": ["value2.0", "value2.1"]} + return {"nextLink": None, "value": ["value2.0", "value2.1"]} def extract_data(response): return response["nextLink"], iter(response["value"]) @@ -52,8 +51,7 @@ def get_next(continuation_token=None): """Simplify my life and return JSON and not response, but should be response.""" if not continuation_token: return {"nextLink": "page2", "value": ["value1.0", "value1.1"]} - else: - return {"nextLink": None, "value": ["value2.0", "value2.1"]} + return {"nextLink": None, "value": ["value2.0", "value2.1"]} def extract_data(response): return response["nextLink"], iter(response["value"]) @@ -73,8 +71,7 @@ def get_next(continuation_token=None): """Simplify my life and return JSON and not response, but should be response.""" if not continuation_token: return {"nextLink": "page2", "value": ["value1.0", "value1.1"]} - else: - return {"nextLink": None, "value": ["value2.0", "value2.1"]} + return {"nextLink": None, "value": ["value2.0", "value2.1"]} def extract_data(response): return response["nextLink"], iter(response["value"]) @@ -119,8 +116,7 @@ def test_paging_continue_on_error(self): def get_next(continuation_token=None): if not continuation_token: return {"nextLink": "foo", "value": ["bar"]} - else: - raise HttpResponseError() + raise HttpResponseError() def extract_data(response): return response["nextLink"], iter(response["value"] or []) diff --git a/sdk/core/azure-core/tests/test_pipeline.py b/sdk/core/azure-core/tests/test_pipeline.py index b9d4eda269ac..0ea8c1a2d205 100644 --- a/sdk/core/azure-core/tests/test_pipeline.py +++ b/sdk/core/azure-core/tests/test_pipeline.py @@ -52,6 +52,8 @@ SensitiveHeaderCleanupPolicy, ) from azure.core.pipeline.transport._base import PipelineClientBase, _format_url_section + +# pylint: disable=no-name-in-module from azure.core.pipeline.transport import ( HttpTransport, RequestsTransport, diff --git a/sdk/core/azure-core/tests/test_requests_universal.py b/sdk/core/azure-core/tests/test_requests_universal.py index 1c7312db8c8a..ac7b1db724d1 100644 --- a/sdk/core/azure-core/tests/test_requests_universal.py +++ b/sdk/core/azure-core/tests/test_requests_universal.py @@ -29,6 +29,7 @@ import pytest from utils import HTTP_REQUESTS, REQUESTS_TRANSPORT_RESPONSES, create_transport_response +# pylint: disable=no-name-in-module from azure.core.pipeline.transport import RequestsTransport from azure.core.pipeline._tools import is_rest diff --git a/sdk/core/azure-core/tests/test_rest_headers.py b/sdk/core/azure-core/tests/test_rest_headers.py index cbabbc4a00d5..1f2841434bdd 100644 --- a/sdk/core/azure-core/tests/test_rest_headers.py +++ b/sdk/core/azure-core/tests/test_rest_headers.py @@ -135,7 +135,7 @@ def test_headers_response_items_mutability(get_response_headers): def test_header_mutations(get_request_headers, get_response_headers): def _headers_check(h): - assert dict(h) == {} + assert not dict(h) h["a"] = "1" assert dict(h) == {"a": "1"} h["a"] = "2" diff --git a/sdk/core/azure-core/tests/test_rest_http_request.py b/sdk/core/azure-core/tests/test_rest_http_request.py index a4bd3670cf2e..7228e6f7a085 100644 --- a/sdk/core/azure-core/tests/test_rest_http_request.py +++ b/sdk/core/azure-core/tests/test_rest_http_request.py @@ -30,7 +30,7 @@ @pytest.fixture def assert_iterator_body(): def _comparer(request, final_value): - content = b"".join([p for p in request.content]) + content = b"".join(list(request.content)) assert content == final_value return _comparer @@ -57,7 +57,7 @@ def __iter__(self): yield b"test 123" # pragma: nocover request = HttpRequest("POST", "http://example.org", content=Content()) - assert request.headers == {} + assert not request.headers assert_iterator_body(request, b"test 123") @@ -66,7 +66,7 @@ def content(): yield b"test 123" # pragma: nocover request = HttpRequest("POST", "http://example.org", content=content()) - assert request.headers == {} + assert not request.headers assert_iterator_body(request, b"test 123") @@ -185,21 +185,21 @@ def hello_world(): assert isinstance(request.content, collections.Iterable) assert_iterator_body(request, b"Hello, world!") - assert request.headers == {} + assert not request.headers # Support 'data' for compat with requests. request = HttpRequest("POST", url="http://example.org", data=hello_world()) assert isinstance(request.content, collections.Iterable) assert_iterator_body(request, b"Hello, world!") - assert request.headers == {} + assert not request.headers # transfer encoding should still be set for GET requests request = HttpRequest("GET", url="http://example.org", data=hello_world()) assert isinstance(request.content, collections.Iterable) assert_iterator_body(request, b"Hello, world!") - assert request.headers == {} + assert not request.headers def test_json_content(): @@ -294,7 +294,7 @@ def test_multipart_invalid_value(value): def test_empty_request(): request = HttpRequest("POST", url="http://example.org", data={}, files={}) - assert request.headers == {} + assert not request.headers assert not request.content # in core, we don't convert urlencoded dict to bytes representation in content diff --git a/sdk/core/azure-core/tests/test_rest_http_response.py b/sdk/core/azure-core/tests/test_rest_http_response.py index 29e2d8b193c6..d5f8e6117190 100644 --- a/sdk/core/azure-core/tests/test_rest_http_response.py +++ b/sdk/core/azure-core/tests/test_rest_http_response.py @@ -338,6 +338,7 @@ def test_readonly(send_request): response = send_request(HttpRequest("GET", "/health")) assert isinstance(response, RestRequestsTransportResponse) + # pylint: disable=no-name-in-module from azure.core.pipeline.transport import RequestsTransportResponse readonly_checks(response, old_response_class=RequestsTransportResponse) diff --git a/sdk/core/azure-core/tests/test_rest_response_backcompat.py b/sdk/core/azure-core/tests/test_rest_response_backcompat.py index 9d2e8d118663..2f942438f27e 100644 --- a/sdk/core/azure-core/tests/test_rest_response_backcompat.py +++ b/sdk/core/azure-core/tests/test_rest_response_backcompat.py @@ -9,6 +9,8 @@ from azure.core.pipeline.transport import HttpRequest as PipelineTransportHttpRequest from azure.core.rest import HttpRequest as RestHttpRequest from azure.core.pipeline import Pipeline + +# pylint: disable=no-name-in-module from azure.core.pipeline.transport import RequestsTransport diff --git a/sdk/core/azure-core/tests/test_rest_stream_responses.py b/sdk/core/azure-core/tests/test_rest_stream_responses.py index b8b14559efab..efdd746b3a75 100644 --- a/sdk/core/azure-core/tests/test_rest_stream_responses.py +++ b/sdk/core/azure-core/tests/test_rest_stream_responses.py @@ -85,9 +85,7 @@ def test_iter_bytes(client): def test_iter_text(client): request = HttpRequest("GET", "/basic/string") with client.send_request(request, stream=True) as response: - content = "" - for part in response.iter_text(): - content += part + content = "".join(response.iter_text()) assert content == "Hello, world!" @@ -150,7 +148,7 @@ def test_decompress_plain_no_header(client): request = HttpRequest("GET", "/streams/string") response = client.send_request(request, stream=True) with pytest.raises(ResponseNotReadError): - response.content + _ = response.content response.read() assert response.content == b"test" diff --git a/sdk/core/azure-core/tests/test_retry_policy.py b/sdk/core/azure-core/tests/test_retry_policy.py index 617e57406396..f5f10caa6438 100644 --- a/sdk/core/azure-core/tests/test_retry_policy.py +++ b/sdk/core/azure-core/tests/test_retry_policy.py @@ -233,9 +233,8 @@ def send(self, request, **kwargs): # type: (PipelineRequest, Any) -> PipelineRe response.status_code = 400 return response - file = tempfile.NamedTemporaryFile(delete=False) - file.write(b"Lots of dataaaa") - file.close() + with tempfile.NamedTemporaryFile(delete=False) as file: + file.write(b"Lots of dataaaa") http_request = http_request("GET", "http://localhost/") headers = {"Content-Type": "multipart/form-data"} http_request.headers = headers @@ -344,7 +343,7 @@ def test_configure_retries_uses_constructor_values(): assert retry_settings["max_backoff"] == 60 assert retry_settings["timeout"] == 300 assert retry_settings["methods"] == frozenset(["HEAD", "GET", "PUT", "DELETE", "OPTIONS", "TRACE"]) - assert retry_settings["history"] == [] + assert not retry_settings["history"] def test_configure_retries_options_override_constructor(): @@ -382,7 +381,7 @@ def test_configure_retries_options_override_constructor(): assert retry_settings["max_backoff"] == 180 assert retry_settings["timeout"] == 600 assert retry_settings["methods"] == frozenset(["GET", "POST"]) - assert retry_settings["history"] == [] + assert not retry_settings["history"] # Verify options dict was modified (values were popped) assert "retry_total" not in options @@ -412,4 +411,4 @@ def test_configure_retries_default_values(): assert retry_settings["max_backoff"] == 120 # default retry_backoff_max (BACKOFF_MAX) assert retry_settings["timeout"] == 604800 # default timeout assert retry_settings["methods"] == frozenset(["HEAD", "GET", "PUT", "DELETE", "OPTIONS", "TRACE"]) - assert retry_settings["history"] == [] + assert not retry_settings["history"] diff --git a/sdk/core/azure-core/tests/test_serialization.py b/sdk/core/azure-core/tests/test_serialization.py index cc94b1092142..09884ccfdfb1 100644 --- a/sdk/core/azure-core/tests/test_serialization.py +++ b/sdk/core/azure-core/tests/test_serialization.py @@ -39,12 +39,11 @@ def _expand_value(obj): except AttributeError: if isinstance(obj, Enum): return obj.value - elif isinstance(obj, list): + if isinstance(obj, list): return [_expand_value(item) for item in obj] - elif isinstance(obj, dict): + if isinstance(obj, dict): return _expand_dict(obj) - else: - return _expand_dict(vars(obj)) + return _expand_dict(vars(obj)) except TypeError: return obj @@ -1237,7 +1236,7 @@ def test_readonly(): model = models.ReadonlyModel({"id": 1}) assert model.id == 1 assert model.as_dict() == {"id": 1} - assert model.as_dict(exclude_readonly=True) == {} + assert not model.as_dict(exclude_readonly=True) def test_as_attribute_dict_scratch(): @@ -1724,7 +1723,7 @@ def test_deserialize_no_registry(self): deserialized = _deserialize(TestTypeHandlerRegistry.FooModel, json_dict) # If no deserializer is registered, the input should be returned as-is assert deserialized == json_dict - assert type(deserialized) is dict + assert isinstance(deserialized, dict) def test_serialize_external_model(self): @@ -2096,10 +2095,9 @@ class ContainerModel(HybridModel): def ext_deserializer(cls: Type, data: Dict[str, Any]) -> Union[ExternalModelA, ExternalModelB]: if "foo" in data: return ExternalModelA(foo=data["foo"], bar=data.get("bar")) - elif "biz" in data: + if "biz" in data: return ExternalModelB(biz=data["biz"], baz=data.get("baz")) - else: - raise ValueError("Invalid data for deserialization") + raise ValueError("Invalid data for deserialization") TYPE_HANDLER_REGISTRY.register_deserializer(lambda t: t in (ExternalModelA, ExternalModelB))(ext_deserializer) @@ -2138,10 +2136,9 @@ class ContainerModel(HybridModel): def ext_deserializer(cls: Type, data: Dict[str, Any]) -> Union[ExternalModelA, ExternalModelB]: if "baz" in data: return ExternalModelB(foo=data["foo"], bar=data.get("bar"), baz=data.get("baz")) - elif "foo" in data: + if "foo" in data: return ExternalModelA(foo=data["foo"], bar=data.get("bar")) - else: - raise ValueError("Invalid data for deserialization") + raise ValueError("Invalid data for deserialization") TYPE_HANDLER_REGISTRY.register_deserializer(lambda t: t in (ExternalModelA, ExternalModelB))(ext_deserializer) @@ -2420,7 +2417,7 @@ class ReadonlyModel(HybridModel): # Should use attr_name, but excluded when exclude_readonly=True assert attribute_list(model) == ["field_name"] assert as_attribute_dict(model) == {"field_name": "value"} - assert as_attribute_dict(model, exclude_readonly=True) == {} + assert not as_attribute_dict(model, exclude_readonly=True) assert getattr(model, "field_name") == "value" assert get_backcompat_attr_name(model, "field_name") == "field_name" @@ -2451,7 +2448,7 @@ class ReadonlyDifferentWireModel(HybridModel): # Should use attr_name, excluded when exclude_readonly=True assert attribute_list(model) == ["client_field"] assert as_attribute_dict(model) == {"client_field": "value"} - assert as_attribute_dict(model, exclude_readonly=True) == {} + assert not as_attribute_dict(model, exclude_readonly=True) assert getattr(model, "client_field") == "value" assert get_backcompat_attr_name(model, "client_field") == "client_field" @@ -2480,7 +2477,7 @@ class ReadonlyPaddedModel(HybridModel): assert attribute_list(model) == ["keys_property"] assert as_attribute_dict(model) == {"keys_property": "value"} - assert as_attribute_dict(model, exclude_readonly=True) == {} + assert not as_attribute_dict(model, exclude_readonly=True) assert get_backcompat_attr_name(model, "keys_property") == "keys" assert getattr(model, "keys_property") == "value" assert set(model.keys()) == {"keys_property"} @@ -2510,7 +2507,7 @@ class ReadonlyDifferentWirePaddedModel(HybridModel): assert attribute_list(model) == ["pop_property"] assert as_attribute_dict(model) == {"pop_property": "value"} - assert as_attribute_dict(model, exclude_readonly=True) == {} + assert not as_attribute_dict(model, exclude_readonly=True) assert getattr(model, "pop_property") == "value" assert set(model.keys()) == {"popWire"} diff --git a/sdk/core/azure-core/tests/test_stream_generator.py b/sdk/core/azure-core/tests/test_stream_generator.py index 805b9d0d74c7..17880331d63c 100644 --- a/sdk/core/azure-core/tests/test_stream_generator.py +++ b/sdk/core/azure-core/tests/test_stream_generator.py @@ -17,6 +17,7 @@ request_and_responses_product, ) +# pylint: disable=no-name-in-module from azure.core.pipeline.transport import ( HttpTransport, RequestsTransport, @@ -110,6 +111,7 @@ def read(self, chunk_size, decode_content=False): data = b"X" * min(chunk_size, self.total_response_size) self.total_response_size -= len(data) return data + return b"" def close(self): pass diff --git a/sdk/core/azure-core/tests/test_streaming.py b/sdk/core/azure-core/tests/test_streaming.py index 4abffa1cdbb7..f3b8df7c5c2b 100644 --- a/sdk/core/azure-core/tests/test_streaming.py +++ b/sdk/core/azure-core/tests/test_streaming.py @@ -26,6 +26,7 @@ import pytest from utils import HTTP_REQUESTS +# pylint: disable=no-name-in-module from azure.core.pipeline.transport import RequestsTransport from azure.core import PipelineClient from azure.core.exceptions import DecodeError diff --git a/sdk/core/azure-core/tests/test_testserver.py b/sdk/core/azure-core/tests/test_testserver.py index 65a5cdd3b9a2..c7b3ab3589c8 100644 --- a/sdk/core/azure-core/tests/test_testserver.py +++ b/sdk/core/azure-core/tests/test_testserver.py @@ -26,6 +26,7 @@ import pytest from utils import HTTP_REQUESTS +# pylint: disable=no-name-in-module from azure.core.pipeline.transport import RequestsTransport """This file does a simple call to the testserver to make sure we can use the testserver""" diff --git a/sdk/core/azure-core/tests/test_tracing_policy.py b/sdk/core/azure-core/tests/test_tracing_policy.py index 7533b6315d95..8e0f2fc7200a 100644 --- a/sdk/core/azure-core/tests/test_tracing_policy.py +++ b/sdk/core/azure-core/tests/test_tracing_policy.py @@ -16,6 +16,8 @@ from azure.core.pipeline import Pipeline, PipelineResponse, PipelineRequest, PipelineContext from azure.core.pipeline.policies import DistributedTracingPolicy, HttpLoggingPolicy, UserAgentPolicy, RetryPolicy + +# pylint: disable=no-name-in-module from azure.core.pipeline.transport import HttpTransport, RequestsTransport from azure.core.settings import settings from azure.core.tracing._models import SpanKind diff --git a/sdk/core/azure-core/tests/test_universal_pipeline.py b/sdk/core/azure-core/tests/test_universal_pipeline.py index 63a323ca6d3e..34a988222490 100644 --- a/sdk/core/azure-core/tests/test_universal_pipeline.py +++ b/sdk/core/azure-core/tests/test_universal_pipeline.py @@ -198,7 +198,9 @@ def send(*args): "http_request,http_response,requests_transport_response", request_and_responses_product(HTTP_RESPONSES, REQUESTS_TRANSPORT_RESPONSES), ) -def test_raw_deserializer(http_request, http_response, requests_transport_response): +def test_raw_deserializer( # pylint: disable=too-many-statements + http_request, http_response, requests_transport_response +): raw_deserializer = ContentDecodePolicy() context = PipelineContext(None, stream=False) universal_request = http_request("GET", "http://localhost/") diff --git a/sdk/core/azure-core/tests/testserver_tests/coretestserver/coretestserver/test_routes/helpers.py b/sdk/core/azure-core/tests/testserver_tests/coretestserver/coretestserver/test_routes/helpers.py index c675a40b941f..c282f6e7681f 100644 --- a/sdk/core/azure-core/tests/testserver_tests/coretestserver/coretestserver/test_routes/helpers.py +++ b/sdk/core/azure-core/tests/testserver_tests/coretestserver/coretestserver/test_routes/helpers.py @@ -4,6 +4,7 @@ # license information. # ------------------------------------------------------------------------- from urllib.parse import urlparse, urlunparse +import base64 import json from flask import ( @@ -104,8 +105,7 @@ def semiflatten(multi): if len(v) == 1: result[k] = v[0] return result - else: - return multi + return multi def json_safe(string, content_type="application/octet-stream"): @@ -141,17 +141,17 @@ def get_dict(*keys, **extras): except (ValueError, TypeError): _json = None - d = dict( - url=get_url(request), - args=semiflatten(request.args), - form=form, - data=json_safe(data), - origin=request.headers.get("X-Forwarded-For", request.remote_addr), - headers=get_headers(), - files=get_files(), - json=_json, - method=request.method, - ) + d = { + "url": get_url(request), + "args": semiflatten(request.args), + "form": form, + "data": json_safe(data), + "origin": request.headers.get("X-Forwarded-For", request.remote_addr), + "headers": get_headers(), + "files": get_files(), + "json": _json, + "method": request.method, + } out_d = {} diff --git a/sdk/core/azure-core/tests/testserver_tests/coretestserver/coretestserver/test_routes/xml_route.py b/sdk/core/azure-core/tests/testserver_tests/coretestserver/coretestserver/test_routes/xml_route.py index afdcb475a2a3..ba380dcb84ef 100644 --- a/sdk/core/azure-core/tests/testserver_tests/coretestserver/coretestserver/test_routes/xml_route.py +++ b/sdk/core/azure-core/tests/testserver_tests/coretestserver/coretestserver/test_routes/xml_route.py @@ -35,7 +35,7 @@ def basic(): if request.method == "GET": return Response(basic_body, status=200) - elif request.method == "PUT": + if request.method == "PUT": assert_with_message("content length", str(len(request.data)), request.headers["Content-Length"]) parsed_xml = ET.fromstring(request.data.decode("utf-8")) assert_with_message("tag", "slideshow", parsed_xml.tag) diff --git a/sdk/core/azure-core/tests/utils.py b/sdk/core/azure-core/tests/utils.py index 553447d78058..6534d6e946b3 100644 --- a/sdk/core/azure-core/tests/utils.py +++ b/sdk/core/azure-core/tests/utils.py @@ -163,7 +163,7 @@ def readonly_checks(response, old_response_class): if attr[0] == "_": # don't care about private variables continue - if type(getattr(response, attr)) == types.MethodType: + if isinstance(getattr(response, attr), types.MethodType): # methods aren't "readonly" continue if attr == "encoding":