Skip to content

Commit

Permalink
Async RPClient: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Aug 30, 2023
1 parent 6ef4137 commit 7c4b35c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
9 changes: 5 additions & 4 deletions reportportal_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
limitations under the License.
"""

from ._local import current
from .logs import RPLogger, RPLogHandler
from .client import RPClient
from .steps import step
# noinspection PyProtectedMember
from reportportal_client._local import current
from reportportal_client.logs import RPLogger, RPLogHandler
from reportportal_client.client import RPClient
from reportportal_client.steps import step

__all__ = [
'current',
Expand Down
12 changes: 12 additions & 0 deletions reportportal_client/async/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2023 EPAM Systems
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

import aiohttp

from .core.rp_issues import Issue
from .logs.log_manager import LogManager, MAX_LOG_BATCH_PAYLOAD_SIZE
from .static.defines import NOT_FOUND
from .steps import StepReporter
from reportportal_client.core.rp_issues import Issue
from reportportal_client.logs.log_manager import LogManager, MAX_LOG_BATCH_PAYLOAD_SIZE
from reportportal_client.static.defines import NOT_FOUND
from reportportal_client.steps import StepReporter

logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())
Expand All @@ -37,7 +37,7 @@ def last(self):
return self.queue[-1]


class _RPClient:
class _RPClientAsync:
_log_manager: LogManager = ...
api_v1: str = ...
api_v2: str = ...
Expand Down Expand Up @@ -129,7 +129,7 @@ async def start_launch(self,
attributes: Optional[Union[List, Dict]] = None,
rerun: bool = False,
rerun_of: Optional[str] = None,
**kwargs) -> Optional[Union[asyncio.Future, str]]:
**kwargs) -> Optional[str]:
pass

async def start_test_item(self,
Expand All @@ -145,7 +145,7 @@ async def start_test_item(self,
code_ref: Optional[str] = None,
retry: bool = False,
test_case_id: Optional[str] = None,
**_: Any) -> Optional[Union[asyncio.Future, str]]:
**_: Any) -> Optional[str]:
parent = parent_item_id
if parent_item_id and asyncio.isfuture(parent_item_id):
parent = await parent_item_id
Expand All @@ -167,13 +167,13 @@ def current_item(self) -> Union[asyncio.Future, str]:
"""Retrieve the last item reported by the client."""
return self._item_stack.last()

def clone(self) -> '_RPClient':
def clone(self) -> '_RPClientAsync':
"""Clone the client object, set current Item ID as cloned item ID.
:returns: Cloned client object
:rtype: _RPClient
:rtype: _RPClientAsync
"""
cloned = _RPClient(
cloned = _RPClientAsync(
endpoint=self.endpoint,
project=self.project,
api_key=self.api_key,
Expand All @@ -193,7 +193,7 @@ def clone(self) -> '_RPClient':
return cloned


class RPClientAsync(_RPClient):
class RPClientAsync(_RPClientAsync):

async def start_test_item(self,
name: str,
Expand All @@ -208,7 +208,7 @@ async def start_test_item(self,
code_ref: Optional[str] = None,
retry: bool = False,
test_case_id: Optional[str] = None,
**kwargs: Any) -> Optional[Union[asyncio.Future, str]]:
**kwargs: Any) -> Optional[str]:
item_id = await super().start_test_item(name, start_time, item_type, description=description,
attributes=attributes, parameters=parameters,
parent_item_id=parent_item_id, has_stats=has_stats,
Expand All @@ -235,7 +235,7 @@ async def finish_test_item(self,
return result


class RPClientSync(_RPClient):
class RPClientSync(_RPClientAsync):
loop: asyncio.AbstractEventLoop
thread: threading.Thread

Expand Down Expand Up @@ -280,7 +280,7 @@ def start_test_item(self,
code_ref: Optional[str] = None,
retry: bool = False,
test_case_id: Optional[str] = None,
**kwargs: Any) -> Optional[Union[asyncio.Future, str]]:
**kwargs: Any) -> Optional[asyncio.Future]:
item_id_coro = super().start_test_item(name, start_time, item_type, description=description,
attributes=attributes, parameters=parameters,
parent_item_id=parent_item_id, has_stats=has_stats,
Expand Down
1 change: 1 addition & 0 deletions reportportal_client/steps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License

"""Report portal Nested Step handling module.
The module for handling and reporting Report Portal Nested Steps inside python
Expand Down

0 comments on commit 7c4b35c

Please sign in to comment.