It sounds like you’re looking for “grammar-based fuzzing”, so perhaps take a look at Hypothesis
issue #170.
If you just need simple mathematical expressions then maybe the
from_regex() strategy might be useful:
@given(
expr=st.from_regex(r"^[0-9] [+-] [0-9] \* [xy] [+-] [xy]$"),
x=st.integers(min_value=0, max_value=20),
y=st.integers(min_value=0, max_value=20),
)
def bla(expr, x, y):
print(eval(expr))
You can get endlessly creative with your regex here.