Skip to content

Commit

Permalink
validate_merge_properties warns if merge properties are set to false …
Browse files Browse the repository at this point in the history
…or null
  • Loading branch information
jpmckinney committed Mar 18, 2020
1 parent 9d2b535 commit 8165f2a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Added

- :meth:`jscc.schema.extend_schema`
- :meth:`jscc.testing.checks.get_invalid_csv_files`
- :meth:`jscc.testing.checks.validate_merge_properties` warns if merge properties are set to ``false`` or ``null``.
- Expand docstrings for ``jscc.schema.checks.validate_*`` methods.

Changed
Expand All @@ -20,7 +21,7 @@ Changed
- :meth:`jscc.testing.filesystem.walk_csv_data` returns text content, fieldnames, and rows, instead of a CSV reader.
- ``jscc.testing.schema`` is moved to :mod:`jscc.schema`.
- ``jscc.schema.is_property_missing`` is renamed to :meth:`jscc.schema.is_missing_property`.
- ``should_be_nullable`` argument to :meth:`jscc.testing.checks.validate_null_type` is renamed to ``expect_null``.
- :meth:`jscc.testing.checks.validate_null_type`'s ``should_be_nullable`` argument is renamed to ``expect_null``.
- Clarify warning messages.

0.0.1 (2020-03-15)
Expand Down
11 changes: 5 additions & 6 deletions jscc/testing/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,14 +604,13 @@ def validate_merge_properties(*args):
def block(path, data, pointer):
errors = 0

if data.get('omitWhenMerged') is False:
if 'omitWhenMerged' in data and not data['omitWhenMerged']:
errors += 1
warn('{} sets "omitWhenMerged" to false at {}'.format(path, pointer), MergePropertiesWarning)
if data.get('wholeListMerge') is False:
warn('{} sets "omitWhenMerged" to false or null at {}'.format(path, pointer), MergePropertiesWarning)
if 'wholeListMerge' in data and not data['wholeListMerge']:
errors += 1
warn('{} sets "wholeListMerge" to false at {}'.format(path, pointer), MergePropertiesWarning)

if 'wholeListMerge' in data:
warn('{} sets "wholeListMerge" to false or null at {}'.format(path, pointer), MergePropertiesWarning)
elif 'wholeListMerge' in data:
if not is_array_of_objects(data):
errors += 1
warn('{} sets "wholeListMerge", though the field is not an array of objects, at {}'.format(path, pointer), MergePropertiesWarning) # noqa: E501
Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/schema/merge_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
"type": "array",
"wholeListMerge": true
},
"omitWhenMergedFalse": {
"omitWhenMerged": false
},
"wholeListMergeFalse": {
"wholeListMerge": false
},
"both": {
"type": "array",
"items": {
Expand Down
4 changes: 3 additions & 1 deletion tests/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,12 @@ def test_validate_merge_properties():
errors = validate('merge_properties')

assert sorted(str(record.message) for record in records) == [
'tests/fixtures/schema/merge_properties.json sets "omitWhenMerged" to false or null at /properties/omitWhenMergedFalse', # noqa
'tests/fixtures/schema/merge_properties.json sets "wholeListMerge" to false or null at /properties/wholeListMergeFalse', # noqa
'tests/fixtures/schema/merge_properties.json sets "wholeListMerge", though the field is not an array of objects, at /properties/array', # noqa
'tests/fixtures/schema/merge_properties.json sets both "omitWhenMerged" and "wholeListMerge" at /properties/both', # noqa
]
assert errors == len(records) == 2
assert errors == len(records) == 4


def test_validate_metadata_presence():
Expand Down

0 comments on commit 8165f2a

Please sign in to comment.