Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_errors():
with pytest.raises(InvalidActionDefinition):
ActionsManager([()])
with pytest.raises(InvalidActionDefinition):
ActionsManager([None])
with pytest.raises(InvalidActionDefinition):
ActionsManager([10])
with pytest.raises(InvalidState):
ActionsManager([('rule', Action(), 'WRONG STATE')])
with pytest.raises(InvalidActionDefinition):
ActionsManager([('rule', Action(), settings.LEVEL_NORMAL, None)])
def test_errors():
with pytest.raises(InvalidActionDefinition):
ActionsManager([()])
with pytest.raises(InvalidActionDefinition):
ActionsManager([None])
with pytest.raises(InvalidActionDefinition):
ActionsManager([10])
with pytest.raises(InvalidState):
ActionsManager([('rule', Action(), 'WRONG STATE')])
with pytest.raises(InvalidActionDefinition):
ActionsManager([('rule', Action(), settings.LEVEL_NORMAL, None)])
def _get_action(self, action):
if not isinstance(action, Action):
raise InvalidActionDefinition('Wrong action, actions must subclass Action')
return action
def _add_action_from_tuple(self, tuple_definition):
trigger = None
if len(tuple_definition) == 2:
name, action = tuple_definition
elif len(tuple_definition) == 3:
name, action, trigger = tuple_definition
else:
raise InvalidActionDefinition('Wrong Action tuple definition, you should '
'either use (name, action) or '
'(name, action, state)')
self.add_action(action=action, name=name, trigger=trigger)
def _add_action_from_tuple(self, tuple_definition):
state = None
if len(tuple_definition) == 2:
name, action = tuple_definition
elif len(tuple_definition) == 3:
name, action, state = tuple_definition
else:
raise InvalidActionDefinition('Wrong Action tuple definition, you should '
'either use (name, action) or '
'(name, action, state)')
self.add_action(action=action, name=name, state=state)
def _get_action(self, action):
if not isinstance(action, Action):
raise InvalidActionDefinition('Wrong action, actions must subclass Action')
return action