Skip to content

Commit

Permalink
various pylint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
anish-mudaraddi committed Aug 3, 2023
1 parent 2a79a0b commit 2891441
Show file tree
Hide file tree
Showing 17 changed files with 29 additions and 63 deletions.
2 changes: 0 additions & 2 deletions lib/exceptions/enum_mapping_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ class EnumMappingError(ValueError):
"""
Exception is raised when Enum is not mapped.
"""

pass
2 changes: 2 additions & 0 deletions lib/exceptions/query_preset_mapping_error.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from exceptions.enum_mapping_error import EnumMappingError

# pylint:disable=too-few-public-methods


class QueryPresetMappingError(EnumMappingError):
"""
Expand Down
2 changes: 2 additions & 0 deletions lib/exceptions/query_property_mapping_error.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from exceptions.enum_mapping_error import EnumMappingError

# pylint:disable=too-few-public-methods


class QueryPropertyMappingError(EnumMappingError):
"""
Expand Down
1 change: 0 additions & 1 deletion lib/openstack_api/openstack_floating_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from openstack_api.dataclasses import (
NonExistentCheckParams,
NonExistentProjectCheckParams,
EmailQueryParams,
)

from openstack_api.openstack_connection import OpenstackConnection
Expand Down
1 change: 0 additions & 1 deletion lib/openstack_api/openstack_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from openstack_api.dataclasses import (
NonExistentCheckParams,
NonExistentProjectCheckParams,
EmailQueryParams,
)

from openstack_api.openstack_connection import OpenstackConnection
Expand Down
14 changes: 8 additions & 6 deletions lib/openstack_query/managers/query_manager.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from typing import Optional, Set, List
import re

from enums.query.query_output_types import QueryOutputTypes
from enums.query.props.prop_enum import PropEnum
from enums.cloud_domains import CloudDomains
from enums.query.query_presets import (
QueryPresetsString,
QueryPresetsGeneric,
QueryPresetsDateTime,
)

from structs.query.query_output_details import QueryOutputDetails
from structs.query.query_preset_details import QueryPresetDetails

from openstack_query.queries.query_wrapper import QueryWrapper
from custom_types.openstack_query.aliases import QueryReturn
import re
from enums.query.query_presets import (
QueryPresetsString,
QueryPresetsGeneric,
QueryPresetsDateTime,
)

# pylint:disable=too-few-public-methods

Expand Down Expand Up @@ -170,6 +170,8 @@ def search_by_regex(self, property_to_search_by: str, pattern: str, **kwargs):
),
)

# maybe convert days, hours, minutes, seconds into a dataclass?
# pylint:disable=too-many-arguments
def search_by_datetime(
self,
search_mode: str,
Expand Down
14 changes: 1 addition & 13 deletions lib/openstack_query/managers/server_manager.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
from typing import List
import re
from custom_types.openstack_query.aliases import QueryReturn

from enums.query.query_presets import (
QueryPresetsDateTime,
QueryPresetsString,
QueryPresetsGeneric,
)
from enums.query.props.server_properties import ServerProperties
from enums.cloud_domains import CloudDomains

from openstack_query.queries.server_query import ServerQuery
from openstack_query.managers.query_manager import QueryManager

from structs.query.query_preset_details import QueryPresetDetails
from structs.query.query_output_details import QueryOutputDetails

# pylint:disable=too-many-arguments
# pylint:disable=too-few-public-methods


class ServerManager(QueryManager):
Expand Down
14 changes: 3 additions & 11 deletions lib/openstack_query/managers/user_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
from openstack_query.queries.user_query import UserQuery
from openstack_query.managers.query_manager import QueryManager


from exceptions.parse_query_error import ParseQueryError

# pylint:disable=too-few-public-methods


class UserManager(QueryManager):
"""
Expand All @@ -23,16 +24,7 @@ def __init__(self, cloud_account: CloudDomains):
prop_cls=UserProperties,
)

def search_by_datetime(
self,
search_mode: str,
property_to_search_by: str,
days: int = 0,
hours: int = 0,
minutes: int = 0,
seconds: int = 0,
**kwargs,
) -> QueryReturn:
def search_by_datetime(self, **kwargs) -> QueryReturn:
"""
Method to search by datetime.
For querying users this will raise an error as this is not possible
Expand Down
1 change: 0 additions & 1 deletion lib/openstack_query/queries/user_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from openstack_query.queries.query_wrapper import QueryWrapper
from openstack_query.runners.user_runner import UserRunner

from openstack_query.time_utils import TimeUtils

# pylint:disable=too-few-public-methods

Expand Down
8 changes: 4 additions & 4 deletions lib/structs/query/query_output_details.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import Optional, List
from typing import List
from enums.query.query_output_types import QueryOutputTypes
from enums.query.props.prop_enum import PropEnum

Expand All @@ -22,13 +22,13 @@ def from_kwargs(prop_cls: PropEnum, **kwargs):
:param prop_cls a PropEnum class to get enum from for properties to select
:param kwargs: A set of kwargs to parse and use to set attributes to dataclass
"""
props = [prop for prop in prop_cls]
props = list(prop_cls)
output_type = QueryOutputTypes.TO_STR
if "properties_to_select" in kwargs.keys() and kwargs["properties_to_select"]:
if "properties_to_select" in kwargs and kwargs["properties_to_select"]:
props = [
prop_cls.from_string(prop) for prop in kwargs["properties_to_select"]
]

if "output_type" in kwargs.keys() and kwargs["output_type"]:
if "output_type" in kwargs and kwargs["output_type"]:
output_type = QueryOutputTypes.from_string(kwargs["output_type"])
return QueryOutputDetails(properties_to_select=props, output_type=output_type)
2 changes: 0 additions & 2 deletions tests/enums/props/test_user_properties.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from parameterized import parameterized

from enums.query.props.user_properties import UserProperties
from nose.tools import raises
from exceptions.parse_query_error import ParseQueryError


@parameterized(["user_domain_id", "User_Domain_ID", "UsEr_DoMaIn_iD"])
Expand Down
2 changes: 0 additions & 2 deletions tests/lib/openstack_query/managers/test_query_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from unittest.mock import MagicMock, patch, NonCallableMock
from parameterized import parameterized

from nose.tools import raises
from openstack_query.managers.query_manager import QueryManager
from enums.query.query_output_types import QueryOutputTypes
from enums.query.query_presets import (
Expand All @@ -13,7 +12,6 @@

from structs.query.query_preset_details import QueryPresetDetails

from lib.exceptions.parse_query_error import ParseQueryError
from tests.lib.openstack_query.mocks.mocked_structs import (
MOCKED_OUTPUT_DETAILS,
MOCKED_PRESET_DETAILS,
Expand Down
11 changes: 1 addition & 10 deletions tests/lib/openstack_query/managers/test_server_manager.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import unittest
from unittest.mock import MagicMock, patch, NonCallableMock
from unittest.mock import MagicMock, patch

from openstack_query.managers.server_manager import ServerManager

from enums.query.query_presets import (
QueryPresetsDateTime,
QueryPresetsString,
QueryPresetsGeneric,
)
from enums.query.props.server_properties import ServerProperties
from enums.query.query_output_types import QueryOutputTypes
from structs.query.query_preset_details import QueryPresetDetails


@patch("openstack_query.managers.query_manager.QueryManager._build_and_run_query")
@patch("openstack_query.managers.server_manager.QueryOutputDetails")
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/openstack_query/managers/test_user_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
from unittest.mock import MagicMock, patch, NonCallableMock
from unittest.mock import MagicMock

from nose.tools import raises

Expand Down
9 changes: 5 additions & 4 deletions tests/lib/openstack_query/runners/test_user_runner.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import unittest
from unittest.mock import Mock, MagicMock, call, patch
from unittest.mock import MagicMock, patch
from nose.tools import raises
from parameterized import parameterized
from openstack_query.runners.user_runner import UserRunner

from openstack_query.runners.user_runner import UserRunner
from openstack.identity.v3.user import User

from exceptions.parse_query_error import ParseQueryError
from exceptions.enum_mapping_error import EnumMappingError

# pylint:disable=protected-access
from enums.user_domains import UserDomains
from exceptions.enum_mapping_error import EnumMappingError

# pylint:disable=protected-access


class RunnerTests(unittest.TestCase):
Expand Down
4 changes: 1 addition & 3 deletions tests/lib/test_openstack_query.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from dataclasses import dataclass
import datetime
import unittest
from typing import Dict
from unittest import mock
from unittest.mock import MagicMock, patch, NonCallableMock, Mock
from unittest.mock import MagicMock, NonCallableMock, Mock

import openstack

Expand All @@ -14,7 +13,6 @@
)

from openstack_api.openstack_query import OpenstackQuery
from structs.email_params import EmailParams


class OpenstackQueryTests(unittest.TestCase):
Expand Down
3 changes: 1 addition & 2 deletions tests/structs/test_query_output_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class QueryOutputDetailsTests(unittest.TestCase):

def setUp(self) -> None:
self.instance = QueryOutputDetails
self.mock_all_properties = [prop for prop in ServerProperties]

@parameterized.expand(
[
Expand All @@ -29,7 +28,7 @@ def test_from_kwargs(self, _, set_mock_props, mock_output_type):
set correct attributes in QueryOutputDetails dataclass and return
"""

expected_mock_props = [prop for prop in ServerProperties]
expected_mock_props = list(ServerProperties)
mock_props = [prop.name for prop in ServerProperties]
if set_mock_props:
expected_mock_props = [
Expand Down

0 comments on commit 2891441

Please sign in to comment.