示例#1
0
    def __init__(self, language=None, variant=None):
        self.parser = Parser(language=language, variant=variant)
        self.registry = StepRegistry()

        # Create decorators for the local registry
        for step_type in step_names.split():
            setattr(self, step_type, self.registry.make_decorator(step_type))
示例#2
0
    def __init__(self, step_registry=None):
        if step_registry is None:
            step_registry = StepRegistry()
        matcher_factory = MatcherFactory()

        self.step_registry = step_registry
        self.step_registry.matcher_factory = matcher_factory
        self.matcher_factory = matcher_factory
示例#3
0
    def discover_step_definitions(self):
        if self.step_registry is None:
            self.step_registry = StepRegistry()

        for step_type in registry.steps.keys():
            step_definitions = tuple(registry.steps[step_type])
            for step_definition in step_definitions:
                step_definition.step_type = step_type
            self.step_registry.steps[step_type] = step_definitions
示例#4
0
class SubSteps:
    def __init__(self, language=None, variant=None):
        self.parser = Parser(language=language, variant=variant)
        self.registry = StepRegistry()

        # Create decorators for the local registry
        for step_type in step_names.split():
            setattr(self, step_type, self.registry.make_decorator(step_type))

    @staticmethod
    def run_match(match, context):
        args = []
        kwargs = {}
        for arg in match.arguments:
            if arg.name is not None:
                kwargs[arg.name] = arg.value
            else:
                args.append(arg.value)

        return match.func(context, *args, **kwargs)

    def run(self, text, context):
        """
        Parse the given text and yield step functions.

        """
        steps = self.parser.parse_steps(text)
        for step in steps:
            match = self.registry.find_match(step)
            if match is None:
                raise ValueError("substep not found '%s'" % step)
            else:
                subcontext = SubContext(
                    table=step.table,
                    text=step.text,
                    step_context=context)
                yield self.run_match(match, context)
示例#5
0
    def setUp(self):
        if not self.step_registry:
            # -- SETUP ONCE:
            self.step_registry = StepRegistry()
            ExampleSteps.register_steps_with(self.step_registry)
        ExampleSteps.text = None
        ExampleSteps.table = None

        runner_ = Mock()
        self.config = runner_.config = Mock()
        runner_.config.verbose = False
        runner_.config.stdout_capture = False
        runner_.config.stderr_capture = False
        runner_.config.log_capture = False
        runner_.step_registry = self.step_registry

        self.context = runner.Context(runner_)
        runner_.context = self.context
        self.context.feature = Mock()
        self.context.feature.parser = parser.Parser()
        self.context.runner = runner_