From 74b8a0e537e52d1d23b3edf6f81ae293f6e577ee 2014-04-22 00:32:59 From: Jessica B. Hamrick Date: 2014-04-22 00:32:59 Subject: [PATCH] Return the list of errors, rather than the number of errors --- diff --git a/IPython/nbformat/current.py b/IPython/nbformat/current.py index 432704f..09870f1 100644 --- a/IPython/nbformat/current.py +++ b/IPython/nbformat/current.py @@ -86,11 +86,11 @@ def reads_json(nbjson, **kwargs): """ nb = reader_reads(nbjson, **kwargs) nb_current = convert(nb, current_nbformat) - num_errors = validate(nb_current) - if num_errors > 0: + errors = validate(nb_current) + if len(errors) > 0: logger.error( "Notebook JSON is invalid (%d errors detected during read)", - num_errors) + len(errors)) return nb_current @@ -99,11 +99,11 @@ def writes_json(nb, **kwargs): any JSON format errors are detected. """ - num_errors = validate(nb) - if num_errors > 0: + errors = validate(nb) + if len(errors) > 0: logger.error( "Notebook JSON is invalid (%d errors detected during write)", - num_errors) + len(errors)) nbjson = versions[current_nbformat].writes_json(nb, **kwargs) return nbjson diff --git a/IPython/nbformat/validator.py b/IPython/nbformat/validator.py index 5ce58ac..e937142 100644 --- a/IPython/nbformat/validator.py +++ b/IPython/nbformat/validator.py @@ -12,24 +12,23 @@ schema_path = os.path.join( os.path.dirname(__file__), "v%d" % nbformat, nbformat_schema) -def isvalid(nbjson, verbose=False): +def isvalid(nbjson): """Checks whether the given notebook JSON conforms to the current notebook format schema. Returns True if the JSON is valid, and False otherwise. - If `verbose` is set, then print out each error that is detected. + To see the individual errors that were encountered, please use the + `validate` function instead. """ - errors = validate(nbjson, verbose=verbose) + errors = validate(nbjson) return errors == 0 -def validate(nbjson, verbose=False): +def validate(nbjson): """Checks whether the given notebook JSON conforms to the current - notebook format schema, and returns the number of errors. - - If `verbose` is set, then print out each error that is detected. + notebook format schema, and returns the list of errors. """ @@ -42,13 +41,8 @@ def validate(nbjson, verbose=False): v3schema = jsonpointer.resolve_pointer(v3schema, '/notebook') # count how many errors there are - errors = 0 v = Draft3Validator(v3schema) - for error in v.iter_errors(nbjson): - errors = errors + 1 - if verbose: - print(error) - + errors = [e for e in v.iter_errors(nbjson)] return errors