Skip to content

Commit 777afa6

Browse files
committed
Simplify test_validate_timestamp & test_validate_scalar_type
1 parent cdf4b31 commit 777afa6

File tree

1 file changed

+31
-66
lines changed

1 file changed

+31
-66
lines changed

tests/test_core_methods.py

+31-66
Original file line numberDiff line numberDiff line change
@@ -29,72 +29,37 @@ def ec():
2929

3030

3131
def test_validate_timestamp():
32-
c = ec()
33-
c._validate_scalar_timestamp("", '')
34-
assert _remap_errors(c) == ["Timestamp value is empty. Path: ''"]
35-
36-
c = ec()
37-
c._validate_scalar_timestamp("1234567", '')
38-
assert _remap_errors(c) == []
39-
40-
c = ec()
41-
c._validate_scalar_timestamp("2016-01-01", '')
42-
assert _remap_errors(c) == []
43-
44-
c = ec()
45-
c._validate_scalar_timestamp("2016-01-01 15:01", '')
46-
assert _remap_errors(c) == []
47-
48-
c = ec()
49-
c._validate_scalar_timestamp(123, '')
50-
assert _remap_errors(c) == []
51-
52-
c = ec()
53-
c._validate_scalar_timestamp(1.5, '')
54-
assert _remap_errors(c) == []
55-
56-
c = ec()
57-
c._validate_scalar_timestamp(0, '')
58-
assert _remap_errors(c) == ["Integer value of timestamp can't be below 0"]
59-
60-
c = ec()
61-
c._validate_scalar_timestamp(-1, '')
62-
assert _remap_errors(c) == ["Integer value of timestamp can't be below 0"]
63-
64-
c = ec()
65-
c._validate_scalar_timestamp(3147483647, '')
66-
assert _remap_errors(c) == ["Integer value of timestamp can't be above 2147483647"]
67-
68-
c = ec()
69-
c._validate_scalar_timestamp([], '')
70-
assert _remap_errors(c) == ['Not a valid timestamp']
71-
72-
c = ec()
73-
c._validate_scalar_timestamp(datetime.now(), '')
74-
assert _remap_errors(c) == []
75-
76-
c = ec()
77-
c._validate_scalar_timestamp(datetime.today(), '')
78-
assert _remap_errors(c) == []
32+
data_matrix = [
33+
("", ["Timestamp value is empty. Path: ''"]),
34+
("1234567", []),
35+
("2016-01-01", []),
36+
("2016-01-01 15:01", []),
37+
(123, []),
38+
(1.5, []),
39+
(0, ["Integer value of timestamp can't be below 0"]),
40+
(-1, ["Integer value of timestamp can't be below 0"]),
41+
(3147483647, ["Integer value of timestamp can't be above 2147483647"]),
42+
([], ["Not a valid timestamp"]),
43+
(datetime.now(), []),
44+
(datetime.today(), []),
45+
]
46+
47+
for data in data_matrix:
48+
c = ec()
49+
c._validate_scalar_timestamp(data[0], '')
50+
assert _remap_errors(c) == data[1]
7951

8052

8153
def test_validate_scalar_type():
82-
c = ec()
83-
c._validate_scalar_type("1e-06", "float", '')
84-
assert _remap_errors(c) == []
85-
86-
c = ec()
87-
c._validate_scalar_type("1z-06", "float", '')
88-
assert _remap_errors(c) == ["Value '1z-06' is not of type 'float'. Path: ''"]
89-
90-
c = ec()
91-
c._validate_scalar_type(1.5, "float", '')
92-
assert _remap_errors(c) == []
93-
94-
c = ec()
95-
c._validate_scalar_type("abc", "float", '')
96-
assert _remap_errors(c) == ["Value 'abc' is not of type 'float'. Path: ''"]
97-
98-
c = ec()
99-
c._validate_scalar_type(True, "float", '')
100-
assert _remap_errors(c) == ["Value 'True' is not of type 'float'. Path: ''"]
54+
data_matrix = [
55+
("1e-06", []),
56+
("1z-06", ["Value '1z-06' is not of type 'float'. Path: ''"]),
57+
(1.5, []),
58+
("abc", ["Value 'abc' is not of type 'float'. Path: ''"]),
59+
(True, ["Value 'True' is not of type 'float'. Path: ''"]),
60+
]
61+
62+
for data in data_matrix:
63+
c = ec()
64+
c._validate_scalar_type(data[0], 'float', '')
65+
assert _remap_errors(c) == data[1]

0 commit comments

Comments
 (0)