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

api: addition of FormatChecker support #144

Merged
merged 1 commit into from Jul 27, 2016
Merged

api: addition of FormatChecker support #144

merged 1 commit into from Jul 27, 2016

Conversation

jacquerie
Copy link
Contributor

  • Makes the FormatChecker feature of jsonschema accessible by allowing
    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).
  • 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

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)
Copy link
Contributor Author

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.

Copy link
Member

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 ...

@jacquerie
Copy link
Contributor Author

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 lambda is acceptable, so I'd rather suppress this warning rather than defining the function. WDYT?

>>> from jsonschema import FormatChecker
>>> from jsonschema.validators import validate
>>> checker = FormatChecker()
>>> checker.checks('foo')(lambda el: el.startswith('foo'))
Copy link
Member

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

@jacquerie
Copy link
Contributor Author

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 lambda is acceptable, so I'd rather suppress this warning rather than defining the function. WDYT?

Ooh, now I understand this error. Sorry, never used doctests before.

@jirikuncar
Copy link
Member

Sorry, never used doctests before.

https://github.com/inveniosoftware/invenio-records/blob/master/CONTRIBUTING.rst#get-started point 5. $./run-tests.sh 😉

@jacquerie
Copy link
Contributor Author

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.

@jirikuncar
Copy link
Member

@jacquerie check #143 for documentation fixes.

@jacquerie
Copy link
Contributor Author

@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?

@jirikuncar
Copy link
Member

@jacquerie I have just merged #143. You can rebase now.

@jirikuncar jirikuncar added this to the v1.0.0 milestone Jul 26, 2016
@jirikuncar jirikuncar self-assigned this Jul 26, 2016
* *format_checker* --
An instance of class :class:`jsonschema.FormatChecker`, which
contains validation rules for formats. See
:func:`~invenio_records.api.RecordBase.validate` for details.
Copy link
Contributor Author

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.

@jirikuncar
Copy link
Member

@jacquerie which email do you use for git commits and signatures? Can you choose one and add it to AUTHORS.rst? Thanks

* 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>
@jirikuncar jirikuncar merged commit 7dbbbc9 into inveniosoftware:master Jul 27, 2016
@jacquerie jacquerie deleted the add-support-for-formatchecker branch July 27, 2016 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

api: make the FormatChecker feature of jsonschema accessible
2 participants