-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_validator.py
More file actions
78 lines (71 loc) · 2.52 KB
/
test_validator.py
File metadata and controls
78 lines (71 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import pytest
from datetime import date
from pipe_segment.cli.commands.validator import (
valid_date,
valid_daterange,
valid_table_reference,
valid_frequency,
valid_positive_int,
)
class TestValidators:
@pytest.mark.parametrize(
"entry,expected",
[
("2020-01-01", date(2020, 1, 1)),
("2024-02-29", date(2024, 2, 29)),
pytest.param("test", "test", marks=pytest.mark.xfail),
]
)
def test_valid_date(self, entry, expected):
assert expected == valid_date(entry)
@pytest.mark.parametrize(
"entry,expected",
[
("2020-01-01,2020-01-01", "2020-01-01,2020-01-01"),
pytest.param("2024-02-29,2024-02-28", "test", marks=pytest.mark.xfail),
]
)
def test_valid_daterange(self, entry, expected):
assert expected == valid_daterange(entry)
@pytest.mark.parametrize(
"table,expected",
[
("a.b.c", "a.b.c"),
("a-x.b-y.c-z", "a-x.b-y.c-z"),
pytest.param("b.c", "b.c", marks=pytest.mark.xfail),
pytest.param("a-b.c", "a-b.c", marks=pytest.mark.xfail),
pytest.param("test", "test", marks=pytest.mark.xfail),
]
)
def test_valid_table_reference(self, table, expected):
assert expected == valid_table_reference(table)
@pytest.mark.parametrize(
"value,expected",
[
(0.1, 0.1),
(1e-1, 1e-1),
pytest.param(1.2, 1.2, marks=pytest.mark.xfail),
pytest.param(-1.2, -1.2, marks=pytest.mark.xfail),
pytest.param("0.1", "0.1", marks=pytest.mark.xfail),
pytest.param("e", "e", marks=pytest.mark.xfail),
pytest.param([], [], marks=pytest.mark.xfail),
pytest.param({}, {}, marks=pytest.mark.xfail),
]
)
def test_value_valid_frequency(self, value, expected):
assert expected == valid_frequency(value)
@pytest.mark.parametrize(
"value,expected",
[
(1, 1),
(0, 0),
pytest.param(-1, -1, marks=pytest.mark.xfail),
pytest.param(1e-1, 1e-1, marks=pytest.mark.xfail),
pytest.param("1", "1", marks=pytest.mark.xfail),
pytest.param("e", "e", marks=pytest.mark.xfail),
pytest.param([], [], marks=pytest.mark.xfail),
pytest.param({}, {}, marks=pytest.mark.xfail),
]
)
def test_value_valid_positive_int(self, value, expected):
assert expected == valid_positive_int(value)