How to use the behave.parser.ParserError function in behave

To help you get started, we’ve selected a few behave examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github behave / behave / behave / parser.py View on Github external
step.table = self.table
                if step.name.endswith(":"):
                    step.name = step.name[:-1]
            self.table = None
            self.state = "steps"
            return self.action_steps(line)

        # -- SUPPORT: Escaped-pipe(s) in Gherkin cell values.
        #    Search for pipe(s) that are not preceeded with an escape char.
        cells = [cell.replace("\\|", "|").strip()
                 for cell in re.split(r"(?
github behave / behave / behave / parser.py View on Github external
* End-of-line comment is stripped.

        :param line:   Line with one/more tags to process.
        :raise ParserError: If syntax error is detected.
        """
        assert line.startswith("@")
        tags = []
        for word in line.split():
            if word.startswith("@"):
                tags.append(model.Tag(word[1:], self.line))
            elif word.startswith("#"):
                break   # -- COMMENT: Skip rest of line.
            else:
                # -- BAD-TAG: Abort here.
                message = u"tag: %s (line: %s)" % (word, line)
                raise ParserError(message, self.line, self.filename)
        return tags
github behave / behave / behave / __main__.py View on Github external
config.log_capture = False
        config.stdou_capture = False

    if not config.format:
        config.format = ['pretty']
    elif config.format == ['help']:
        print "Available formatters:"
        formatters.list_formatters(sys.stdout)
        sys.exit(0)

    stream = config.output

    runner = Runner(config)
    try:
        failed = runner.run()
    except ParserError, e:
        sys.exit(str(e))
    except ConfigError, e:
        sys.exit(str(e))

    def format_summary(statement_type, summary):
        first = True
        parts = []
        for status in ('passed', 'failed', 'skipped', 'undefined'):
            if status not in summary:
                continue
            if first:
                label = statement_type
                if summary[status] != 1:
                    label += 's'
                part = '%d %s %s' % (summary[status], label, status)
                first = False
github django-behave / django-behave / django_behave / runner.py View on Github external
def runTest(self, result=None):
        # run behave on a single directory

        # from behave/__main__.py
        #stream = self.behave_config.output
        runner = Runner(self.behave_config)
        try:
            failed = runner.run()
        except ParserError, e:
            sys.exit(str(e))
        except ConfigError, e:
            sys.exit(str(e))

        if self.behave_config.show_snippets and runner.undefined:
            msg = u"\nYou can implement step definitions for undefined steps with "
            msg += u"these snippets:\n\n"
            printed = set()

            if sys.version_info[0] == 3:
                string_prefix = "('"
            else:
                string_prefix = u"(u'"

            for step in set(runner.undefined):
                if step in printed:
github behave / behave / behave / parser.py View on Github external
language = line[9:].strip()
                self.language = language
                self.keywords = i18n.languages[language]
            return

        func = getattr(self, "action_" + self.state, None)
        if func is None:
            line = line.strip()
            msg = u"Parser in unknown state %s;" % self.state
            raise ParserError(msg, self.line, self.filename, line)

        if not func(line):
            line = line.strip()
            msg = u'\nParser failure in state=%s' % self.state
            reason = self.ask_parse_failure_oracle(line)
            raise ParserError(msg, self.line, self.filename,
                              line_text=line, reason=reason)
github behave / behave / behave / parser.py View on Github external
def _build_background_statement(self, keyword, line):
        if self.tags:
            msg = u"Background supports no tags: @%s" % (u" @".join(self.tags))
            raise ParserError(msg, self.line, self.filename, line)
        elif self.scenario_container and self.scenario_container.background:
            if self.scenario_container.background.steps:
                # -- HINT: Rule may have default background w/o steps.
                msg = u"Second Background (can have only one)"
                raise ParserError(msg, self.line, self.filename, line)
        name = line[len(keyword) + 1:].strip()
        background = model.Background(self.filename, self.line, keyword, name)
        self.scenario_container.add_background(background)
        self.statement = background
github behave / behave / behave / parser.py View on Github external
self.multiline_start)
            if step.name.endswith(":"):
                step.name = step.name[:-1]
            self.lines = []
            self.multiline_terminator = None
            self.state = "steps"
            return True

        self.lines.append(line[self.multiline_leading:])
        # -- BETTER DIAGNOSTICS: May remove non-whitespace in execute_steps()
        removed_line_prefix = line[:self.multiline_leading]
        if removed_line_prefix.strip():
            message = u"BAD-INDENT in multiline text: "
            message += u"Line '%s' would strip leading '%s'" % \
                        (line, removed_line_prefix)
            raise ParserError(message, self.line, self.filename)
        return True
github behave / behave / behave / parser.py View on Github external
if self.state != "init" or self.tags or self.variant != "feature":
                return

            # -- DETECT: language comment (at begin of feature file; state=init)
            line = line.strip()[1:].strip()
            if line.lstrip().lower().startswith("language:"):
                language = line[9:].strip()
                self.language = language
                self.keywords = i18n.languages[language]
            return

        func = getattr(self, "action_" + self.state, None)
        if func is None:
            line = line.strip()
            msg = u"Parser in unknown state %s;" % self.state
            raise ParserError(msg, self.line, self.filename, line)

        if not func(line):
            line = line.strip()
            msg = u'\nParser failure in state=%s' % self.state
            reason = self.ask_parse_failure_oracle(line)
            raise ParserError(msg, self.line, self.filename,
                              line_text=line, reason=reason)
github behave / behave / behave / __main__.py View on Github external
if "help" in config.format:
        print_formatters("Available formatters:")
        return 0

    if len(config.outputs) > len(config.format):
        print("CONFIG-ERROR: More outfiles (%d) than formatters (%d)." % \
              (len(config.outputs), len(config.format)))
        return 1

    # -- MAIN PART:
    failed = True
    try:
        reset_runtime()
        runner = runner_class(config)
        failed = runner.run()
    except ParserError as e:
        print(u"ParserError: %s" % e)
    except ConfigError as e:
        print(u"ConfigError: %s" % e)
    except FileNotFoundError as e:
        print(u"FileNotFoundError: %s" % e)
    except InvalidFileLocationError as e:
        print(u"InvalidFileLocationError: %s" % e)
    except InvalidFilenameError as e:
        print(u"InvalidFilenameError: %s" % e)
    except ConstraintError as e:
        print(u"ConstraintError: %s" % e)
    except Exception as e:
        # -- DIAGNOSTICS:
        text = _text(e)
        print(u"Exception %s: %s" % (e.__class__.__name__, text))
        raise