When I perform unit testing for the state machines using farc, I want to independently run several test cases. That is, I want to have a new loop created for each test. Currently, once we import the farc package, a default event loop, which is a class variable, is created for the Framework class.
class Framework(object):
"""Framework is a composite class that holds:
- the asyncio event loop
- the registry of AHSMs
- the set of TimeEvents
- the handle to the next TimeEvent
- the table subscriptions to events
"""
_event_loop = asyncio.get_event_loop()
I propose to add a class method to allow us to specify the used event loop and reset the Framework.
For example:
class Framework(object):
"""Framework is a composite class that holds:
- the asyncio event loop
- the registry of AHSMs
- the set of TimeEvents
- the handle to the next TimeEvent
- the table subscriptions to events
"""
#_event_loop = asyncio.get_event_loop()
_event_loop = None
...
@classmethod
def init(cls, loop):
cls._event_loop = loop
cls._priority_dict.clear()
# May need to reset other class variables too.
# Bind a useful set of POSIX signals to the handler
# (ignore a NotImplementedError on Windows)
try:
cls._event_loop.add_signal_handler(signal.SIGINT, lambda: Framework.stop())
cls._event_loop.add_signal_handler(signal.SIGTERM, lambda: Framework.stop())
cls._event_loop.add_signal_handler(29, Framework.print_info)
except NotImplementedError:
pass
When I perform unit testing for the state machines using
farc, I want to independently run several test cases. That is, I want to have a new loop created for each test. Currently, once we import thefarcpackage, a default event loop, which is a class variable, is created for theFrameworkclass.I propose to add a class method to allow us to specify the used event loop and reset the Framework.
For example: