Skip to content

Commit

Permalink
Remove pass, format code
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy-Grigg committed Feb 16, 2024
1 parent 55f2672 commit 50e0cfc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/ansys/openapi/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

from ._api_client import ApiClient
from ._base import ApiBase, ApiClientBase, ModelBase
from ._exceptions import ApiConnectionException, ApiException, AuthenticationWarning, UndefinedObjectWarning
from ._exceptions import (
ApiConnectionException,
ApiException,
AuthenticationWarning,
UndefinedObjectWarning,
)
from ._session import ApiClientFactory, OIDCSessionBuilder
from ._util import SessionConfiguration, generate_user_agent

Expand Down
10 changes: 7 additions & 3 deletions src/ansys/openapi/common/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from urllib.parse import quote

import requests

with warnings.catch_warnings():
warnings.simplefilter("ignore", category=DeprecationWarning)
from dateutil.parser import parse
Expand Down Expand Up @@ -372,9 +373,12 @@ def __deserialize(self, data: SerializedType, klass_name: str) -> DeserializedTy
return None

if klass_name == "object":
warnings.warn("Attempting to deserialize an object with no defined type. Returning "
"the raw data as a dictionary. Check your OpenAPI definition and ensure "
"all types are fully defined.", UndefinedObjectWarning)
warnings.warn(
"Attempting to deserialize an object with no defined type. Returning "
"the raw data as a dictionary. Check your OpenAPI definition and ensure "
"all types are fully defined.",
UndefinedObjectWarning,
)
return data

list_match = self.LIST_MATCH_REGEX.match(klass_name)
Expand Down
1 change: 0 additions & 1 deletion src/ansys/openapi/common/_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,3 @@ class UndefinedObjectWarning(UserWarning):
This warning can be safely suppressed if the required detail cannot be added to the OpenAPI
definition, but in this case the deserialization must be defined manually.
"""
pass
12 changes: 10 additions & 2 deletions tests/test_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
from requests_mock.request import _RequestObjectProxy
import secrets

from ansys.openapi.common import ApiClient, SessionConfiguration, ApiException, UndefinedObjectWarning
from ansys.openapi.common import (
ApiClient,
SessionConfiguration,
ApiException,
UndefinedObjectWarning,
)

TEST_URL = "http://localhost/api/v1.svc"
UA_STRING = (
Expand Down Expand Up @@ -376,7 +381,10 @@ def test_deserialize_primitive_of_wrong_type_does_nothing(self, data, target_typ

def test_deserialize_undefined_object_returns_dict_and_warns(self):
data = {"foo": "bar", "baz": [1, 2, 3]}
with pytest.warns(UndefinedObjectWarning, match="Attempting to deserialize an object with no defined type"):
with pytest.warns(
UndefinedObjectWarning,
match="Attempting to deserialize an object with no defined type",
):
output = self._client._ApiClient__deserialize(data, "object")
assert output == data

Expand Down

0 comments on commit 50e0cfc

Please sign in to comment.