test(pyargus): better test for expr_gen
This commit is contained in:
parent
c68620dfdd
commit
f8e570756c
3 changed files with 11 additions and 11 deletions
2
.github/workflows/ci.yaml
vendored
2
.github/workflows/ci.yaml
vendored
|
|
@ -83,8 +83,6 @@ jobs:
|
||||||
flake8
|
flake8
|
||||||
ruff check .
|
ruff check .
|
||||||
mypy .
|
mypy .
|
||||||
- name: Python Tests
|
|
||||||
run: pytest pyargus
|
|
||||||
|
|
||||||
docs:
|
docs:
|
||||||
name: Documentation
|
name: Documentation
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,9 @@ class Transformer(lark.Transformer):
|
||||||
def INT(self, tok: lark.Token) -> lark.Token: # noqa: N802
|
def INT(self, tok: lark.Token) -> lark.Token: # noqa: N802
|
||||||
"""Convert the value of `tok` from string to int, while maintaining line number & column.
|
"""Convert the value of `tok` from string to int, while maintaining line number & column.
|
||||||
|
|
||||||
Performs wrapping conversion for 64-bit integers
|
Performs wrapping conversion for 32-bit integers
|
||||||
"""
|
"""
|
||||||
return tok.update(value=int(tok) // 2**64)
|
return tok.update(value=int(float(tok) // 2**32))
|
||||||
|
|
||||||
|
|
||||||
ARGUS_EXPR_GRAMMAR = lark.Lark(
|
ARGUS_EXPR_GRAMMAR = lark.Lark(
|
||||||
|
|
@ -21,14 +21,15 @@ ARGUS_EXPR_GRAMMAR = lark.Lark(
|
||||||
TRUE: "true" | "TRUE"
|
TRUE: "true" | "TRUE"
|
||||||
FALSE: "false" | "FALSE"
|
FALSE: "false" | "FALSE"
|
||||||
BOOLEAN: TRUE | FALSE
|
BOOLEAN: TRUE | FALSE
|
||||||
|
INT: /[0-9]+/
|
||||||
|
|
||||||
KEYWORD: "X" | "G" | "F" | "U" | BOOLEAN
|
KEYWORD: "X" | "G" | "F" | "U" | BOOLEAN
|
||||||
|
|
||||||
ESCAPED_STRING: "\"" /(\w|[\t ]){1,20}/ "\""
|
ESCAPED_STRING: /(\w|[\t ]){1,20}/
|
||||||
NUM_IDENT: ESCAPED_STRING
|
NUM_IDENT: "\"num_" ESCAPED_STRING "\""
|
||||||
| "num_" CNAME
|
| "num_" CNAME
|
||||||
BOOL_IDENT: ESCAPED_STRING
|
BOOL_IDENT: "\"bool_" ESCAPED_STRING "\""
|
||||||
| "bool_" CNAME
|
| "bool_" CNAME
|
||||||
|
|
||||||
num_expr: num_expr "*" num_expr
|
num_expr: num_expr "*" num_expr
|
||||||
| num_expr "/" num_expr
|
| num_expr "/" num_expr
|
||||||
|
|
@ -66,7 +67,6 @@ phi: bool_expr
|
||||||
|
|
||||||
%import common.CNAME
|
%import common.CNAME
|
||||||
%import common.NUMBER
|
%import common.NUMBER
|
||||||
%import common.INT
|
|
||||||
%import common.WS
|
%import common.WS
|
||||||
%import common.WS_INLINE
|
%import common.WS_INLINE
|
||||||
%ignore WS
|
%ignore WS
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,16 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import hypothesis.strategies as st
|
||||||
from hypothesis import HealthCheck, given, settings
|
from hypothesis import HealthCheck, given, settings
|
||||||
|
|
||||||
import argus
|
import argus
|
||||||
from argus.test_utils.expr_gen import argus_expr
|
from argus.test_utils.expr_gen import argus_expr
|
||||||
|
|
||||||
|
|
||||||
@given(spec=argus_expr())
|
@given(data=st.data())
|
||||||
@settings(suppress_health_check=[HealthCheck.too_slow])
|
@settings(suppress_health_check=[HealthCheck.too_slow])
|
||||||
def test_correct_expr(spec: str) -> None:
|
def test_correct_expr(data: st.DataObject) -> None:
|
||||||
|
spec = data.draw(argus_expr())
|
||||||
try:
|
try:
|
||||||
_ = argus.parse_expr(spec)
|
_ = argus.parse_expr(spec)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue