2
2
from datetime import datetime
3
3
4
4
from pykwalify .core import Core
5
- from pykwalify .errors import NotSequenceError
5
+ from pykwalify .errors import NotSequenceError , CoreError
6
6
7
7
8
8
class Rule (object ):
@@ -28,6 +28,48 @@ def ec():
28
28
return Core (source_data = {}, schema_data = {})
29
29
30
30
31
+ def test_validate_range ():
32
+ data_matrix = [
33
+ (10 , 5 , 10 , 5 , 7 , []),
34
+ (None , None , None , None , 7 , []),
35
+
36
+ (10 , 5 , None , None , 13 , ["Type 'prefix' has size of '13', greater than max limit '10'. Path: '/'" ]),
37
+ (10 , 5 , None , None , 3 , ["Type 'prefix' has size of '3', less than min limit '5'. Path: '/'" ]),
38
+ (10 , 5 , None , None , 13.5 , ["Type 'prefix' has size of '13.5', greater than max limit '10'. Path: '/'" ]),
39
+ (10 , 5 , None , None , 3.5 , ["Type 'prefix' has size of '3.5', less than min limit '5'. Path: '/'" ]),
40
+ (10 , 5 , None , None , 10 , []),
41
+ (10 , 5 , None , None , 5 , []),
42
+ (10 , 5 , None , None , 10.0 , []),
43
+ (10 , 5 , None , None , 5.0 , []),
44
+
45
+ (None , None , 10 , 5 , 13 , ["Type 'prefix' has size of '13', greater than or equals to max limit(exclusive) '10'. Path: '/'" ]),
46
+ (None , None , 10 , 5 , 3 , ["Type 'prefix' has size of '3', less than or equals to min limit(exclusive) '5'. Path: '/'" ]),
47
+ (None , None , 10 , 5 , 13.5 , ["Type 'prefix' has size of '13.5', greater than or equals to max limit(exclusive) '10'. Path: '/'" ]),
48
+ (None , None , 10 , 5 , 3.5 , ["Type 'prefix' has size of '3.5', less than or equals to min limit(exclusive) '5'. Path: '/'" ]),
49
+ (None , None , 10 , 5 , 10 , ["Type 'prefix' has size of '10', greater than or equals to max limit(exclusive) '10'. Path: '/'" ]),
50
+ (None , None , 10 , 5 , 5 , ["Type 'prefix' has size of '5', less than or equals to min limit(exclusive) '5'. Path: '/'" ]),
51
+ (None , None , 10 , 5 , 8 , []),
52
+ (None , None , 10 , 5 , 7 , []),
53
+ (None , None , 10 , 5 , 8.5 , []),
54
+ (None , None , 10 , 5 , 7.5 , []),
55
+ ]
56
+
57
+ for max_ , min_ , max_ex , min_ex , value , errors in data_matrix :
58
+ print ("Testing data: {} {} {} {} {}" .format (max_ , min_ , max_ex , min_ex , value ))
59
+ c = ec ()
60
+ c ._validate_range (max_ , min_ , max_ex , min_ex , value , '/' , 'prefix' )
61
+ assert _remap_errors (c ) == errors
62
+
63
+ # Test value type validation inside the method
64
+ with pytest .raises (CoreError ):
65
+ c = ec ()
66
+ c ._validate_range (5 , 1 , None , None , [1 , 2 , 3 ], '/' , 'prefix' )
67
+
68
+ with pytest .raises (CoreError ):
69
+ c = ec ()
70
+ c ._validate_range (5 , 1 , None , None , {'a' : 1 , 'b' : 2 , 'c' : 3 }, '/' , 'prefix' )
71
+
72
+
31
73
def test_validate_timestamp ():
32
74
data_matrix = [
33
75
("" , ["Timestamp value is empty. Path: ''" ]),
0 commit comments