How to use the spidermon.exceptions.InvalidExpression function in spidermon

To help you get started, we’ve selected a few spidermon 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 scrapinghub / spidermon / _tests / rules / test_rules.py View on Github external
def test_python_rule():
    with pytest.raises(SyntaxError):
        for exp in SYNTAXERROR_EXPRESSIONS:
            PythonExpressionRule(exp)

    with pytest.raises(InvalidExpression):
        for exp in INVALID_EXPRESSIONS:
            PythonExpressionRule(exp)

    for exp in VALID_EXPRESSIONS:
        PythonExpressionRule(exp)

    rule = PythonExpressionRule(RULE_EXPRESSION)
    _test_rule_with_stats(rule)

    for expression, result in EXPRESSIONS_TO_EVALUATE:
        rule = PythonExpressionRule(expression)
        assert result == rule.run_check(STATS_TO_EVALUATE), \
            'Expression fails: "%s" != %s' % (expression, result)
github scrapinghub / spidermon / spidermon / python / interpreter.py View on Github external
def _raise_not_allowed_node(self, node):
        raise InvalidExpression(
            "'%s' definition not allowed in python expressions"
            % node.__class__.__name__
        )
github scrapinghub / spidermon / spidermon / python / interpreter.py View on Github external
def check(self, expression):
        if not isinstance(expression, six.string_types):
            raise InvalidExpression("Python expressions must be defined as strings")
        if not expression:
            raise InvalidExpression("Empty python expression")

        try:
            tree = ast.parse(expression)
        except SyntaxError as e:
            raise e

        if not tree.body:
            raise InvalidExpression("Empty python expression")
        elif len(tree.body) > 1:
            raise InvalidExpression(
                "Python expressions must be a single line expression"
            )

        start_node = tree.body[0]
        if not isinstance(start_node, ast.Expr):
            raise InvalidExpression(
                "Python string must be an expression: '%s' found"
                % start_node.__class__.__name__
            )

        self._check_node(start_node)
github scrapinghub / spidermon / spidermon / python / interpreter.py View on Github external
def check(self, expression):
        if not isinstance(expression, six.string_types):
            raise InvalidExpression("Python expressions must be defined as strings")
        if not expression:
            raise InvalidExpression("Empty python expression")

        try:
            tree = ast.parse(expression)
        except SyntaxError as e:
            raise e

        if not tree.body:
            raise InvalidExpression("Empty python expression")
        elif len(tree.body) > 1:
            raise InvalidExpression(
                "Python expressions must be a single line expression"
            )

        start_node = tree.body[0]
        if not isinstance(start_node, ast.Expr):
            raise InvalidExpression(
github scrapinghub / spidermon / spidermon / python / interpreter.py View on Github external
try:
            tree = ast.parse(expression)
        except SyntaxError as e:
            raise e

        if not tree.body:
            raise InvalidExpression("Empty python expression")
        elif len(tree.body) > 1:
            raise InvalidExpression(
                "Python expressions must be a single line expression"
            )

        start_node = tree.body[0]
        if not isinstance(start_node, ast.Expr):
            raise InvalidExpression(
                "Python string must be an expression: '%s' found"
                % start_node.__class__.__name__
            )

        self._check_node(start_node)
github scrapinghub / spidermon / spidermon / python / interpreter.py View on Github external
def check(self, expression):
        if not isinstance(expression, six.string_types):
            raise InvalidExpression("Python expressions must be defined as strings")
        if not expression:
            raise InvalidExpression("Empty python expression")

        try:
            tree = ast.parse(expression)
        except SyntaxError as e:
            raise e

        if not tree.body:
            raise InvalidExpression("Empty python expression")
        elif len(tree.body) > 1:
            raise InvalidExpression(
                "Python expressions must be a single line expression"
            )

        start_node = tree.body[0]
github scrapinghub / spidermon / spidermon / python / interpreter.py View on Github external
def check(self, expression):
        if not isinstance(expression, six.string_types):
            raise InvalidExpression("Python expressions must be defined as strings")
        if not expression:
            raise InvalidExpression("Empty python expression")

        try:
            tree = ast.parse(expression)
        except SyntaxError as e:
            raise e

        if not tree.body:
            raise InvalidExpression("Empty python expression")
        elif len(tree.body) > 1:
            raise InvalidExpression(
                "Python expressions must be a single line expression"
            )

        start_node = tree.body[0]
        if not isinstance(start_node, ast.Expr):
            raise InvalidExpression(
                "Python string must be an expression: '%s' found"
                % start_node.__class__.__name__
            )

        self._check_node(start_node)