Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d7dd02d
[validation.py] Add Possible DType Check for String Property Values
fschrader1992 Mar 19, 2020
be4663c
[test_validation.py] Add Test for Property String Dtype Validation
fschrader1992 Mar 19, 2020
2ec7e54
[test/resources] Add integration.xml for odML Validation Test
fschrader1992 Mar 19, 2020
53eba68
[test_validation.py] Add Test for XML File Validation
fschrader1992 Mar 19, 2020
d062f52
[test/resources] Add integration.json for odML Validation Test
fschrader1992 Mar 19, 2020
3e5aaa7
[test_validation.py] Add Test for JSON File Validation
fschrader1992 Mar 19, 2020
43b4941
[test/resources] Add integration.yaml for odML Validation Test
fschrader1992 Mar 19, 2020
30892b4
[test_validation.py] Add Test for YAML File Validation
fschrader1992 Mar 19, 2020
f24eed3
[test_validation.py] Specify Section Type Test for File Loading Tests
fschrader1992 Mar 19, 2020
b5d8d09
[test_validation.py] Add Test for Property String Dtype Validation
fschrader1992 Mar 19, 2020
e22f725
[validation.py] Throw String Dtype Warning Only If All Values Match D…
fschrader1992 Mar 23, 2020
f912971
[test_validation.py] Move dir_path to setUp
fschrader1992 Mar 23, 2020
dde6730
[test_validation.py] Adapt Test for String Dtype Validation Behavior
fschrader1992 Mar 23, 2020
0d41ae8
[test_validation.py] Add Property with Dtype String for Property Stri…
fschrader1992 Mar 23, 2020
4160a8b
[test/resources] Replace File for XML Validation Tests
fschrader1992 Mar 23, 2020
7ee2ef6
[test_validation.py] Add Test for XML File Loading Sections
fschrader1992 Mar 23, 2020
4b1939a
[test_validation.py] Add Test for XML File Loading Property Dtypes
fschrader1992 Mar 23, 2020
3c78947
[test/resources] Replace File for JSON Validation Tests
fschrader1992 Mar 23, 2020
719e6fb
[test_validation.py] Add Test for JSON File Loading Sections
fschrader1992 Mar 23, 2020
2488ceb
[test_validation.py] Add Test for JSON File Loading Property Dtypes
fschrader1992 Mar 23, 2020
976b10b
[test/resources] Replace File for YAML Validation Tests
fschrader1992 Mar 23, 2020
f85ffe6
[test_validation.py] Add Test for YAML File Loading Sections
fschrader1992 Mar 23, 2020
52eb412
[test_validation.py] Add Test for YAML File Loading Property Dtypes
fschrader1992 Mar 23, 2020
fd78be4
[validation_dtypes.json] Remove Wrongly Set Dtype String
fschrader1992 Mar 24, 2020
baf75c8
[validation_dtypes] Remove Section For Text Without Dtype
fschrader1992 Mar 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions odml/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Generic odML validation framework.
"""

import re
from . import dtypes

LABEL_ERROR = 'error'
Expand Down Expand Up @@ -386,3 +387,56 @@ def property_values_check(prop):


Validation.register_handler('property', property_values_check)


def property_values_string_check(prop):
"""
PROTOTYPE

Tests whether values with dtype "string" are maybe of different dtype.

:param prop: property the validation is applied on.
"""

if prop.dtype != "string" or not prop.values:
return

dtype_checks = {
'int': r'^(-+)?\d+$',
'date': r'^\d{2,4}-\d{1,2}-\d{1,2}$',
'datetime': r'^\d{2,4}-\d{1,2}-\d{1,2} \d{2}:\d{2}(:\d{2})?$',
'time': r'^\d{2}:\d{2}(:\d{2})?$',
'float': r'^(-+)?\d+\.\d+$',
'tuple': r'^\((.*?)\)',
'boolean': r'^TRUE|FALSE|True|False|t|f+$',
'text': r'[\r\n]'}

val_dtypes = []

for val in prop.values:
curr_dtype = "string"

for check_dtype in dtype_checks.items():
if bool(re.compile(check_dtype[1]).match(val.strip())):
if check_dtype[0] == "tuple" and val.count(';') > 0:
curr_dtype = str(val.count(';') + 1) + "-" + check_dtype[0]
else:
curr_dtype = check_dtype[0]
break
if check_dtype[0] == "text" and len(re.findall(check_dtype[1], val.strip())) > 0:
curr_dtype = check_dtype[0]
break

val_dtypes += [curr_dtype]

res_dtype = max(set(val_dtypes), key=val_dtypes.count)

if len(set(val_dtypes)) > 1:
res_dtype = "string"

if res_dtype != "string":
msg = 'Dtype of property "%s" currently is "string", but might fit dtype "%s"!' % (prop.name, res_dtype)
yield ValidationError(prop, msg, LABEL_WARNING)


Validation.register_handler('property', property_values_string_check)
Loading