Skip to content

Commit 12050b2

Browse files
committed
Fixed Issue 1378
- Fixed geopands version to `0.14.4`. - Added unit test cases for invalid and invalid zones file - Updated package version
1 parent f2c47aa commit 12050b2

File tree

11 files changed

+99
-25
lines changed

11 files changed

+99
-25
lines changed

CHANGELOG.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
# Change log
22

3+
### 0.2.8
4+
5+
- Fixed geopands version to `0.14.4`.
6+
- Latest geopands version `0.10.0` is not compatible and failing to parse the zones.
7+
- Added unit test cases for valid and invalid zone files
8+
39
### 0.2.7
10+
411
- Switch to `jsonschema_rs` for performance enhancement, instead of `jsonschema` package
512
- Refactor code for improve memory utilization
613
- Added garbage collector
714

8-
915
### 0.2.6
10-
- Add garbage collection to free up memory after validation
1116

17+
- Add garbage collection to free up memory after validation
1218

1319
### 0.2.5
14-
- Updated geopandas package
1520

21+
- Updated geopandas package
1622

1723
### 0.2.3
18-
- Performance improvement if there are any errors
1924

25+
- Performance improvement if there are any errors
2026

2127
### 0.2.2
28+
2229
- Added functionality to get the specific number of errors
2330
```
2431
validator = OSWValidation(zipfile_path=<ZIP_FILE_PATH>)
@@ -27,10 +34,12 @@
2734
```
2835

2936
### 0.2.1
37+
3038
- Updated zipfile_handler
3139
- Fixed "No .geojson files found in the specified directory or its subdirectories." issue
3240

3341
### 0.2.0
42+
3443
- Updated schema file to OSW 0.2
3544
- Added create_zip method to ZipFileHandler
3645
- Made all OSW files optional
@@ -40,20 +49,25 @@
4049
- Aggregate schema errors and data integrity errors separately before returning errors to user
4150

4251
### 0.0.5
52+
4353
- Support for multi-level geojson file
4454
- Now handles the following two folder structures when unzipped abc.zip
45-
1. abc\{nodes, edges, points}.geojson
46-
2. {nodes, edges, points}.geojson
47-
55+
1. abc\{nodes, edges, points}.geojson
56+
2. {nodes, edges, points}.geojson
57+
4858
### 0.0.4
59+
4960
- Points are not required for a valid OSW dataset
5061

5162
### 0.0.3
63+
5264
- Added schema file to package
5365

5466
### 0.0.2
67+
5568
- Updated package Unit test cases.
5669
- Updated README file
5770

5871
### 0.0.1
72+
5973
- Initial version of python_osw_validation package.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
jsonschema_rs
22
zipfile36
33
coverage
4-
geopandas
4+
geopandas==0.14.4

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
long_description_content_type='text/markdown',
2020
url='https://github.com/TaskarCenterAtUW/TDEI-python-lib-osw-validation',
2121
install_requires=[
22-
'jsonschema_rs',
23-
'zipfile36',
24-
'geopandas'
22+
'jsonschema_rs==0.26.1',
23+
'zipfile36==0.0.12',
24+
'geopandas==0.14.4'
2525
],
2626
packages=find_packages(where='src'),
2727
classifiers=[

src/python_osw_validation/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import Dict, Any, Optional, List
88
from .extracted_data_validator import ExtractedDataValidator, OSW_DATASET_FILES
99
from .version import __version__
10+
import traceback
1011

1112
SCHEMA_PATH = os.path.join(os.path.dirname(__file__), 'schema')
1213

@@ -149,6 +150,7 @@ def validate(self, max_errors=20) -> ValidationResult:
149150
return ValidationResult(True)
150151
except Exception as e:
151152
self.errors.append(f'Unable to validate: {e}')
153+
traceback.print_exc()
152154
return ValidationResult(False, self.errors)
153155
finally:
154156
del OSW_DATASET
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.2.7'
1+
__version__ = '0.2.8'

src/python_osw_validation/zipfile_handler.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os
2+
import glob
23
import shutil
34
import tempfile
4-
from typing import Optional
55
import zipfile36 as zipfile
6-
import glob
6+
from typing import Optional
77

88

99
class ZipFileHandler:
@@ -21,19 +21,19 @@ def create_zip(self, file_pattern) -> Optional[str]:
2121
try:
2222
# Build the full pattern with the directory
2323
full_pattern = os.path.join(os.path.dirname(self.zip_file_path), file_pattern)
24-
24+
2525
# Find all files in the directory matching the pattern
2626
files_to_zip = glob.glob(full_pattern)
27-
27+
2828
# Create a zip file and add matching files to it
2929
with zipfile.ZipFile(self.zip_file_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
3030
for file in files_to_zip:
3131
archive_name = os.path.relpath(file, os.path.dirname(self.zip_file_path))
3232
zipf.write(file, arcname=archive_name)
33-
33+
3434
# Get the full path to the created zip file
3535
full_zip_path = os.path.abspath(self.zip_file_path)
36-
36+
3737
# Return the full path to the zip file
3838
return full_zip_path
3939
except Exception as e:
@@ -49,22 +49,21 @@ def extract_zip(self) -> Optional[str]:
4949

5050
if len(zip_ref.namelist()) == 0:
5151
raise Exception('ZIP file is empty')
52-
52+
5353
internal_folder_name = self.find_internal_folder(zip_ref)
54-
return os.path.join(self.extracted_dir,internal_folder_name)
54+
return os.path.join(self.extracted_dir, internal_folder_name)
5555
except Exception as e:
5656
self.error = f'Error extracting ZIP file: {e}'
57-
57+
5858
# finds the first folder available in the extracted folder.
5959
# returns empty if there are no folders inside
60-
def find_internal_folder(self, zip_ref: zipfile.ZipFile)-> str:
60+
def find_internal_folder(self, zip_ref: zipfile.ZipFile) -> str:
6161
for filename in zip_ref.namelist():
62-
path = os.path.join(self.extracted_dir,filename)
63-
if(os.path.isdir(path)):
62+
path = os.path.join(self.extracted_dir, filename)
63+
if (os.path.isdir(path)):
6464
return filename
6565
return ''
6666

67-
6867
def remove_extracted_files(self) -> None:
6968
if self.extracted_dir and os.path.exists(self.extracted_dir):
7069
shutil.rmtree(self.extracted_dir)

tests/assets/UW.zones.invalid.zip

26.2 KB
Binary file not shown.

tests/assets/UW.zones.valid.zip

26.2 KB
Binary file not shown.

tests/assets/wa.bellevue.zip

6.32 MB
Binary file not shown.

tests/unit_tests/test_osw_validation.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ def setUp(self):
2626
self.missing_identifier_zipfile = os.path.join(ASSETS_PATH, 'missing_identifier.zip')
2727
self.no_entity_zipfile = os.path.join(ASSETS_PATH, 'no_entity.zip')
2828
self.wrong_datatypes_zipfile = os.path.join(ASSETS_PATH, 'wrong_datatype.zip')
29+
self.valid_zones_file = os.path.join(ASSETS_PATH, 'UW.zones.valid.zip')
30+
self.invalid_zones_file = os.path.join(ASSETS_PATH, 'UW.zones.invalid.zip')
31+
self.valid_osw_file = os.path.join(ASSETS_PATH, 'wa.bellevue.zip')
2932
self.schema_file_path = SCHEMA_FILE_PATH
3033
self.invalid_schema_file_path = INVALID_SCHEMA_FILE_PATH
3134

@@ -205,6 +208,24 @@ def test_wrong_datatypes_zipfile(self):
205208
self.assertFalse(result.is_valid)
206209
self.assertIsNotNone(result.errors)
207210

211+
def test_valid_osw_file(self):
212+
validation = OSWValidation(zipfile_path=self.valid_osw_file)
213+
result = validation.validate()
214+
self.assertTrue(result.is_valid)
215+
self.assertIsNone(result.errors)
216+
217+
def test_valid_zones_file(self):
218+
validation = OSWValidation(zipfile_path=self.valid_zones_file)
219+
result = validation.validate()
220+
self.assertTrue(result.is_valid)
221+
self.assertIsNone(result.errors)
222+
223+
def test_invalid_zones_file(self):
224+
validation = OSWValidation(zipfile_path=self.invalid_zones_file)
225+
result = validation.validate()
226+
self.assertFalse(result.is_valid)
227+
self.assertIsNotNone(result.errors)
228+
208229

209230
if __name__ == '__main__':
210231
unittest.main()

0 commit comments

Comments
 (0)