Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change log

### 0.2.3
- Performance improvement if there are any errors


### 0.2.2
- Added functionality to get the specific number of errors
```
Expand Down
16 changes: 12 additions & 4 deletions src/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ASSETS_DIR = os.path.join(PARENT_DIR, 'tests/assets')
VALID_ZIP_FILE = os.path.join(ASSETS_DIR, 'valid.zip')
INVALID_ZIP_FILE = os.path.join(ASSETS_DIR, 'invalid.zip')
INVALID_VANCOUVER_ZIP_FILE = os.path.join(ASSETS_DIR, 'vancouver-dataset.zip')
SCHEMA_DIR = os.path.join(PARENT_DIR, 'src/python_osw_validation/schema')
SCHEMA_FILE_PATH = os.path.join(SCHEMA_DIR, 'opensidewalks.schema.json')

Expand All @@ -24,15 +25,21 @@ def valid_test_without_provided_schema():
def invalid_test_with_provided_schema():
validator = OSWValidation(zipfile_path=INVALID_ZIP_FILE, schema_file_path=SCHEMA_FILE_PATH)
result = validator.validate()
if not result.is_valid:
for error in result.errors:
print(error)
print(f'Number of errors: {len(result.errors)}')
print(f'Invalid Test With Provided Schema: {"Failed" if result.is_valid else "Passed"}')


def invalid_test_without_provided_schema():
validator = OSWValidation(zipfile_path=INVALID_ZIP_FILE)
result = validator.validate()
result = validator.validate(max_errors=10)
print(f'Number of errors: {len(result.errors)}')
print(f'Invalid Test With Provided Schema: {"Failed" if result.is_valid else "Passed"}')


def invalid_test_vancouver_dataset():
validator = OSWValidation(zipfile_path=INVALID_VANCOUVER_ZIP_FILE)
result = validator.validate(max_errors=30)
print(f'Number of errors: {len(result.errors)}')
print(f'Invalid Test Without Schema: {"Failed" if result.is_valid else "Passed"}')


Expand All @@ -41,3 +48,4 @@ def invalid_test_without_provided_schema():
valid_test_without_provided_schema()
invalid_test_with_provided_schema()
invalid_test_without_provided_schema()
invalid_test_vancouver_dataset()
16 changes: 8 additions & 8 deletions src/python_osw_validation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ def validate_osw_errors(self, file_path: str, max_errors: int) -> bool:
'''Validate OSW Data against the schema and process all errors'''
geojson_data = self.load_osw_file(file_path)
validator = jsonschema.Draft7Validator(self.load_osw_schema(self.schema_file_path))
errors = list(validator.iter_errors(geojson_data))

if errors:
for index, error in enumerate(errors):
if index < max_errors:
self.errors.append(f'Validation error: {error.message}')
if len(self.errors) == max_errors:
break

for error in validator.iter_errors(geojson_data):
self.errors.append(f'Validation error: {error.message}')
if len(self.errors) == max_errors:
break

if len(self.errors) >= max_errors:
return False

return True
2 changes: 1 addition & 1 deletion src/python_osw_validation/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.2.2'
__version__ = '0.2.3'
Binary file added tests/assets/vancouver-dataset.zip
Binary file not shown.