From 8feb4edd75ecb271435ab48f25267390d9aec070 Mon Sep 17 00:00:00 2001 From: PRANETALLU <92874312+PRANETALLU@users.noreply.github.com> Date: Tue, 24 Oct 2023 00:01:29 -0400 Subject: [PATCH] spoof.py documentation done --- .../navigator_test_lib/spoof.py | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/NaviGator/test/navigator_test/navigator_test_lib/spoof.py b/NaviGator/test/navigator_test/navigator_test_lib/spoof.py index 5cb974b4c..f1bc46809 100644 --- a/NaviGator/test/navigator_test/navigator_test_lib/spoof.py +++ b/NaviGator/test/navigator_test/navigator_test_lib/spoof.py @@ -3,6 +3,13 @@ class SpoofPubilsher: + """ + Attributes: + topic_name (str): the name of the topic + message_type (str): the actual content + responses (List[str]): stores a list of responses + times (int): represents the current time + """ def __init__(self, topic_name, message_type, responses, times): self.topic_name = topic_name self.responses = responses @@ -11,6 +18,12 @@ def __init__(self, topic_name, message_type, responses, times): self.total = len(self.responses) async def start(self, nh): + """ + To simplify, this publishes the necessary information within an allocation time slot. + + Args: + nh (NodeHandle): peforms all operations for the successful publication of content. + """ self.my_pub = await nh.advertise(self.topic_name, self.message_type) i = 0 started = nh.get_time() @@ -24,10 +37,22 @@ async def start(self, nh): await nh.sleep(0.3) async def stop(self): + """ + Stops the process that is initally set by "nh.advertise". + """ await self.my_pub.shutdown() class SpoofService: + """ + Attributes: + service_name (str): the name of the service + responses (List[str]): stores a list of responses + message_type (str): the actual content + total (int): the length of the array "responses" + count (int): a regular incrementor + serv: performs service functions, such as "setup" and "shutdown" + """ def __init__(self, service_name, message_type, responses): self.service_name = service_name self.responses = responses @@ -37,23 +62,62 @@ def __init__(self, service_name, message_type, responses): self.serv = None async def start(self, nh: NodeHandle): + """sets up the process using a NodeHandler + + Args: + nh (NodeHandle): it is an object that ensures a proper setup using service components + """ self.serv = nh.advertise_service( self.service_name, self.message_type, self._service_cb ) await self.serv.setup() def _service_cb(self, req): + """Increments the counter to move on to the next index position + + Args: + req (n/a): unused variable + + Returns: + ans: it returns the value from array "responses" from the incremented index + """ ans = self.responses[self.count % self.total] self.count += 1 return ans async def stop(self): + """ + Stops the process that is initally set by "nh.advertise_service". + """ await self.serv.shutdown() class SpoofGenerator: def spoof_service(self, service_name, message_type, responses): + """ + Returns "SpoofService" object + + Args: + service_name (str): the name of the service + message_type (str): the actual content + responses (List[str]): stores a list of responses + + Returns: + SpoofService: an instance of "SpoofService" with arguments passed from the parameters of the function + """ return SpoofService(service_name, message_type, responses) def spoof_publisher(self, topic_name, message_type, responses, time): + """ + Returns "SpoofPubilsher" object + + Args: + topic_name (str): the name of the topic + message_type (str): the actual content + responses (List[str]): stores a list of responses + time (int): represents the current time + + Returns: + SpoofPubilsher: an instance of "SpoofPubilsher" with arguments passed from the parameters of the function + """ return SpoofPubilsher(topic_name, message_type, responses, time)