-
Notifications
You must be signed in to change notification settings - Fork 586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add initialization rules to RuleBasedStateMachine #1216
Comments
|
You can close #1214 as duplicate if you like. This would fill my feature request. |
|
The API I had imagined is below. Do you prefer yours? |
Yes, pretty strongly. I'd possibly be OK with an |
|
+1 to |
Hmm. You may have accidentally just argued against this feature, because there are two different interpretations here and we seem to have hit on different ones. Possible semantics of multiple initialization rules:
I had intended the latter and you seem to have inferred the former. This might be fine if we explicitly document it, but it might lead to some significant user confusion. |
|
So I might almost be tempted to lean a third way, and suggest So if you have different constructors, you push your rules into a mixin, and create variants of that mixin with different This is just spitballing, I’m not convinced this is actually a good idea. 🙃 |
|
FWIW I think the use-case of different constructors can be solved by just branching within the initialize method. So you can have something like: @initialize(data=st.data())
def setup(self, data):
if data.draw(st.booleans()):
self.thing = ...
else:
self.thing = ...So I'm not convinced that "What should we do about multiple constructors?" is an interesting question for shaping the design of this. I don't have a problem with allowing at most one |
I think I agree. Most classes I write don’t have multiple constructors, and of the ones that do, most of them have a “primary” constructor, and others that just tidy up the inputs (e.g. taking a |
I mean in Python no classes have multiple constructors. The only real way to get something like that is to have multiple subclasses. |
|
Or classmethods! I meant "you can define multiple methods with Take Pandas dataframes for example; they have an |
A common usage pattern in RuleBasedStateMachine is that you have a a single mutable data structure instance that is shared across the whole test.
This is currently only well supported if you can just straightforwardly initialize that data structure without relying on Hypothesis provided data and do that in
__init__.If you need Hypothesis to provide the data, currently the best emulation is something like the following:
(disclaimer: I wrote that from memory without running it).
This is obviously quite awkward! You have to add preconditions to each rule.
It would be nice if we could instead write:
Suggested semantics/implementation:
state_machine_initmethod or something like that toGenericStateMachineas the relevant hook.state_machine_initis called with ast.data()strategy before the firstcheck_invariantscallRuleBasedStateMachineimplementsstate_machine_initto run each@initializedecorated method exactly once in an arbitrary order (possibly an explicitly randomised order usingpermutations? That way people won't depend on the order).The text was updated successfully, but these errors were encountered: