Skip to content

Commit

Permalink
Async RPClient: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Sep 6, 2023
1 parent 9c05fdd commit c5ebaff
Showing 1 changed file with 74 additions and 3 deletions.
77 changes: 74 additions & 3 deletions reportportal_client/aio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
from reportportal_client.helpers import uri_join, verify_value_length, await_if_necessary, agent_name_version
from reportportal_client.logs import MAX_LOG_BATCH_PAYLOAD_SIZE
from reportportal_client.services.statistics import async_send_event
from reportportal_client.static.abstract import (
AbstractBaseClass,
abstractmethod
)
from reportportal_client.static.defines import NOT_FOUND
from reportportal_client.steps import StepReporter

Expand Down Expand Up @@ -411,7 +415,64 @@ def clone(self) -> '_AsyncRPClient':
return cloned


class AsyncRPClient:
class RPClient(metaclass=AbstractBaseClass):
__metaclass__ = AbstractBaseClass

@abstractmethod
def start_launch(self,
name: str,
start_time: str,
description: Optional[str] = None,
attributes: Optional[Union[List, Dict]] = None,
rerun: bool = False,
rerun_of: Optional[str] = None,
**kwargs) -> Union[Optional[str], asyncio.Task]:
raise NotImplementedError('"start_launch" method is not implemented!')

@abstractmethod
def start_test_item(self,
name: str,
start_time: str,
item_type: str,
*,
description: Optional[str] = None,
attributes: Optional[List[Dict]] = None,
parameters: Optional[Dict] = None,
parent_item_id: Union[Optional[str], asyncio.Task] = None,
has_stats: bool = True,
code_ref: Optional[str] = None,
retry: bool = False,
test_case_id: Optional[str] = None,
**kwargs: Any) -> Union[Optional[str], asyncio.Task]:
raise NotImplementedError('"start_test_item" method is not implemented!')

@abstractmethod
def finish_test_item(self,
item_id: Union[str, asyncio.Task],
end_time: str,
*,
status: str = None,
issue: Optional[Issue] = None,
attributes: Optional[Union[List, Dict]] = None,
description: str = None,
retry: bool = False,
**kwargs: Any) -> Union[Optional[str], asyncio.Task]:
raise NotImplementedError('"finish_test_item" method is not implemented!')

@abstractmethod
def finish_launch(self,
end_time: str,
status: str = None,
attributes: Optional[Union[List, Dict]] = None,
**kwargs: Any) -> Union[Optional[str], asyncio.Task]:
raise NotImplementedError('"finish_launch" method is not implemented!')

@abstractmethod
def get_launch_info(self) -> Union[Optional[dict], asyncio.Task]:
raise NotImplementedError('"get_launch_info" method is not implemented!')


class AsyncRPClient(RPClient):
__client: _AsyncRPClient
_item_stack: _LifoQueue
launch_uuid: Optional[str]
Expand Down Expand Up @@ -498,7 +559,7 @@ async def finish_launch(self,
attributes=attributes,
**kwargs)

async def get_launch_info(self) -> Optional[Dict]:
async def get_launch_info(self) -> Optional[dict]:
if not self.launch_uuid:
return {}
return await self.__client.get_launch_info(self.launch_uuid)
Expand Down Expand Up @@ -535,7 +596,7 @@ def clone(self) -> 'AsyncRPClient':
return cloned


class SyncRPClient:
class SyncRPClient(RPClient):
__client: _AsyncRPClient
_item_stack: _LifoQueue
loop: asyncio.AbstractEventLoop
Expand Down Expand Up @@ -650,6 +711,16 @@ def finish_launch(self,
result_task = self.loop.create_task(result_coro)
return result_task

async def __empty_dict(self):
return {}

def get_launch_info(self) -> asyncio.Task:
if not self.launch_uuid:
return self.loop.create_task(self.__empty_dict())
result_coro = self.__client.get_launch_info(self.launch_uuid)
result_task = self.loop.create_task(result_coro)
return result_task

def get_item_id_by_uuid(self, item_uuid_future: asyncio.Task) -> asyncio.Task:
result_coro = self.__client.get_item_id_by_uuid(item_uuid_future)
result_task = self.loop.create_task(result_coro)
Expand Down

0 comments on commit c5ebaff

Please sign in to comment.