def process_token(self, token): action_type, args, kw = ActionRegistry.suitable_for(token.line) if not action_type: raise ActionNotFoundError("The action for the line \"%s\" was not found. Are you sure you have that action right?" % token.line) action = lambda context: action_type().execute_action(context, *args, **kw) self.actions.append(action)
def test_action_registry_returns_action(): class ActionToTest(ActionBase): regex = r'^Test$' def execute(): pass action, args, kw = ActionRegistry.suitable_for('Test') assert action is ActionToTest assert not args assert not kw
def test_action_registry_returns_kw_only_when_both_named_and_unnamed_groups_are_specified(): class ActionToTest4(ActionBase): regex = r'^Test4-(\d)-(?P<index>\d)$' def execute(): pass action, args, kw = ActionRegistry.suitable_for('Test4-1-2') assert action is ActionToTest4 assert kw.has_key('index') assert kw['index'] == '2' assert not args
def test_action_registry_returns_named_groups_as_kw(): class ActionToTest3(ActionBase): regex = r'^Test3-(?P<index>\d)$' def execute(): pass action, args, kw = ActionRegistry.suitable_for('Test3-2') assert action is ActionToTest3 assert kw.has_key('index') assert kw['index'] == '2' assert not args
def test_action_registry_returns_groups_as_args(): class ActionToTest2(ActionBase): regex = r'^Test2-(\d)$' def execute(): pass action, args, kw = ActionRegistry.suitable_for('Test2-2') assert action is ActionToTest2 assert len(args) == 1 assert args[0] == '2' assert not kw