-
Notifications
You must be signed in to change notification settings - Fork 8
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
A hypothesis test which loads object template from json file and create hypothesis object #44
Conversation
a5da70b
to
5b600f2
Compare
amostra/schemas/container.json
Outdated
"required": [ | ||
"uuid", | ||
"revision", | ||
"name" | ||
"name", | ||
"kind", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this testing PR have to change what is required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In code here, both kind and content needed.
https://github.com/NSLS-II/amostra/blob/master/amostra/objects.py#L175
In design,
contents needed make sense, not sure about kind
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn't have really strong connection with this PR. I updated them to make fake container works(has kind and contents).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, then let's leave the schema as is. Schema changes should be motivated by user needs, not testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why you marked this as "resolved".
amostra/tests/test_jsonschema.py
Outdated
container_dict = load_schema("container.json") | ||
container_dict['properties'].pop('uuid') | ||
container_dict['properties'].pop('revision') | ||
container_dict['required'] = ['name', 'kind', 'contents'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comments as above... it would be good if the only change we had to make here was popping the read-only keys, uuid
and revision
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same reason here. https://github.com/NSLS-II/amostra/pull/44/files#r319613117
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think changing the schema before testing cuts against the spirit of how to use hypothesis. We have to dispense with uuid
and required
become of how our API works, but it would be better not to mutate anything else about the schema.
37e9a14
to
0970840
Compare
The error was observed when try to init a
The reason isn't clear yet. I suspect it come from |
Interesting. I think it would be good to understand the cause before merging. Can you start with something minimal like: class Thing(amostra.objects.AmostraDocument):
stuff = traitlets.List(traitlets.Unicode()) |
I'll try. Do you have clue/direction why |
After some search online, I feel typical way to use
Also in traitlets examples here, looks
|
amostra/objects.py
Outdated
cls._validate = validate(*trait_names)(_validate_with_jsonschema) | ||
return super().__new__(cls, *args, **kwargs) | ||
instance = super().__new__(cls, *args, **kwargs) | ||
instance._validate = validate(*trait_names)(_validate_with_jsonschema) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think think that this change makes the validation not happen at al! The validate
method produces a descriptor which needs to be in place for the super().__new__(...)
to find them and do something about it.
Are there any tests we we are sure that we do reject invalid documents?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think @tacaswell is right. It would be good to add a test that uses pytest.raises
to ensure that validation is running and correctly raising an error on invalid inputs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you that validation wasn't triggered.
is enough to trigger the recursion. I suspect this is due to Given that we have already made 'name' special via the signature, I think we should enforce that it is not the empty sttring in the |
I suspect this need to be fixed? short words about why recursion |
Maybe I should do thing below instead of every place using
|
Great, using the lock inside |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I re-opened an old, unresolved comment and left one optional implementation suggestion.
2fb89fe
to
0be3b5b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks for your persistence.
Hypothesis object created by this process based on
container.json
will look likeThis also could be a beginning point for who want to try using hypothesis test/package later.