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 part 2 #421

Merged
merged 28 commits into from
Oct 14, 2019
Merged

Validator part 2 #421

merged 28 commits into from
Oct 14, 2019

Conversation

achilleas-k
Copy link
Member

Did a bit of a cleanup and rewrite of the validator.

  • The format of the results is a nested dictionary of the form
results = {
    "errors": {
        nixobject: ["list of errors"]
    },
    "warnings": {
        nixobject: ["list of warnings"]
    }
}
  • The validator doesn't throw any exceptions (like it did before), but it doesn't catch any read exceptions either. I plan on adding this later so we can validate, for instance, a Block that's missing an ID. Currently, the library throws an exception if an ID is missing.
  • Error and warning strings are used from two static classes. This puts the strings in a single location, so they're easier to change and test.
  • Tests for every error and warning that doesn't break reading.

In a followup PR, I'll add a script so that the validator can be run from the command line.

- Renamed validate.py to validator.py
- Validator module will simply be a collection of functions and not a
class to instantiate with a file.  There's no need to have an object.
Return the new style of results, which is a dictionary with two
sub-dictionaries, one for errors and one for warnings.
Instead of returning a dictionary, each validation function (except
check_file) returns a list of errors and a list of warnings for the
provided object.  None of the functions check objects recursively, but
it may be necessary for Dimensions and Features.
- Some conditionals were flipped
- Empty string units in tags should be allowed
New helper function for checking Tag (and MultiTag) units against all
the units in referenced DataArrays.  Allows for the special case where
both the Tag unit and the corresponding reference unit are empty
strings.
Create fully valid file in test setUp() and create one error or warning
per test.
Mostly the same as Tags, with differences in positions and extents
checks.
Disable failing tests until they are rewritten
Can't test for the error now since the time can't be parsed by the lib.
@lgtm-com
Copy link

lgtm-com bot commented Oct 12, 2019

This pull request introduces 5 alerts when merging 7b3c338 into d493d01 - view on LGTM.com

new alerts:

  • 3 for Module-level cyclic import
  • 2 for Unused import

@lgtm-com
Copy link

lgtm-com bot commented Oct 12, 2019

This pull request introduces 3 alerts and fixes 3 when merging 307dccd into d493d01 - view on LGTM.com

new alerts:

  • 3 for Module-level cyclic import

fixed alerts:

  • 3 for Module-level cyclic import

@lgtm-com
Copy link

lgtm-com bot commented Oct 12, 2019

This pull request introduces 3 alerts and fixes 3 when merging 305d795 into d493d01 - view on LGTM.com

new alerts:

  • 3 for Module-level cyclic import

fixed alerts:

  • 3 for Module-level cyclic import

@jgrewe
Copy link
Member

jgrewe commented Oct 13, 2019

looks like we are caught in cycle here :)

jgrewe
jgrewe previously approved these changes Oct 13, 2019
Copy link
Member

@jgrewe jgrewe left a comment

Choose a reason for hiding this comment

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

Very nice work, the static classes make it super clear, imho

nixio/validator.py Outdated Show resolved Hide resolved
@achilleas-k
Copy link
Member Author

achilleas-k commented Oct 13, 2019

I don't think the detected import cycles are real cycles. Pycycle doesn't seem to think so. I guess the issue detected is that File imports validator which imports dimensions and dimensions haven't been imported by __init__.py yet.

EDIT: We could also drop the dimension type validation check since it's not really meaningful. The library initialises the Dimension object based on the dimension_type attribute when reading, so it's not like they can differ.

@lgtm-com
Copy link

lgtm-com bot commented Oct 13, 2019

This pull request introduces 3 alerts and fixes 3 when merging 5ed05de into d493d01 - view on LGTM.com

new alerts:

  • 3 for Module-level cyclic import

fixed alerts:

  • 3 for Module-level cyclic import

@jgrewe
Copy link
Member

jgrewe commented Oct 13, 2019

I don't think the detected import cycles are real cycles. Pycycle doesn't seem to think so. I guess the issue detected is that File imports validator which imports dimensions and dimensions haven't been imported by __init__.py yet.

EDIT: We could also drop the dimension type validation check since it's not really meaningful. The library initialises the Dimension object based on the dimension_type attribute when reading, so it's not like they can differ.

Could the dimension type be invalid? Not when the file was created via the library at least. I vote for skipping the check.

@achilleas-k
Copy link
Member Author

Could the dimension type be invalid? Not when the file was created via the library at least. I vote for skipping the check.

It's the same as with other kinds of invalid states (like not having an ID). The instantiation of the object will throw an exception, so there's way to have a Dimension object that's has an invalid dimtype. I'll include it in the next version that will be able to catch exceptions and report them as errors.

The library initialises the Dimension object based on the dimension_type
attribute when reading, so it's impossible for them to differ without
the library throwing an exception on load.
@lgtm-com
Copy link

lgtm-com bot commented Oct 13, 2019

This pull request fixes 3 alerts when merging a7fd01c into d493d01 - view on LGTM.com

fixed alerts:

  • 3 for Module-level cyclic import

@jgrewe jgrewe merged commit ac0d807 into G-Node:master Oct 14, 2019
@achilleas-k achilleas-k deleted the validator-part-2 branch October 14, 2019 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants