def feature_definition(context, **kwargs): parser = Parser(language=kwargs.get('lang', None)) feature = parser.parse(context.text) if hasattr(context, "feature_definition"): context.feature_definition.append(feature) else: context.feature_definition = [feature]
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))
def add_feature(self, path): with open(path, 'rb') as feature_file: # file encoding is assumed to be utf8. Oh, yes. data = feature_file.read().decode('utf8').strip() # ALL data operated on by the parser MUST be unicode assert isinstance(data, unicode) try: if data: feature = Parser(DEFAULT_LANGUAGE).parse(data, path) else: raise ParserError("Empty file", line=0) if feature is None: raise ParserError("Unknown reasons", line=0) else: self.features.append(feature) except ParserError, e: e.filename = path raise
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)
def feature_definition(context, **kwargs): parser = Parser(language=kwargs.get('lang', None)) context.feature_definition = parser.parse(context.text)