Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
scenario_test_tools.scriptable_base.ScriptableBase Class Reference
Inheritance diagram for scenario_test_tools.scriptable_base.ScriptableBase:
Inheritance graph
[legend]

Public Member Functions

def __init__ (self, name, goal_formatter=format, reply_formatter=format, default_reply=None, default_reply_delay=0)
 
def add_pre_reply_callback (self, callback)
 
def await_goal (self, timeout=None, marker=None)
 
def clear_goals (self)
 
def current_goal (self)
 
def custom_reply (self)
 
def default_reply (self)
 
def default_reply (self, result)
 
def default_reply_delay (self)
 
def default_reply_delay (self, delay)
 
def direct_reply (self, result, reply_delay=None, marker=None)
 
def match_in_received_goals (self, match_against, key=lambda x:x)
 
def name (self)
 
def received_goals (self)
 
def remember_goals (self)
 
def reply (self, result, timeout=None, reply_delay=None, marker=None)
 
def reply_conditionally (self, condition, true_result, false_result, timeout=None, reply_delay=None, marker=None)
 
def stop (self)
 

Public Attributes

 default_reply
 
 goal_formatter
 
 result_formatter
 

Private Member Functions

def _call_pre_reply_callbacks (self, goal, reply)
 

Private Attributes

 _current_goal
 
 _default_reply
 
 _default_reply_delay
 
 _name
 
 _next_reply
 
 _pre_reply_callbacks
 
 _received_goals
 
 _reply
 
 _request
 
 _sent
 
 _waiting_for
 

Detailed Description

ScriptableBase is a superclass that has common functionality for Scriptable... callbacks.

It allows to set a default reply that can be overridden if need be, so custom replies can be defined

Definition at line 24 of file scriptable_base.py.

Constructor & Destructor Documentation

def scenario_test_tools.scriptable_base.ScriptableBase.__init__ (   self,
  name,
  goal_formatter = format,
  reply_formatter = format,
  default_reply = None,
  default_reply_delay = 0 
)
Set up a ScriptableBase. Must be subclassed.

:param name: the action namespace the server should operate on (e.g. `move_base`)
:param goal_formatter: a function accepting a goal and returning a nice-looking summary str of it
:param reply_formatter: a function accepting a result and returning a nice-looking summary str of it
:param default_reply: optional. If set, this will be returned after default_result_delay,
    otherwise a .reply* call is needed to send a reply. Overriding the default reply and
    doing something custom is possible with the `custom_reply`-context manager
:param default_reply_delay: If default_result is defined, the Scriptable... waits for this delay before returning.
    This delay is also used when no more specific reply_delay is specified in a reply_*-call

Definition at line 31 of file scriptable_base.py.

Member Function Documentation

def scenario_test_tools.scriptable_base.ScriptableBase._call_pre_reply_callbacks (   self,
  goal,
  reply 
)
private
Trigger all callback in the order they were added, with the current goal and the reply to it

:param goal: current goal
:param reply: reply to that goal

Definition at line 310 of file scriptable_base.py.

def scenario_test_tools.scriptable_base.ScriptableBase.add_pre_reply_callback (   self,
  callback 
)
Add a callback that is called just before a result is being sent back

:param callback: callable that will receive the goal and result. The return value of the callable is discarded

Definition at line 301 of file scriptable_base.py.

def scenario_test_tools.scriptable_base.ScriptableBase.await_goal (   self,
  timeout = None,
  marker = None 
)
Await a goal to be sent to this Scriptable... and return that goal for close inspection.
Based on that, send a reply via `direct_reply`
An AssertionError is raised when a goal is not received within the given timeout.

:param timeout: how long to wait for the goal? Defaults to None to wait indefinitely
:param marker: A str that is printed in the output for easy reference between different replies
:return: the received goal

Definition at line 177 of file scriptable_base.py.

def scenario_test_tools.scriptable_base.ScriptableBase.clear_goals (   self)
Clear the log of goals that we've received

Definition at line 281 of file scriptable_base.py.

def scenario_test_tools.scriptable_base.ScriptableBase.current_goal (   self)
The goal we've received last

Definition at line 288 of file scriptable_base.py.

def scenario_test_tools.scriptable_base.ScriptableBase.custom_reply (   self)
Use this context manager to temporarily define your own replies and go back to defaulting outside the context

Usage:

>>> server = ScriptableBase()
>>> server.default_result = True
>>> # Do other stuff that does not require special attention of server
>>> with server.custom_reply():
>>>    server.reply(False)
>>> # Continue to do other stuff that does not require special attention of server

Definition at line 262 of file scriptable_base.py.

def scenario_test_tools.scriptable_base.ScriptableBase.default_reply (   self)
The Result that is currently set to be returned by default

Definition at line 231 of file scriptable_base.py.

def scenario_test_tools.scriptable_base.ScriptableBase.default_reply (   self,
  result 
)
Set the current default reply.
If this is None, there will not be a default reply, then a reply must be defined via a reply*-call

:param result: a ...Result of the type associated with the type of this server

Definition at line 238 of file scriptable_base.py.

def scenario_test_tools.scriptable_base.ScriptableBase.default_reply_delay (   self)
Wait this amount of time before returning the default reply

Definition at line 248 of file scriptable_base.py.

def scenario_test_tools.scriptable_base.ScriptableBase.default_reply_delay (   self,
  delay 
)
Set the delay after which the `default_result` is sent

:param delay number of seconds to wait before sending the `default_result`

Definition at line 255 of file scriptable_base.py.

def scenario_test_tools.scriptable_base.ScriptableBase.direct_reply (   self,
  result,
  reply_delay = None,
  marker = None 
)
Reply to the current goal with the given result, after `reply_delay` amount of seconds.

:param result: a ...Result of the type associated with the type of this server
:param reply_delay: how long to 'reply_delay/calculate' on this goal before sending the reply
:param marker: A str that is printed in the output for easy reference between different replies

Definition at line 203 of file scriptable_base.py.

def scenario_test_tools.scriptable_base.ScriptableBase.match_in_received_goals (   self,
  match_against,
  key = lambda x: x 
)
Find out if this server has any goal in it's history that is also in `match_against`

:param match_against: We're looking for any of the items in `match_against`
:param key: optionally transform the received goals with this callable into the same type as `match_against`'s elements
:return: The matching elements

Definition at line 320 of file scriptable_base.py.

def scenario_test_tools.scriptable_base.ScriptableBase.name (   self)

Definition at line 74 of file scriptable_base.py.

def scenario_test_tools.scriptable_base.ScriptableBase.received_goals (   self)
all goals received (since the last `clear_goals()` call

Definition at line 295 of file scriptable_base.py.

def scenario_test_tools.scriptable_base.ScriptableBase.remember_goals (   self)
Remember goals only instance of this context.
Goals before this context are forgotten;
Goals received during/in the context only are remembered;
after the context everything is forgotten.

Definition at line 334 of file scriptable_base.py.

def scenario_test_tools.scriptable_base.ScriptableBase.reply (   self,
  result,
  timeout = None,
  reply_delay = None,
  marker = None 
)
Reply to the next goal with the given result, after `reply_delay` amount of seconds.
An AssertionError is raised when a goal is not received within the given timeout.

:param result: an ...ActionResult of the type associated with the Action-type of this server
:param timeout: how long to wait for the goal? Defaults to None to wait indefinitely
:param reply_delay: how to to reply_delay/calculate on this goal before sending the reply
:param marker: A str that is printed in the output for easy reference between different replies
:return: None

Definition at line 84 of file scriptable_base.py.

def scenario_test_tools.scriptable_base.ScriptableBase.reply_conditionally (   self,
  condition,
  true_result,
  false_result,
  timeout = None,
  reply_delay = None,
  marker = None 
)
Reply one of two possibilities, based on a condition. This is a callable that, given a Goal, returns a bool
If True, then reply with the true_reply and vice versa.
An AssertionError is raised when a goal is not received within the given timeout.

:param condition: callable(...Goal) -> bool
:param true_result: a ...Result
:param false_result: a ...Result
:param timeout: seconds to wait for the goal. Defaults to None to wait indefinitely
:param reply_delay: Delay the reply by this amount of seconds
:param marker: A str that is printed in the output for easy reference between different replies
:return: bool

Definition at line 125 of file scriptable_base.py.

def scenario_test_tools.scriptable_base.ScriptableBase.stop (   self)
If the process is blocked by waiting for some Events to be set, stop sets those Events.

Definition at line 77 of file scriptable_base.py.

Member Data Documentation

scenario_test_tools.scriptable_base.ScriptableBase._current_goal
private

Definition at line 46 of file scriptable_base.py.

scenario_test_tools.scriptable_base.ScriptableBase._default_reply
private

Definition at line 66 of file scriptable_base.py.

scenario_test_tools.scriptable_base.ScriptableBase._default_reply_delay
private

Definition at line 67 of file scriptable_base.py.

scenario_test_tools.scriptable_base.ScriptableBase._name
private

Definition at line 44 of file scriptable_base.py.

scenario_test_tools.scriptable_base.ScriptableBase._next_reply
private

Definition at line 49 of file scriptable_base.py.

scenario_test_tools.scriptable_base.ScriptableBase._pre_reply_callbacks
private

Definition at line 71 of file scriptable_base.py.

scenario_test_tools.scriptable_base.ScriptableBase._received_goals
private

Definition at line 69 of file scriptable_base.py.

scenario_test_tools.scriptable_base.ScriptableBase._reply
private

Definition at line 55 of file scriptable_base.py.

scenario_test_tools.scriptable_base.ScriptableBase._request
private

Definition at line 52 of file scriptable_base.py.

scenario_test_tools.scriptable_base.ScriptableBase._sent
private

Definition at line 59 of file scriptable_base.py.

scenario_test_tools.scriptable_base.ScriptableBase._waiting_for
private

Definition at line 61 of file scriptable_base.py.

scenario_test_tools.scriptable_base.ScriptableBase.default_reply

Definition at line 101 of file scriptable_base.py.

scenario_test_tools.scriptable_base.ScriptableBase.goal_formatter

Definition at line 63 of file scriptable_base.py.

scenario_test_tools.scriptable_base.ScriptableBase.result_formatter

Definition at line 64 of file scriptable_base.py.


The documentation for this class was generated from the following file:


scenario_test_tools
Author(s): Loy van Beek
autogenerated on Wed Apr 7 2021 03:03:18