Ejemplo n.º 1
0
def validate_events(events='all', allowed_events=set(WalkoffEvent)):
    """Validates a set of events against allowed events. Converts strings to events if possible.

    Args:
        events (str|WalkoffEvent|iterable(str|WalkoffEvent), optional): The event or events to validate.
            Defaults to all events
        allowed_events (iterable(WalkoffEvent), optional): The allowed events. Defaults to all WalkoffEvents

    Returns:
        set(WalkoffEvent): The converted set of events.

    Raises:
        UnknownEvent: If some events passed in are not in available_events
    """
    if events == 'all':
        return set(allowed_events)
    converted_events = convert_events(events)
    if set(converted_events) - set(allowed_events):
        raise UnknownEvent(set(converted_events) - set(allowed_events))
    return converted_events
Ejemplo n.º 2
0
def convert_events(events):
    """Converts events from signal names to WalkoffEvents

    Args:
        events (str|WalkoffEvent|iterable(str|WalkoffEvent)): The events to convert

    Returns:
        set{WalkoffEvent}: The converted events

    Raises:
        UnknownEvent: If any signal name has no corresponding WalkoffEvent
    """
    converted_events = set()
    for event in convert_to_iterable(events):
        if isinstance(event, WalkoffEvent):
            converted_events.add(event)
        else:
            converted_event = WalkoffEvent.get_event_from_signal_name(event)
            if converted_event is None:
                raise UnknownEvent(event)
            converted_events.add(converted_event)
    return converted_events
Ejemplo n.º 3
0
 def test_unknown_event_init_multiple_event(self):
     exception = UnknownEvent(['Event1', 'Event2'])
     self.assertIn('Event1', exception.message)
     self.assertIn('Event2', exception.message)
Ejemplo n.º 4
0
 def test_unknown_event_init_single_event(self):
     exception = UnknownEvent('SingleEvent')
     self.assertIn('SingleEvent', exception.message)