Coverage for tests/common.py: 100%
18 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-04 15:55 +0100
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-04 15:55 +0100
1"""Commonly used utilities among the test modules."""
3import string
5import hypothesis.strategies as st
7from certus.nodes import Token
9ST_STRINGS = st.text(string.ascii_letters + string.digits + " _-", min_size=1, max_size=5).filter(
10 lambda t: not t.isspace()
11)
12ST_LOGPROBS = st.floats(-10, 0)
13ST_STARTS = st.integers(0, 100)
16@st.composite
17def st_tokens(
18 draw: st.DrawFn,
19 value_strategy: st.SearchStrategy = ST_STRINGS,
20 logprob_strategy: st.SearchStrategy = ST_LOGPROBS,
21 start_strategy: st.SearchStrategy = ST_STARTS,
22) -> Token:
23 """Create a token for a test."""
24 return draw(
25 st.builds(Token, value=value_strategy, logprob=logprob_strategy, start=start_strategy)
26 )
29@st.composite
30def st_token_lists(draw: st.DrawFn, min_size: int = 1, max_size: int = 5) -> list[Token]:
31 """Create a list of tokens for a test."""
32 num = draw(st.integers(min_size, max_size))
33 tokens, position = [], draw(ST_STARTS)
34 for _ in range(num):
35 token = draw(st_tokens(start_strategy=st.just(position)))
36 position += len(token.value)
37 tokens.append(token)
39 return tokens