Strategy for interdependent attributes of a class

22 views
Skip to first unread message

Abulafia

unread,
Dec 19, 2022, 3:30:17 PM12/19/22
to Hypothesis users

Assume this simple case:

@dataclass
class A:
   names: list[str]
   ages: dict[str, float]

How could I write a strategy which generates objects of type A but with the restriction that the keys in the ages dict are taken from the list names (which are, in turn, randomly generated)?

Many thanks!

Zac Hatfield Dodds

unread,
Dec 22, 2022, 8:55:46 PM12/22/22
to Abulafia, Hypothesis users
Hi Abulafia,

I've answered this over on StackOverflow so that other users are more likely to benefit from the explanation: https://stackoverflow.com/q/74895414/

Best,
Zac

--
You received this message because you are subscribed to the Google Groups "Hypothesis users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hypothesis-use...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/hypothesis-users/020530c4-5857-4b05-861d-b5591b88fe4fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages