Skip to content
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

Validator overhaul #417

Merged
merged 3 commits into from Sep 11, 2020
Merged

Validator overhaul #417

merged 3 commits into from Sep 11, 2020

Conversation

ml-evs
Copy link
Member

@ml-evs ml-evs commented Jul 20, 2020

This PR updates the way we do validation. Instead of applying an arbitrary list of filter examples from the spec (which provide useless results), this PR adds the following:

  • Get the list of supported properties (and if available, their types) from the implementations /info endpoint
  • Compare that list to (currently) hardcoded values for the fields that "SHOULD", "MUST" and are "OPTIONALLY" supported for each endpoint (eventually we will get these from our schema models directly, see Add classes to operate on model schemas directly #277)
  • For each endpoint, grab a random entry (say {"int_field": 1, "string_field": "foo"}), then:
    • for each property, test the values of that particular entry according to the type of the field for all appropriate operators, e.g. int_field = 1, int_field >= 1 and so on, making sure that the results are all consistent (i.e. int_field = 1 returns at most as many results as int_field >= 1).
    • if the property has no reported type, do not perform any query checks
    • if the property is an OPTIMADE "MUST", then error if any check fails.
    • if the property is a "SHOULD" or an "OPTIONAL", then emit an optional test failure.
    • in the case of a string or numeric comparison, also try reversing the order of the identifier and value (e.g. id =1 and 1 = id must return the same results).

This PR also introduces some extra changes:

There are still many things missing from this PR, but I think its at a useful stage (and will require some effort to review...):

Still missing:

  • Query tests on dictionary and timestamp field types (we don't actually have timestamps implemented anyway)
  • Query combination with AND and OR
  • Query negation with NOT
  • Queries with optional operators like HAS ONLY
  • Queries on relationships
  • Queries with KNOWN and UNKNOWN
  • Queries that test operator precedence...
  • Queries that test query parameters, e.g. api_hint and sorting
  • JSON responses to be used in the providers dashboard
  • Test that unknown fields return a 501

@CasperWA
Copy link
Member

Yay! This PR is all I've ever dreamed of... 🤩

@codecov
Copy link

codecov bot commented Jul 20, 2020

Codecov Report

Merging #417 into master will decrease coverage by 0.18%.
The diff coverage is 89.47%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #417      +/-   ##
==========================================
- Coverage   91.66%   91.48%   -0.19%     
==========================================
  Files          60       61       +1     
  Lines        2856     3065     +209     
==========================================
+ Hits         2618     2804     +186     
- Misses        238      261      +23     
Flag Coverage Δ
#project 91.48% <89.47%> (?)
#unittests ?
#validator 63.29% <74.14%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
optimade/validator/__init__.py 9.37% <0.00%> (ø)
optimade/validator/validator.py 82.18% <88.57%> (+5.08%) ⬆️
optimade/validator/utils.py 90.15% <90.15%> (ø)
optimade/validator/config.py 100.00% <100.00%> (ø)
optimade/validator/data/__init__.py 0.00% <0.00%> (-100.00%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 21e3ab7...060da80. Read the comment docs.

@ml-evs
Copy link
Member Author

ml-evs commented Jul 20, 2020

Yay! This PR is all I've ever dreamed of... star_struck

Give it a while... having to unpick my code from a couple of weeks ago from the other PRs we've merged recently.

@ml-evs ml-evs changed the title [WIP] validator overhaul Validator overhaul Sep 3, 2020
@ml-evs ml-evs marked this pull request as ready for review September 3, 2020 13:14
Copy link
Member

@CasperWA CasperWA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some very few comments.

There are a lot of new stuff (it seems to me) in the validator, which is absolutely awesome!
But maybe we can have a live walkthrough at some point, perhaps via Zoom or some such?

optimade/validator/validator.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
@ml-evs
Copy link
Member Author

ml-evs commented Sep 3, 2020

Some very few comments.

There are a lot of new stuff (it seems to me) in the validator, which is absolutely awesome!
But maybe we can have a live walkthrough at some point, perhaps via Zoom or some such?

Yeah, I'm happy to. I think at the very least I need to write a fat module docstring and some notes on how to extend it...

Copy link
Member

@CasperWA CasperWA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking very clean now, great work @ml-evs !

From the new fancy in-line codecov warnings, it seems there are a lot of code-blocks that are not being checked in the test_case function, i.e., we should probably have a static test file that represents a response with some errors?

Also, there are a lot of stuff in the validator file. I have tried to pick out some nit-picky stuff (like the doc-strings, type-info, etc.), which should be applied in a more broader sense throughout the file.
Furthermore, I am unsure whether I have actually found all I wanted.

I think it's a good idea to check which lines are not covered in the coverage tests and attempt to add some mock-responses, e.g., static files that should test these various lines?

optimade/validator/config.py Show resolved Hide resolved
optimade/validator/utils.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
optimade/validator/utils.py Outdated Show resolved Hide resolved
optimade/validator/utils.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
@ml-evs ml-evs requested a review from CasperWA September 9, 2020 18:04
Copy link
Member

@CasperWA CasperWA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some doc strings for the tests.

tests/validator/test_utils.py Outdated Show resolved Hide resolved
tests/validator/test_utils.py Outdated Show resolved Hide resolved
tests/validator/test_utils.py Outdated Show resolved Hide resolved
tests/validator/test_utils.py Outdated Show resolved Hide resolved
tests/validator/test_utils.py Outdated Show resolved Hide resolved
tests/validator/test_utils.py Outdated Show resolved Hide resolved
tests/validator/test_utils.py Outdated Show resolved Hide resolved
tests/validator/test_utils.py Outdated Show resolved Hide resolved
Copy link
Member

@CasperWA CasperWA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lot's of nitpicking here - mainly doc strings and such.

After this has been addressed, I'd say this should be merged.

Again, great job here @ml-evs !

optimade/validator/validator.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Show resolved Hide resolved
optimade/validator/validator.py Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
@ml-evs
Copy link
Member Author

ml-evs commented Sep 10, 2020

I think that's all your docstring changes now @CasperWA, plus the SystemExit stuff in 60772e5 that I mentioned, and the changes to make most of the ImplementationValidator private. Once you're happy, I'll do a final rebase that squashes the last few commits and leaves us with about 15 to rebase merge into master?

Copy link
Member

@CasperWA CasperWA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last change I just spotted.
After that I'll approve and you can merge.

If you wish to convert this PR to several commits, instead of a single, I think that's fair enough. E.g., one for the move separately and then the updates?

tests/validator/test_utils.py Outdated Show resolved Hide resolved
CasperWA
CasperWA previously approved these changes Sep 11, 2020
- Split validator into validator and utils submodules
- Add validator specific-coverage report
- Disable parsing filter examples from specification for validation
- Removed `optimade.validator.data` submodule
- Removed corresponding invoke task
- Removed tests from validator
- Minor tweaks, function renames and update docs
- Added dynamic filters of every field based on type reported in entry info
- Add another test client that fakes HTTP exceptions
- Created optimade.validator.config module
- Updates to @test_case decorator, and test for MUST fields in entry info
- Added test to check that all MUST properties are present in entry info
- Allow test cases to return None to indicate that the test should be
  ignored. The use case here is e.g. if an optional field is missing,
  then we don't care and the test can be ignored
- Added `multistage` option to `@test_case` that suppresses output and counters of success on multistage tests
- Added hard filter to running optional tests in @test_case itself
- Made deserialization of multi-entry endpoints optional
- Test bad version responds with 553 (closes #427)
- Add validation of versions endpoint (closes #491)
- Add test for matching data_available and data_returned (closes #402)
- Improved module docstrings
- Fixed hardcoded endpoint in logging
- Updated base info error message
- Removed extraneous base info attribute
- Tweaked endpoint variables and added missing logging
- Make wider use of config values in error messages
- Tidied some function docstrings
- Remove argument from test_versions
- Added middle ground verbosity
- Better handling of fatal errors (SystemExit) in the test_case decorator
- Standardization of test_case API
    - Unify test_case decorator and wrapped method API by returning string summary in both cases
    - Updated all type hints and docstrings
    - Slightly refactored test_case decorator for clearer exception handling
- Add validator.utils tests for @test_case decorator
- Remove "Keyword arguments" from docstrings
- Made many validator methods/attributes private
Copy link
Member

@CasperWA CasperWA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job with this @ml-evs !

@ml-evs
Copy link
Member Author

ml-evs commented Sep 11, 2020

Great job with this @ml-evs !

Always improved by your reviews 👍

@ml-evs ml-evs merged commit d53ab89 into Materials-Consortia:master Sep 11, 2020
@ml-evs ml-evs deleted the ml-evs/validator_overhaul branch September 11, 2020 13:03
@ml-evs ml-evs mentioned this pull request Sep 11, 2020
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants