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
api: addition of FormatChecker support #144
api: addition of FormatChecker support #144
Conversation
resolver = self.ref_resolver_cls.from_schema(schema) | ||
types = self.app.config.get('RECORDS_VALIDATION_TYPES', {}) | ||
|
||
return validate(data, schema, resolver=resolver, types=types, **kwargs) |
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.
Extracted two variables so that the call to validate
can fit in one line.
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 not:
return validate(
data,
schema,
resolver=self.ref_resolver_cls.from_schema(schema),
types=self.app.config.get('RECORDS_VALIDATION_TYPES', {}),
**kwargs
)
IMHO the readability is the same ...
Stopped the build because it would have clogged the queue for no good reason: https://travis-ci.org/inveniosoftware/invenio-records/jobs/147219213#L537. IMO in this case a |
>>> from jsonschema import FormatChecker | ||
>>> from jsonschema.validators import validate | ||
>>> checker = FormatChecker() | ||
>>> checker.checks('foo')(lambda el: el.startswith('foo')) |
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.
checker returns not None, hence you need to add <function <lambda> at ...>
on next line
Ooh, now I understand this error. Sorry, never used doctests before. |
https://github.com/inveniosoftware/invenio-records/blob/master/CONTRIBUTING.rst#get-started point 5. |
Some builds fail with: https://travis-ci.org/inveniosoftware/invenio-records/jobs/147414276#L468 This appears to be sphinx-doc/sphinx#2796, which will be fixed in Sphinx 1.4.6. |
@jacquerie check #143 for documentation fixes. |
Mh. This means that this PR has to wait for #143 to be merged, and then be rebased on top of that. Right? |
@jacquerie I have just merged #143. You can rebase now. |
* *format_checker* -- | ||
An instance of class :class:`jsonschema.FormatChecker`, which | ||
contains validation rules for formats. See | ||
:func:`~invenio_records.api.RecordBase.validate` for details. |
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.
This style of documenting kwargs is lifted from http://stackoverflow.com/a/27724915/374865.
@jacquerie which email do you use for git commits and signatures? Can you choose one and add it to |
* Makes the FormatChecker feature of jsonschema accessible by allowing arbitrary keyword arguments in calls to validate and create, which are passed to the underlying JSON schema implementation (closes #142). * Adds a reminder about this jsonschema feature in the documentation, and a complete example as a test. Signed-off-by: Jacopo Notarstefano <jacopo.notarstefano@cern.ch>
arbitrary keyword arguments in calls to validate and create, which
are passed to the underlying jsonschema implementation (closes api: make the FormatChecker feature of jsonschema accessible #142).
and a complete example as a test.
Signed-off-by: Jacopo Notarstefano jacopo.notarstefano@cern.ch