Skip to content

Commit 975a14c

Browse files
Merge pull request #6 from TaskarCenterAtUW/feature-extensions
Points are not required for a valid OSW dataset
2 parents fcb5476 + e0fdd70 commit 975a14c

File tree

7 files changed

+36
-8
lines changed

7 files changed

+36
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@
88
- Updated README file
99

1010
### 0.0.3
11-
- Added schema file to package
11+
- Added schema file to package
12+
13+
### 0.0.4
14+
- Points are not required for a valid OSW dataset

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ This package validates the OSW geojson file. Package requires a OSW zip file pat
1111
## What this package does?
1212

1313
- It unzip the provided zip files
14-
- Check for nodes, edges and points geojson files inside the unzipped folder
15-
- Validate each file against schema, schema can be found here
14+
- Check for the required nodes and edges geojson files inside the unzipped folder
15+
- Validate each file (nodes, edges and points) against schema, schema can be found here
1616
- Return true or false according to validation
1717
- you can check the error if it returned false.
1818

@@ -73,6 +73,9 @@ test_invalid_geometry_zipfile (test_osw_validation.TestOSWValidation) ... ok
7373
test_invalid_zipfile (test_osw_validation.TestOSWValidation) ... ok
7474
test_invalid_zipfile_with_invalid_schema (test_osw_validation.TestOSWValidation) ... ok
7575
test_invalid_zipfile_with_schema (test_osw_validation.TestOSWValidation) ... ok
76+
test_minimal_zipfile (test_osw_validation.TestOSWValidation) ... ok
77+
test_minimal_zipfile_with_invalid_schema (test_osw_validation.TestOSWValidation) ... ok
78+
test_minimal_zipfile_with_schema (test_osw_validation.TestOSWValidation) ... ok
7679
test_missing_files_inside_zipfile (test_osw_validation.TestOSWValidation) ... ok
7780
test_missing_files_inside_zipfile_with_invalid_schema (test_osw_validation.TestOSWValidation) ... ok
7881
test_missing_files_inside_zipfile_with_schema (test_osw_validation.TestOSWValidation) ... ok
@@ -93,7 +96,7 @@ test_extract_valid_zip (test_zipfile_handler.TestZipFileHandler) ... ok
9396
test_remove_extracted_files (test_zipfile_handler.TestZipFileHandler) ... ok
9497

9598
----------------------------------------------------------------------
96-
Ran 31 tests in 193.358s
99+
Ran 34 tests in 121.220s
97100

98101
OK
99102
```

freeze_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
build_date = date.today().strftime('%Y-%m-%d')
1313

14-
version = '0.0.3'
14+
version = '0.0.4'
1515

1616
with open(version_file_path, 'w+') as version_file:
1717
version_file.write("version = '{}'\n".format(version))

src/python_osw_validation/extracted_data_validator.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,24 @@ def is_valid(self) -> bool:
1414
return False
1515

1616
geojson_files = glob.glob(os.path.join(self.extracted_dir, '*.geojson'))
17-
if len(geojson_files) < 3:
17+
if len(geojson_files) < 2:
1818
self.error = 'There are not enough .geojson files in the folder.'
1919
return False
2020

21+
edges_present = False
22+
nodes_present = False
2123
for filename in geojson_files:
2224
base_name = os.path.basename(filename)
2325
if 'edges' in base_name and base_name.endswith('.geojson'):
2426
self.files.append(filename)
27+
edges_present = True
2528
elif 'nodes' in base_name and base_name.endswith('.geojson'):
2629
self.files.append(filename)
30+
nodes_present = True
2731
elif 'points' in base_name and base_name.endswith('.geojson'):
2832
self.files.append(filename)
2933

30-
if len(self.files) != 3:
34+
if not edges_present or not nodes_present:
3135
self.error = 'Missing one or more required .geojson files.'
3236
return False
3337

tests/assets/minimal.zip

926 Bytes
Binary file not shown.

tests/unit_tests/test_extracted_data_validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def create_invalid_missing_files_directory(self):
3535

3636
def create_invalid_missing_required_files_directory(self):
3737
# Create a directory with three geojson files, but not all required ones
38-
invalid_files = ['edges.geojson', 'invalid.geojson', 'nodes.geojson']
38+
invalid_files = ['edges.geojson', 'invalid.geojson', 'points.geojson']
3939
for file in invalid_files:
4040
open(os.path.join(self.invalid_missing_required_files_dir, file), 'w').close()
4141

tests/unit_tests/test_osw_validation.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class TestOSWValidation(unittest.TestCase):
1414

1515
def setUp(self):
1616
self.valid_zipfile = os.path.join(ASSETS_PATH, 'valid.zip')
17+
self.minimal_zipfile = os.path.join(ASSETS_PATH, 'minimal.zip')
1718
self.invalid_zipfile = os.path.join(ASSETS_PATH, 'invalid.zip')
1819
self.nodes_invalid_zipfile = os.path.join(ASSETS_PATH, 'nodes_invalid.zip')
1920
self.edges_invalid_zipfile = os.path.join(ASSETS_PATH, 'edges_invalid.zip')
@@ -46,6 +47,23 @@ def test_valid_zipfile_with_invalid_schema(self):
4647
result = validation.validate()
4748
self.assertTrue(len(result.errors) > 0)
4849

50+
def test_minimal_zipfile(self):
51+
validation = OSWValidation(zipfile_path=self.minimal_zipfile)
52+
result = validation.validate()
53+
self.assertTrue(result.is_valid)
54+
self.assertIsNone(result.errors)
55+
56+
def test_minimal_zipfile_with_schema(self):
57+
validation = OSWValidation(zipfile_path=self.minimal_zipfile, schema_file_path=self.schema_file_path)
58+
result = validation.validate()
59+
self.assertTrue(result.is_valid)
60+
self.assertIsNone(result.errors)
61+
62+
def test_minimal_zipfile_with_invalid_schema(self):
63+
validation = OSWValidation(zipfile_path=self.minimal_zipfile, schema_file_path=self.invalid_schema_file_path)
64+
result = validation.validate()
65+
self.assertTrue(len(result.errors) > 0)
66+
4967
def test_invalid_zipfile(self):
5068
validation = OSWValidation(zipfile_path=self.invalid_zipfile)
5169
result = validation.validate()

0 commit comments

Comments
 (0)