Skip to content

Commit c6e6586

Browse files
authored
Merge pull request #32 from TaskarCenterAtUW/feature-1679
Fixed 1679
2 parents 636348f + ebfa402 commit c6e6586

File tree

6 files changed

+63
-9
lines changed

6 files changed

+63
-9
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change log
22

3+
### 0.2.10
4+
5+
- Added limit the message error when u_id and v_id are missing
6+
- Added Unit test cases for missing u_id and v_id
7+
38
### 0.2.8
49

510
- Fixed geopands version to `0.14.4`.

src/example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
PARENT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
55
ASSETS_DIR = os.path.join(PARENT_DIR, 'tests/assets')
66
VALID_ZIP_FILE = os.path.join(ASSETS_DIR, 'valid.zip')
7-
INVALID_ZIP_FILE = os.path.join(ASSETS_DIR, 'invalid.zip')
7+
INVALID_ZIP_FILE = os.path.join(ASSETS_DIR, '4151.zip')
88
INVALID_VANCOUVER_ZIP_FILE = os.path.join(ASSETS_DIR, 'vancouver-dataset.zip')
99
SCHEMA_DIR = os.path.join(PARENT_DIR, 'src/python_osw_validation/schema')
1010
SCHEMA_FILE_PATH = os.path.join(SCHEMA_DIR, 'opensidewalks.schema.json')
@@ -33,6 +33,7 @@ def invalid_test_without_provided_schema():
3333
validator = OSWValidation(zipfile_path=INVALID_ZIP_FILE)
3434
result = validator.validate(max_errors=10)
3535
print(f'Number of errors: {len(result.errors)}')
36+
print(result.errors)
3637
print(f'Invalid Test With Provided Schema: {"Failed" if result.is_valid else "Passed"}')
3738

3839

src/python_osw_validation/__init__.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,40 @@ def validate(self, max_errors=20) -> ValidationResult:
107107
unmatched = node_ids_edges_u - node_ids
108108
is_valid = len(unmatched) == 0
109109
if not is_valid:
110+
unmatched_list = list(unmatched)
111+
num_unmatched = len(unmatched_list)
112+
limit = min(num_unmatched, 20)
113+
displayed_unmatched = ', '.join(map(str, unmatched_list[:limit]))
110114
self.errors.append(
111-
f"All _u_id's in edges should be part of _id's mentioned in nodes, _u_id's not in nodes are: {unmatched}")
115+
f"All _u_id's in edges should be part of _id's mentioned in nodes. "
116+
f"Showing {'20' if num_unmatched > 20 else 'all'} out of {len(unmatched)} unmatched _u_id's: {displayed_unmatched}"
117+
)
112118

113119
# Do all node references in _v_id exist in nodes?
114120
unmatched = node_ids_edges_v - node_ids
115121
is_valid = len(unmatched) == 0
116122
if not is_valid:
123+
unmatched_list = list(unmatched)
124+
num_unmatched = len(unmatched_list)
125+
limit = min(num_unmatched, 20)
126+
displayed_unmatched = ', '.join(map(str, unmatched_list[:limit]))
117127
self.errors.append(
118-
f"All _v_id's in edges should be part of _id's mentioned in nodes, _v_id's not in nodes are: {unmatched}")
128+
f"All _v_id's in edges should be part of _id's mentioned in nodes. "
129+
f"Showing {'20' if num_unmatched > 20 else 'all'} out of {len(unmatched)} unmatched _v_id's: {displayed_unmatched}"
130+
)
119131

120132
# Do all node references in _w_id exist in nodes?
121133
unmatched = node_ids_zones_w - node_ids
122134
is_valid = len(unmatched) == 0
123135
if not is_valid:
136+
unmatched_list = list(unmatched)
137+
num_unmatched = len(unmatched_list)
138+
limit = min(num_unmatched, 20)
139+
displayed_unmatched = ', '.join(map(str, unmatched_list[:limit]))
124140
self.errors.append(
125-
f"All _w_id's in zones should be part of _id's mentioned in nodes, _w_id's not in nodes are: {unmatched}")
141+
f"All _w_id's in zones should be part of _id's mentioned in nodes. "
142+
f"Showing {'20' if num_unmatched > 20 else 'all'} out of {len(unmatched)} unmatched _w_id's: {displayed_unmatched}"
143+
)
126144

127145
# Geometry validation: check geometry type in each file and test if coordinates make a shape that is reasonable geometric shape according to the Simple Feature Access standard
128146
for osw_file in OSW_DATASET:
@@ -131,8 +149,14 @@ def validate(self, max_errors=20) -> ValidationResult:
131149
OSW_DATASET[osw_file].is_valid == False)]
132150
is_valid = len(invalid_geojson) == 0
133151
if not is_valid:
152+
invalid_ids = list(set(invalid_geojson['_id']))
153+
num_invalid = len(invalid_ids)
154+
limit = min(num_invalid, 20)
155+
displayed_invalid = ', '.join(map(str, invalid_ids[:min(num_invalid, limit)]))
134156
self.errors.append(
135-
f"Invalid {osw_file} geometries found, id's of invalid geometries: {set(invalid_geojson['_id'])}")
157+
f"Showing {'20' if num_invalid > 20 else 'all'} out of {num_invalid} invalid {osw_file} geometries, "
158+
f"id's of invalid geometries: {displayed_invalid}"
159+
)
136160

137161
# Validate OSW external extensions
138162
for file in validator.externalExtensions:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.2.9'
1+
__version__ = '0.2.10'

tests/assets/4151.zip

14 KB
Binary file not shown.

tests/unit_tests/test_osw_validation.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def setUp(self):
2929
self.valid_zones_file = os.path.join(ASSETS_PATH, 'UW.zones.valid.zip')
3030
self.invalid_zones_file = os.path.join(ASSETS_PATH, 'UW.zones.invalid.zip')
3131
self.valid_osw_file = os.path.join(ASSETS_PATH, 'wa.bellevue.zip')
32+
self.invalid_v_id_file = os.path.join(ASSETS_PATH, '4151.zip')
3233
self.schema_file_path = SCHEMA_FILE_PATH
3334
self.invalid_schema_file_path = INVALID_SCHEMA_FILE_PATH
3435

@@ -45,7 +46,6 @@ def test_valid_zipfile_with_schema(self):
4546
self.assertIsNone(result.errors)
4647

4748
def test_valid_zipfile_with_invalid_schema(self):
48-
4949
validation = OSWValidation(zipfile_path=self.valid_zipfile, schema_file_path=self.invalid_schema_file_path)
5050
result = validation.validate()
5151
self.assertTrue(len(result.errors) > 0)
@@ -95,7 +95,7 @@ def test_invalid_zipfile_should_specific_errors_counts(self):
9595

9696
def test_invalid_zipfile_with_invalid_schema(self):
9797
validation = OSWValidation(zipfile_path=self.invalid_zipfile,
98-
schema_file_path=self.invalid_schema_file_path)
98+
schema_file_path=self.invalid_schema_file_path)
9999
result = validation.validate()
100100
self.assertTrue(len(result.errors) > 0)
101101

@@ -160,7 +160,8 @@ def test_external_extension_file_inside_zipfile(self):
160160
self.assertIsNone(result.errors)
161161

162162
def test_external_extension_file_inside_zipfile_with_schema(self):
163-
validation = OSWValidation(zipfile_path=self.external_extension_file_zipfile, schema_file_path=self.schema_file_path)
163+
validation = OSWValidation(zipfile_path=self.external_extension_file_zipfile,
164+
schema_file_path=self.schema_file_path)
164165
result = validation.validate()
165166
self.assertTrue(result.is_valid)
166167
self.assertIsNone(result.errors)
@@ -226,6 +227,29 @@ def test_invalid_zones_file(self):
226227
self.assertFalse(result.is_valid)
227228
self.assertIsNotNone(result.errors)
228229

230+
def test_unmatched_ids_limited_to_20(self):
231+
validation = OSWValidation(zipfile_path=self.invalid_v_id_file)
232+
result = validation.validate()
233+
234+
# Ensure validation fails
235+
self.assertFalse(result.is_valid, 'Validation should fail, but it passed.')
236+
self.assertTrue(result.errors, 'Validation should produce errors, but it returned none.')
237+
238+
# Try to find the unmatched ID error message
239+
error_message = next((err for err in result.errors if 'unmatched' in err.lower()), None)
240+
241+
# Ensure the error message exists
242+
self.assertIsNotNone(error_message, 'Expected error message for unmatched IDs not found.')
243+
244+
# Extract the displayed IDs from the message
245+
extracted_ids = error_message.split(':')[-1].strip().split(', ')
246+
247+
# Ensure only 20 IDs are displayed
248+
self.assertLessEqual(len(extracted_ids), 20, 'More than 20 unmatched IDs displayed in the error message.')
249+
250+
# Ensure the total count is mentioned
251+
self.assertIn('Showing 20 out of', error_message)
252+
229253

230254
if __name__ == '__main__':
231255
unittest.main()

0 commit comments

Comments
 (0)