Skip to content

Commit

Permalink
Linting fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
chsou committed Nov 20, 2024
1 parent 9110aad commit 79048ff
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 19 deletions.
3 changes: 3 additions & 0 deletions c8y_api/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,6 @@ def _get_tenant_instance(self, tenant_id: str) -> CumulocityApi:

def __enter__(self) -> MultiTenantCumulocityApp:
return self

def __exit__(self, __exc_type, __exc_value, __traceback):
pass
4 changes: 1 addition & 3 deletions c8y_api/model/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
from __future__ import annotations

import logging
from urllib.parse import quote_plus
from typing import Any, Iterable, Set
from urllib.parse import quote_plus, urlencode

from collections.abc import MutableMapping
from deprecated import deprecated
from urllib.parse import urlencode

from c8y_api._base_api import CumulocityRestApi

from c8y_api.model._util import _DateUtil, _StringUtil, _QueryUtil


Expand Down
1 change: 0 additions & 1 deletion c8y_api/model/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from __future__ import annotations

from typing import Any, Generator, List
from urllib.parse import urlencode, quote_plus

from c8y_api.model._base import CumulocityResource
from c8y_api.model._util import _QueryUtil
Expand Down
1 change: 0 additions & 1 deletion c8y_api/model/measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import dataclasses
from datetime import datetime, timedelta
from typing import Type, List, Generator, Sequence
from urllib.parse import urlencode, quote_plus

from c8y_api._base_api import CumulocityRestApi

Expand Down
1 change: 0 additions & 1 deletion c8y_tk/interactive/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# and/or its subsidiaries and/or its affiliates and/or their licensors.
# Use, reproduction, transfer, publication or disclosure is prohibited except
# as specifically provided for in your License Agreement with Software AG.
import contextlib
# pylint: disable=protected-access

import getpass
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/test_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ def test_context_manager(test_environment):
assert c8y.username

with MultiTenantCumulocityApp() as c8y:
assert c8y.username
assert c8y.bootstrap_instance.username
5 changes: 1 addition & 4 deletions integration_tests/test_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def factory_fun(n: int, device=None, type=None, series=None) -> List[Measurement

def test_select(live_c8y: CumulocityApi, measurement_factory):
"""Verify that selection works as expected."""
# pylint: disable=too-many-statements)
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
Expand All @@ -77,21 +78,17 @@ def test_select(live_c8y: CumulocityApi, measurement_factory):

# create a couple of measurements (at a new device)
created_ms = measurement_factory(10, type=name, series=name)
created_values = [m[name]['series'].value for m in created_ms]

# create a couple of measurements with different source
source_ms = measurement_factory(10, type=name, series=name)
source_values = [m[name]['series'].value for m in source_ms]

# create a couple of measurements with different type name
device_id = created_ms[0].source
device = live_c8y.device_inventory.get(created_ms[0].source)
type_ms = measurement_factory(10, device=device, type=other_name, series=name)
type_values = [m[name]['series'].value for m in type_ms]

# create a couple of measurements with different series name
series_ms = measurement_factory(10, device=device, type=name, series=other_name)
series_values = [m[other_name]['series'].value for m in series_ms]

# (1) all measurement collections can be selected separately

Expand Down
10 changes: 5 additions & 5 deletions tests/model/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,11 @@ def test_iteration(page_size, num_all, limit, expected):
all_items = [{'i': i} for i in range(num_all)]

# returns a 'page' from all items
def get_page(_, page):
def get_page(_, p):
nonlocal all_items
s = page_size * (page - 1)
e = page_size * page
return [i for i in all_items[s:e]]
s = page_size * (p - 1)
e = page_size * p
return all_items[s:e]

# parses an item as CumulocityObject
def parse_fun(item):
Expand All @@ -261,7 +261,7 @@ def parse_fun(item):

# create class under test
res = CumulocityResource(Mock(CumulocityRestApi), '')
res._get_page = get_page
res._get_page = Mock(side_effect=get_page)

# iterate oder results
result = list(res._iterate(base_query="q", page_number=None, limit=limit, parse_fun=parse_fun))
Expand Down
5 changes: 4 additions & 1 deletion tests/model/test_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Use, reproduction, transfer, publication or disclosure is prohibited except
# as specifically provided for in your License Agreement with Software AG.
# pylint: disable=protected-access
import itertools

from unittest.mock import Mock

import pytest
Expand Down Expand Up @@ -108,6 +108,7 @@ def _invoke_target_and_isolate_url(target, kwargs):


def gen_common_select_cases():
"""Generate test case data for common select cases."""
return [
# expression has the highest priority
({'expression': 'EX', 'query': 'QUERY'}, ['?EX'], ['query=', 'QUERY']),
Expand Down Expand Up @@ -156,6 +157,7 @@ def gen_common_select_cases():


def gen_common_select_cases_ids():
"""Generate test case ID for common select cases."""
return ['+'.join(x[0].keys()) for x in gen_common_select_cases()]


Expand All @@ -171,6 +173,7 @@ def gen_common_select_cases_ids():
'group_inventory.get_count',
])
def test_common_select_params(fun, params, expected, not_expected):
"""Verify that common select parameters are handled correctly."""
url = _invoke_target_and_isolate_url(fun, params)
for e in expected:
assert e in url
Expand Down
3 changes: 1 addition & 2 deletions tests/model/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
# as specifically provided for in your License Agreement with Software AG.

from datetime import timedelta
from unittest.mock import Mock, patch
from unittest.mock import Mock
from urllib.parse import unquote_plus

import pytest

from c8y_api import CumulocityApi
from c8y_api.model import Operations
from model import BulkOperations

from tests.utils import isolate_last_call_arg

Expand Down

0 comments on commit 79048ff

Please sign in to comment.