Show More
@@ -53,6 +53,39 b' def isvalid(nbjson, ref=None, version=None):' | |||||
53 | return True |
|
53 | return True | |
54 |
|
54 | |||
55 |
|
55 | |||
|
56 | def better_validation_error(error, version): | |||
|
57 | """Get better ValidationError on oneOf failures | |||
|
58 | ||||
|
59 | oneOf errors aren't informative. | |||
|
60 | if it's a cell type or output_type error, | |||
|
61 | try validating directly based on the type for a better error message | |||
|
62 | """ | |||
|
63 | key = error.schema_path[-1] | |||
|
64 | if key.endswith('Of'): | |||
|
65 | ||||
|
66 | ref = None | |||
|
67 | if isinstance(error.instance, dict): | |||
|
68 | if 'cell_type' in error.instance: | |||
|
69 | ref = error.instance['cell_type'] + "_cell" | |||
|
70 | elif 'output_type' in error.instance: | |||
|
71 | ref = error.instance['output_type'] | |||
|
72 | ||||
|
73 | if ref: | |||
|
74 | try: | |||
|
75 | validate(error.instance, | |||
|
76 | ref, | |||
|
77 | version=version | |||
|
78 | ) | |||
|
79 | except ValidationError as e: | |||
|
80 | return better_validation_error(e, version) | |||
|
81 | except: | |||
|
82 | # if it fails for some reason, | |||
|
83 | # let the original error through | |||
|
84 | pass | |||
|
85 | ||||
|
86 | return error | |||
|
87 | ||||
|
88 | ||||
56 | def validate(nbjson, ref=None, version=None): |
|
89 | def validate(nbjson, ref=None, version=None): | |
57 | """Checks whether the given notebook JSON conforms to the current |
|
90 | """Checks whether the given notebook JSON conforms to the current | |
58 | notebook format schema. |
|
91 | notebook format schema. | |
@@ -65,8 +98,11 b' def validate(nbjson, ref=None, version=None):' | |||||
65 |
|
98 | |||
66 | validator = get_validator(version) |
|
99 | validator = get_validator(version) | |
67 |
|
100 | |||
68 |
|
|
101 | try: | |
69 | return validator.validate(nbjson, {'$ref' : '#/definitions/%s' % ref}) |
|
102 | if ref: | |
70 | else: |
|
103 | return validator.validate(nbjson, {'$ref' : '#/definitions/%s' % ref}) | |
71 | return validator.validate(nbjson) |
|
104 | else: | |
|
105 | return validator.validate(nbjson) | |||
|
106 | except ValidationError as e: | |||
|
107 | raise better_validation_error(e, version) | |||
72 |
|
108 |
General Comments 0
You need to be logged in to leave comments.
Login now