Skip to content

Commit

Permalink
fixed validation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wshayes committed Oct 29, 2020
1 parent ff107e3 commit 99bce14
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions bel/lang/ast.py
Expand Up @@ -1340,6 +1340,18 @@ def validate_function(fn: Function, errors: List[ValidationError] = None) -> Lis
index=fn.args[position].span.start,
)
)
# Sixth pass - non-positional StrArgs are errors
for idx, arg in enumerate(fn.args):
if arg.type == "StrArg" and signature["arguments"][idx]["position"] is None:
errors.append(
ValidationError(
type="Assertion",
severity="Error",
msg="String argument not allowed as an optional or multiple argument. Probably missing a namespace.",
visual_pairs=[(arg.span.start, arg.span.end)],
index=arg.span.start,
)
)

# Check for obsolete namespaces
for arg in fn.args:
Expand Down
14 changes: 14 additions & 0 deletions tests/lang/test_ast.py
Expand Up @@ -194,6 +194,20 @@ def test_validate_missing_namespace():
assert ast.errors[0].severity == "Warning"


def test_validate_strarg():

assertion = AssertionStr(subject='complex("missing")')
expected = ""

ast = bel.lang.ast.BELAst(assertion=assertion)

ast.validate()

print("Errors", ast.errors)

assert ast.errors[0].msg == expected


def test_validate_empty_function():
"""Validate empty function"""

Expand Down

0 comments on commit 99bce14

Please sign in to comment.