Skip to content

Allow to run several unit test cases independently #9

@maxpeng

Description

@maxpeng

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions