python-osw-validation 0.0.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,36 @@
1
+ import os
2
+ import shutil
3
+ import tempfile
4
+ from typing import Optional
5
+ import zipfile36 as zipfile
6
+
7
+
8
+ class ZipFileHandler:
9
+ def __init__(self, zip_file_path: str):
10
+ self.zip_file_path = zip_file_path
11
+ self.extracted_dir = None
12
+ self.error = None
13
+
14
+ def create_temp_dir(self) -> str:
15
+ # Create a temporary directory for extracting files
16
+ self.extracted_dir = tempfile.mkdtemp()
17
+ return os.path.abspath(self.extracted_dir)
18
+
19
+ def extract_zip(self) -> Optional[str]:
20
+ try:
21
+ if not self.extracted_dir:
22
+ self.create_temp_dir()
23
+
24
+ with zipfile.ZipFile(self.zip_file_path, "r") as zip_ref:
25
+ zip_ref.extractall(self.extracted_dir)
26
+
27
+ first_item = zip_ref.namelist()[0]
28
+
29
+ return f'{self.extracted_dir}/{first_item}'
30
+ except Exception as e:
31
+ self.error = f'Error extracting ZIP file: {e}'
32
+
33
+ def remove_extracted_files(self) -> None:
34
+ if self.extracted_dir and os.path.exists(self.extracted_dir):
35
+ shutil.rmtree(self.extracted_dir)
36
+ self.extracted_dir = None
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2018 The Python Packaging Authority
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,119 @@
1
+ Metadata-Version: 2.1
2
+ Name: python-osw-validation
3
+ Version: 0.0.3
4
+ Summary: Python library for OSW validation
5
+ Home-page: https://github.com/TaskarCenterAtUW/TDEI-python-lib-osw-validation
6
+ Author: Sujata Misra
7
+ Author-email: sujatam@gaussiansolutions.com
8
+ Project-URL: Documentation, https://github.com/TaskarCenterAtUW/TDEI-python-lib-osw-validation/blob/main/README.md
9
+ Project-URL: GitHub, https://github.com/TaskarCenterAtUW/TDEI-python-lib-osw-validation
10
+ Project-URL: Changelog, https://github.com/TaskarCenterAtUW/TDEI-python-lib-osw-validation/blob/main/CHANGELOG.md
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: jsonschema ==4.19.1
18
+ Requires-Dist: zipfile36 ==0.1.3
19
+ Requires-Dist: coverage ==7.2.7
20
+
21
+ # TDEI python lib OSW validation package
22
+
23
+ This package validates the OSW geojson file. Package requires a OSW zip file path
24
+
25
+ ## System requirements
26
+
27
+ | Software | Version |
28
+ |----------|---------|
29
+ | Python | 3.10.x |
30
+
31
+ ## What this package does?
32
+
33
+ - It unzip the provided zip files
34
+ - Check for nodes, edges and points geojson files inside the unzipped folder
35
+ - Validate each file against schema, schema can be found here
36
+ - Return true or false according to validation
37
+ - you can check the error if it returned false.
38
+
39
+ ## Starting a new project with template
40
+
41
+ - Add `python-osw-validation` package as dependency in your `requirements.txt`
42
+ - or `pip install python-osw-validation`
43
+ - Start using the packages in your code.
44
+
45
+ ## Initialize and Configuration
46
+
47
+ ```python
48
+ from python_osw_validation import OSWValidation
49
+
50
+ validator = OSWValidation(zipfile_path='<Zip file path>')
51
+ result = validator.validate()
52
+ print(result.is_valid)
53
+ print(result.errors)
54
+
55
+ ```
56
+
57
+ ### Testing
58
+
59
+ The project is configured with `python` to figure out the coverage of the unit tests. All the tests are in `tests`
60
+ folder.
61
+
62
+ - To execute the tests, please follow the commands:
63
+
64
+ `pip install -r requirements.txt`
65
+
66
+ `python -m unittest discover -v tests/unit_tests`
67
+
68
+ - To execute the code coverage, please follow the commands:
69
+
70
+ `coverage run --source=src/python_osw_validation -m unittest discover -v tests/unit_tests`
71
+
72
+ `coverage html` // Can be run after 1st command
73
+
74
+ `coverage report` // Can be run after 1st command
75
+
76
+ - After the commands are run, you can check the coverage report in `htmlcov/index.html`. Open the file in any browser,
77
+ and it shows complete coverage details
78
+ - The terminal will show the output of coverage like this
79
+
80
+ ```shell
81
+
82
+ > coverage run --source=src/python_osw_validation -m unittest discover -v tests/unit_tests
83
+ test_invalid_empty_directory (test_extracted_data_validator.TestExtractedDataValidator) ... ok
84
+ test_invalid_missing_files_directory (test_extracted_data_validator.TestExtractedDataValidator) ... ok
85
+ test_invalid_missing_required_files_directory (test_extracted_data_validator.TestExtractedDataValidator) ... ok
86
+ test_valid_directory_structure (test_extracted_data_validator.TestExtractedDataValidator) ... ok
87
+ test_edges_invalid_zipfile (test_osw_validation.TestOSWValidation) ... ok
88
+ test_edges_invalid_zipfile_with_invalid_schema (test_osw_validation.TestOSWValidation) ... ok
89
+ test_edges_invalid_zipfile_with_schema (test_osw_validation.TestOSWValidation) ... ok
90
+ test_extra_field_zipfile (test_osw_validation.TestOSWValidation) ... ok
91
+ test_id_missing_zipfile (test_osw_validation.TestOSWValidation) ... ok
92
+ test_invalid_geometry_zipfile (test_osw_validation.TestOSWValidation) ... ok
93
+ test_invalid_zipfile (test_osw_validation.TestOSWValidation) ... ok
94
+ test_invalid_zipfile_with_invalid_schema (test_osw_validation.TestOSWValidation) ... ok
95
+ test_invalid_zipfile_with_schema (test_osw_validation.TestOSWValidation) ... ok
96
+ test_missing_files_inside_zipfile (test_osw_validation.TestOSWValidation) ... ok
97
+ test_missing_files_inside_zipfile_with_invalid_schema (test_osw_validation.TestOSWValidation) ... ok
98
+ test_missing_files_inside_zipfile_with_schema (test_osw_validation.TestOSWValidation) ... ok
99
+ test_missing_identifier_zipfile (test_osw_validation.TestOSWValidation) ... ok
100
+ test_no_entity_zipfile (test_osw_validation.TestOSWValidation) ... ok
101
+ test_nodes_invalid_zipfile (test_osw_validation.TestOSWValidation) ... ok
102
+ test_nodes_invalid_zipfile_with_invalid_schema (test_osw_validation.TestOSWValidation) ... ok
103
+ test_nodes_invalid_zipfile_with_schema (test_osw_validation.TestOSWValidation) ... ok
104
+ test_points_invalid_zipfile (test_osw_validation.TestOSWValidation) ... ok
105
+ test_points_invalid_zipfile_with_invalid_schema (test_osw_validation.TestOSWValidation) ... ok
106
+ test_points_invalid_zipfile_with_schema (test_osw_validation.TestOSWValidation) ... ok
107
+ test_valid_zipfile (test_osw_validation.TestOSWValidation) ... ok
108
+ test_valid_zipfile_with_invalid_schema (test_osw_validation.TestOSWValidation) ... ok
109
+ test_valid_zipfile_with_schema (test_osw_validation.TestOSWValidation) ... ok
110
+ test_wrong_datatypes_zipfile (test_osw_validation.TestOSWValidation) ... ok
111
+ test_extract_invalid_zip (test_zipfile_handler.TestZipFileHandler) ... ok
112
+ test_extract_valid_zip (test_zipfile_handler.TestZipFileHandler) ... ok
113
+ test_remove_extracted_files (test_zipfile_handler.TestZipFileHandler) ... ok
114
+
115
+ ----------------------------------------------------------------------
116
+ Ran 31 tests in 193.358s
117
+
118
+ OK
119
+ ```
@@ -0,0 +1,9 @@
1
+ python_osw_validation/__init__.py,sha256=wbfrPcBdOZsBOgwTYq2QByJ5RzXqVMGqZ62H85CNXkY,3046
2
+ python_osw_validation/extracted_data_validator.py,sha256=Nv_WQy7TOOMZWz0v6HEuwHrqPqseh2pn3yLhm1Tbjq8,1216
3
+ python_osw_validation/zipfile_handler.py,sha256=fv3GwxUIrtsB8qlMCYjz7GsMBvo7Mf8n7g5WZqcPaoY,1123
4
+ python_osw_validation/schema/opensidewalks.schema.json,sha256=qd-AJBfcMNA3Qr1EoL9u1fR662Qd9Qu3oNNkahzGNpE,103828
5
+ python_osw_validation-0.0.3.dist-info/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
6
+ python_osw_validation-0.0.3.dist-info/METADATA,sha256=F9O9WElt4VFSfc2gNDlOsQS11fWiLEt7vBdVUSFEuSQ,5396
7
+ python_osw_validation-0.0.3.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
8
+ python_osw_validation-0.0.3.dist-info/top_level.txt,sha256=GE81UPcDHEffJCxYu3M_iPz3Dt-O3axB73R5SLm_Veo,22
9
+ python_osw_validation-0.0.3.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.41.3)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ python_osw_validation