Skip to content

Commit

Permalink
Improve error thrown for invalid schema with multi source.
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey committed Mar 15, 2023
1 parent 6cfd352 commit f459d23
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Speed up validating annotations with user fields ([#1078](../../pull/1078))
- Speed up validating annotation colors ([#1080](../../pull/1080))
- Support more complex bands from the test source ([#1082](../../pull/1082))
- Improve error thrown for invalid schema with multi source ([#1083](../../pull/1083))

### Bug Fixes
- The cache could reuse a class inappropriately ([#1070](../../pull/1070))
Expand Down
5 changes: 4 additions & 1 deletion sources/multi/large_image_source_multi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,10 @@ def __init__(self, path, **kwargs):
self._info = yaml.safe_load(fptr)
except (json.JSONDecodeError, yaml.YAMLError, UnicodeDecodeError):
raise TileSourceError('File cannot be opened via multi-source reader.')
self._validator.validate(self._info)
try:
self._validator.validate(self._info)
except jsonschema.ValidationError:
raise TileSourceError('File cannot be validated via multi-source reader.')
self._basePath = Path(self._largeImagePath).parent
self._basePath /= Path(self._info.get('basePath', '.'))
for axis in self._info.get('axes', []):
Expand Down
9 changes: 9 additions & 0 deletions test/test_source_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ def testTilesFromMultiString():
large_image_source_multi.open('invalid' + sourceString)


def testTilesFromNonschemaMultiString():
sourceString = json.dumps({'sources': [{
'sourceName': 'test', 'path': '__none__',
'notAKnownKey': 'X',
'params': {'sizeX': 10000, 'sizeY': 10000}}]})
with pytest.raises(large_image.exceptions.TileSourceError):
large_image_source_multi.open(sourceString)


@pytest.mark.skipif(sys.version_info < (3, 7), reason='requires python >= 3.7 for a sub-source')
def testInternalMetadata(multiSourceImagePath):
imagePath = multiSourceImagePath
Expand Down

0 comments on commit f459d23

Please sign in to comment.