From b300212e204a4beacc22d423dd5d22e7c8e3133f Mon Sep 17 00:00:00 2001 From: Acurisu Date: Wed, 16 Oct 2024 16:05:35 +0200 Subject: [PATCH] remove unused code/imports as well as some reformatting --- .../json_parse_node.py | 2 +- .../json/tests/helpers/union_type.py | 1 - .../serialization/json/tests/helpers/user2.py | 3 +- .../serialization/json/tests/unit/conftest.py | 88 ++++++++----------- .../tests/unit/test_intersection_wrapper.py | 2 - .../json/tests/unit/test_json_parse_node.py | 39 ++++---- .../unit/test_json_parse_node_factory.py | 12 +-- .../test_json_serialization_writer_factory.py | 4 +- .../json/tests/unit/test_union_wrapper.py | 2 - 9 files changed, 65 insertions(+), 88 deletions(-) diff --git a/packages/serialization/json/kiota_serialization_json/json_parse_node.py b/packages/serialization/json/kiota_serialization_json/json_parse_node.py index bf05ce02..cb561aa1 100644 --- a/packages/serialization/json/kiota_serialization_json/json_parse_node.py +++ b/packages/serialization/json/kiota_serialization_json/json_parse_node.py @@ -5,7 +5,7 @@ import warnings from datetime import date, datetime, time, timedelta from enum import Enum -from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar, Union +from typing import Any, Callable, List, Optional, TypeVar from uuid import UUID import pendulum diff --git a/packages/serialization/json/tests/helpers/union_type.py b/packages/serialization/json/tests/helpers/union_type.py index 7ebf4c8e..5bb3e052 100644 --- a/packages/serialization/json/tests/helpers/union_type.py +++ b/packages/serialization/json/tests/helpers/union_type.py @@ -4,7 +4,6 @@ from typing import Any, Callable, Dict, List, Optional from kiota_abstractions.serialization import Parsable, ParseNode, SerializationWriter -from kiota_abstractions.serialization.parse_node_helper import ParseNodeHelper from . import User, User2 diff --git a/packages/serialization/json/tests/helpers/user2.py b/packages/serialization/json/tests/helpers/user2.py index 1d22bc9b..1e165e11 100644 --- a/packages/serialization/json/tests/helpers/user2.py +++ b/packages/serialization/json/tests/helpers/user2.py @@ -1,8 +1,7 @@ from __future__ import annotations from dataclasses import dataclass, field -from datetime import date, datetime -from typing import Any, Callable, Dict, List, Optional, TypeVar +from typing import Any, Callable, Dict, Optional, TypeVar from kiota_abstractions.serialization import Parsable, ParseNode, SerializationWriter diff --git a/packages/serialization/json/tests/unit/conftest.py b/packages/serialization/json/tests/unit/conftest.py index bca9a293..d9baf605 100644 --- a/packages/serialization/json/tests/unit/conftest.py +++ b/packages/serialization/json/tests/unit/conftest.py @@ -1,63 +1,45 @@ -import json - import pytest -url: str = "https://graph.microsoft.com/v1.0/$metadata#users/$entity" - @pytest.fixture def user1_json(): - return '{"id": "8f841f30-e6e3-439a-a812-ebd369559c36", '\ - '"office_location": "dunhill", '\ - '"updated_at": "2021-07-29T03:07:25Z", '\ - '"birthday": "2000-09-04", '\ - '"business_phones": ["+1 205 555 0108"], '\ - '"mobile_phone": null, '\ - '"is_active": true, '\ - '"additional_data": {"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity", '\ - '"manager": {"id": "8f841f30-e6e3-439a-a812-ebd369559c36", '\ - '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}, '\ - '"approvers": [{"id": "8f841f30-e6e3-439a-a812-ebd369559c36", '\ - '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}, '\ - '{"display_name": "John Doe", "age": 32}], '\ - '"data": {'\ - '"groups": ['\ - '{"friends": [{"display_name": "John Doe", "age": 32}]}'\ - ']'\ - '}}}'\ - - -@pytest.fixture -def user2_json(): - - return '{"id": 2, "display_name": "MOD Administrator", "age": 32, "gpa": 3.9}' + return ( + '{"id": "8f841f30-e6e3-439a-a812-ebd369559c36", ' + '"office_location": "dunhill", ' + '"updated_at": "2021-07-29T03:07:25Z", ' + '"birthday": "2000-09-04", ' + '"business_phones": ["+1 205 555 0108"], ' + '"mobile_phone": null, ' + '"is_active": true, ' + '"additional_data": {"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity", ' + '"manager": {"id": "8f841f30-e6e3-439a-a812-ebd369559c36", ' + '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}, ' + '"approvers": [{"id": "8f841f30-e6e3-439a-a812-ebd369559c36", ' + '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}, ' + '{"display_name": "John Doe", "age": 32}], ' + '"data": {' + '"groups": [' + '{"friends": [{"display_name": "John Doe", "age": 32}]}' + "]" + "}}}" + ) @pytest.fixture def users_json(): - return '[{"id": "8f841f30-e6e3-439a-a812-ebd369559c36", '\ - '"office_location": "dunhill", '\ - '"updated_at": "2021-07-29T03:07:25Z", '\ - '"birthday": "2000-09-04", '\ - '"business_phones": ["+1 205 555 0108"], '\ - '"mobile_phone": null, '\ - '"is_active": true}, '\ - '{"id": "8f841f30-e6e3-439a-a812-ebd369559c36", '\ - '"office_location": "dunhill", '\ - '"updated_at": "2021-07-29T03:07:25Z", '\ - '"birthday": "2000-09-04", '\ - '"business_phones": ["+1 205 555 0108"], '\ - '"mobile_phone": null, '\ - '"is_active": true}]' - - -@pytest.fixture -def sample_entity_json(): - - entity_json = json.dumps( - { - "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#$entity", - "id": "8f841f30-e6e3-439a-a812-ebd369559c36" - } + return ( + '[{"id": "8f841f30-e6e3-439a-a812-ebd369559c36", ' + '"office_location": "dunhill", ' + '"updated_at": "2021-07-29T03:07:25Z", ' + '"birthday": "2000-09-04", ' + '"business_phones": ["+1 205 555 0108"], ' + '"mobile_phone": null, ' + '"is_active": true}, ' + '{"id": "8f841f30-e6e3-439a-a812-ebd369559c36", ' + '"office_location": "dunhill", ' + '"updated_at": "2021-07-29T03:07:25Z", ' + '"birthday": "2000-09-04", ' + '"business_phones": ["+1 205 555 0108"], ' + '"mobile_phone": null, ' + '"is_active": true}]' ) - return entity_json diff --git a/packages/serialization/json/tests/unit/test_intersection_wrapper.py b/packages/serialization/json/tests/unit/test_intersection_wrapper.py index 80c1b5ef..94af1968 100644 --- a/packages/serialization/json/tests/unit/test_intersection_wrapper.py +++ b/packages/serialization/json/tests/unit/test_intersection_wrapper.py @@ -1,8 +1,6 @@ import json from uuid import UUID -import pytest - from kiota_serialization_json.json_parse_node import JsonParseNode from kiota_serialization_json.json_serialization_writer import JsonSerializationWriter diff --git a/packages/serialization/json/tests/unit/test_json_parse_node.py b/packages/serialization/json/tests/unit/test_json_parse_node.py index 7bec942d..8436464c 100644 --- a/packages/serialization/json/tests/unit/test_json_parse_node.py +++ b/packages/serialization/json/tests/unit/test_json_parse_node.py @@ -8,8 +8,6 @@ from kiota_serialization_json.json_parse_node import JsonParseNode from ..helpers import OfficeLocation, User -url: str = "https://graph.microsoft.com/v1.0/$metadata#users/$entity" - def test_get_str_value(): parse_node = JsonParseNode("Diego Siciliani") @@ -42,7 +40,7 @@ def test_get_float_value_from_float(): @pytest.mark.parametrize("value", [0, 10, 100]) def test_get_float_value(value: int): """ - Consider an OpenAPI Specification using the type: number and format: float or double + Consider an OpenAPI Specification using the type: number and format: float or double Note: The OpenAPI Specification also allows for the use of the type: integer and format: int32 or int64 Consider an API with Price data [0, 0.5, 1, 1.5, 2] and so on @@ -70,30 +68,30 @@ def test_get_datetime_value_returns_none_with_invalid_str(value: str): def test_get_datetime_value(): - parse_node = JsonParseNode('2022-01-27T12:59:45.596117') + parse_node = JsonParseNode("2022-01-27T12:59:45.596117") result = parse_node.get_datetime_value() assert isinstance(result, datetime) def test_get_date_value(): - parse_node = JsonParseNode('2015-04-20') + parse_node = JsonParseNode("2015-04-20") result = parse_node.get_date_value() assert isinstance(result, date) - assert str(result) == '2015-04-20' + assert str(result) == "2015-04-20" def test_get_time_value(): - parse_node = JsonParseNode('12:59:45.596117') + parse_node = JsonParseNode("12:59:45.596117") result = parse_node.get_time_value() assert isinstance(result, time) - assert str(result) == '12:59:45.596117' + assert str(result) == "12:59:45.596117" def test_get_timedelta_value(): - parse_node = JsonParseNode('PT30S') + parse_node = JsonParseNode("PT30S") result = parse_node.get_timedelta_value() assert isinstance(result, timedelta) - assert str(result) == '0:00:30' + assert str(result) == "0:00:30" def test_get_collection_of_primitive_values(): @@ -109,7 +107,7 @@ def test_get_collection_of_primitive_values_no_type(): def test_get_bytes_value(): - parse_node = JsonParseNode('U2Ftd2VsIGlzIHRoZSBiZXN0') + parse_node = JsonParseNode("U2Ftd2VsIGlzIHRoZSBiZXN0") result = parse_node.get_bytes_value() assert isinstance(result, bytes) @@ -159,26 +157,29 @@ def test_get_object_value(user1_json): assert result.business_phones == ["+1 205 555 0108"] assert result.is_active is True assert result.mobile_phone is None - assert result.additional_data["additional_data"][ - "@odata.context"] == "https://graph.microsoft.com/v1.0/$metadata#users/$entity" + assert ( + result.additional_data["additional_data"]["@odata.context"] == + "https://graph.microsoft.com/v1.0/$metadata#users/$entity" + ) assert result.additional_data["additional_data"]["manager"] == { - "id": UUID('8f841f30-e6e3-439a-a812-ebd369559c36'), + "id": UUID("8f841f30-e6e3-439a-a812-ebd369559c36"), "updated_at": DateTime(2022, 1, 27, 12, 59, 45, 596117, tzinfo=FixedTimezone(0, name="+00:00")), - "is_active": True + "is_active": True, } assert result.additional_data["additional_data"]["approvers"] == [ { "id": - UUID('8f841f30-e6e3-439a-a812-ebd369559c36'), + UUID("8f841f30-e6e3-439a-a812-ebd369559c36"), "updated_at": DateTime(2022, 1, 27, 12, 59, 45, 596117, tzinfo=FixedTimezone(0, name="+00:00")), "is_active": - True - }, { + True, + }, + { "display_name": "John Doe", "age": 32 - } + }, ] assert result.additional_data["additional_data"]["data"] == { "groups": [{ diff --git a/packages/serialization/json/tests/unit/test_json_parse_node_factory.py b/packages/serialization/json/tests/unit/test_json_parse_node_factory.py index 2975f37c..3f736c42 100644 --- a/packages/serialization/json/tests/unit/test_json_parse_node_factory.py +++ b/packages/serialization/json/tests/unit/test_json_parse_node_factory.py @@ -20,24 +20,24 @@ def test_get_root_parse_node(sample_json_string): def test_get_root_parse_node_no_content_type(sample_json_string): - with pytest.raises(Exception) as e_info: + with pytest.raises(Exception): factory = JsonParseNodeFactory() sample_json_string_bytes = sample_json_string.encode('utf-8') - root = factory.get_root_parse_node('', sample_json_string_bytes) + factory.get_root_parse_node('', sample_json_string_bytes) def test_get_root_parse_node_unsupported_content_type(sample_json_string): - with pytest.raises(Exception) as e_info: + with pytest.raises(Exception): factory = JsonParseNodeFactory() sample_json_string_bytes = sample_json_string.encode('utf-8') - root = factory.get_root_parse_node('application/xml', sample_json_string_bytes) + factory.get_root_parse_node('application/xml', sample_json_string_bytes) def test_get_root_parse_node_empty_json(): - with pytest.raises(TypeError) as e_info: + with pytest.raises(TypeError): factory = JsonParseNodeFactory() sample_string_bytes = ''.encode('utf-8') - root = factory.get_root_parse_node('application/json', sample_string_bytes) + factory.get_root_parse_node('application/json', sample_string_bytes) def test_get_valid_content_type(): diff --git a/packages/serialization/json/tests/unit/test_json_serialization_writer_factory.py b/packages/serialization/json/tests/unit/test_json_serialization_writer_factory.py index adf452d0..f2dfbe11 100644 --- a/packages/serialization/json/tests/unit/test_json_serialization_writer_factory.py +++ b/packages/serialization/json/tests/unit/test_json_serialization_writer_factory.py @@ -13,13 +13,13 @@ def test_get_serialization_writer(): def test_get_serialization_writer_no_content_type(): - with pytest.raises(TypeError) as e_info: + with pytest.raises(TypeError): factory = JsonSerializationWriterFactory() factory.get_serialization_writer('') def test_get_serialization_writer_unsupported_content_type(): - with pytest.raises(Exception) as e_info: + with pytest.raises(Exception): factory = JsonSerializationWriterFactory() factory.get_serialization_writer('application/xml') diff --git a/packages/serialization/json/tests/unit/test_union_wrapper.py b/packages/serialization/json/tests/unit/test_union_wrapper.py index 50c5577d..14097c88 100644 --- a/packages/serialization/json/tests/unit/test_union_wrapper.py +++ b/packages/serialization/json/tests/unit/test_union_wrapper.py @@ -1,8 +1,6 @@ import json from uuid import UUID -import pytest - from kiota_serialization_json.json_parse_node import JsonParseNode from kiota_serialization_json.json_serialization_writer import JsonSerializationWriter