Skip to content

Commit 95c2472

Browse files
committed
- Updated code as per review comments
- Added unit test workflow
1 parent 2865098 commit 95c2472

File tree

4 files changed

+38
-19
lines changed

4 files changed

+38
-19
lines changed

.github/workflows/unit_tests.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
name: Tests
3+
on:
4+
pull_request:
5+
branches: [develop]
6+
7+
jobs:
8+
Tests:
9+
name: Unit tests
10+
# Set the agent to run on
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v3
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: "3.10"
20+
21+
- name: Install dependencies
22+
run: |
23+
pip install -r requirement.txt
24+
25+
- name: Run unit tests
26+
run: |
27+
python -m unittest discover -v tests/unit_tests

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Change log
22

33
### 0.2.2
4-
- Added functionality to get the specific umber of errors
4+
- Added functionality to get the specific number of errors
55
```
66
validator = OSWValidation(zipfile_path=<ZIP_FILE_PATH>)
77
result = validator.validate() // will return only first 20 errors by default

src/python_osw_validation/__init__.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ def validate(self, max_errors=20) -> ValidationResult:
7373
OSW_dataset = {}
7474
for file in validator.files:
7575
file_path = os.path.join(file)
76-
osw_file = next(
77-
(osw_file_any for osw_file_any in OSW_dataset_files.keys() if osw_file_any in file_path), '')
76+
osw_file = next((osw_file_any for osw_file_any in OSW_dataset_files.keys() if osw_file_any in file_path), '')
7877
OSW_dataset[osw_file] = gpd.read_file(file_path)
7978

8079
# Are all id's unique in each file? No need to check uniqueness across files yet since we do not have a global OSW ID format yet
@@ -105,32 +104,26 @@ def validate(self, max_errors=20) -> ValidationResult:
105104
unmatched = node_ids_edges_u - node_ids
106105
is_valid = len(unmatched) == 0
107106
if not is_valid:
108-
self.errors.append(
109-
f"All _u_id's in edges should be part of _id's mentioned in nodes, _u_id's not in nodes are: {unmatched}")
107+
self.errors.append(f"All _u_id's in edges should be part of _id's mentioned in nodes, _u_id's not in nodes are: {unmatched}")
110108

111109
# Do all node references in _v_id exist in nodes?
112110
unmatched = node_ids_edges_v - node_ids
113111
is_valid = len(unmatched) == 0
114112
if not is_valid:
115-
self.errors.append(
116-
f"All _v_id's in edges should be part of _id's mentioned in nodes, _v_id's not in nodes are: {unmatched}")
113+
self.errors.append(f"All _v_id's in edges should be part of _id's mentioned in nodes, _v_id's not in nodes are: {unmatched}")
117114

118115
# Do all node references in _w_id exist in nodes?
119116
unmatched = node_ids_zones_w - node_ids
120117
is_valid = len(unmatched) == 0
121118
if not is_valid:
122-
self.errors.append(
123-
f"All _w_id's in zones should be part of _id's mentioned in nodes, _w_id's not in nodes are: {unmatched}")
119+
self.errors.append(f"All _w_id's in zones should be part of _id's mentioned in nodes, _w_id's not in nodes are: {unmatched}")
124120

125121
# 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
126122
for osw_file in OSW_dataset:
127-
invalid_geojson = OSW_dataset[osw_file][
128-
(OSW_dataset[osw_file].geometry.type != OSW_dataset_files[osw_file]['geometry']) | (
129-
OSW_dataset[osw_file].is_valid == False)]
123+
invalid_geojson = OSW_dataset[osw_file][(OSW_dataset[osw_file].geometry.type != OSW_dataset_files[osw_file]['geometry']) | (OSW_dataset[osw_file].is_valid == False)]
130124
is_valid = len(invalid_geojson) == 0
131125
if not is_valid:
132-
self.errors.append(
133-
f"Invalid {osw_file} geometries found, id's of invalid geometries: {set(invalid_geojson['_id'])}")
126+
self.errors.append(f"Invalid {osw_file} geometries found, id's of invalid geometries: {set(invalid_geojson['_id'])}")
134127

135128
# Validate OSW external extensions
136129
for file in validator.externalExtensions:
@@ -139,8 +132,7 @@ def validate(self, max_errors=20) -> ValidationResult:
139132
invalid_geojson = extensionFile[extensionFile.is_valid == False]
140133
is_valid = len(invalid_geojson) == 0
141134
if not is_valid:
142-
self.errors.append(
143-
f"Invalid geometries found in extension file {file}, list of invalid geometries: {invalid_geojson.to_json()}")
135+
self.errors.append(f"Invalid geometries found in extension file {file}, list of invalid geometries: {invalid_geojson.to_json()}")
144136

145137
if self.errors:
146138
zip_handler.remove_extracted_files()

tests/unit_tests/test_osw_validation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ def test_invalid_zipfile_default_error_count(self):
8181
result = validation.validate()
8282
self.assertFalse(result.is_valid)
8383
self.assertIsNotNone(result.errors)
84-
self.assertEqual(20, len(result.errors))
84+
self.assertLessEqual(len(result.errors), 20)
8585

86-
def test_invalid_zipfile_should_return_10_errors(self):
86+
def test_invalid_zipfile_should_specific_errors_counts(self):
8787
validation = OSWValidation(zipfile_path=self.invalid_zipfile)
8888
result = validation.validate(max_errors=10)
8989
self.assertFalse(result.is_valid)
9090
self.assertIsNotNone(result.errors)
91-
self.assertEqual(10, len(result.errors))
91+
self.assertLessEqual(len(result.errors), 10)
9292

9393
def test_invalid_zipfile_with_invalid_schema(self):
9494
validation = OSWValidation(zipfile_path=self.invalid_zipfile,

0 commit comments

Comments
 (0)