-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_main.py
59 lines (48 loc) · 1.7 KB
/
test_main.py
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
import unittest
from datetime import datetime
from main import build_filter_function, filter_by_age
class TestFilterByAge(unittest.TestCase):
def setUp(self) -> None:
self.indices = [
"pdauditlog-2021-10-01",
"pdauditlog-2021-10-02",
"pdauditlog-2021-10-03",
"pddebuglog-2021-10-01",
"pddebuglog-2021-10-02",
"pddebuglog-2021-10-03",
]
return
def test_filter_2_days_ago(
self, unit_count: int = 2, today_timestring: str = "2021-10-04"
):
print(f"\nIndices: {self.indices}")
print(f"Today ==> {today_timestring}")
fn = build_filter_function(
unit_count,
today_timeobj=datetime.strptime(str(today_timestring), "%Y-%m-%d"),
)
indices = filter_by_age(fn, self.indices)
print(f"Filter {unit_count} days ago indices.")
print(f"Found {len(indices)} indices {indices}")
self.assertEqual(
indices,
[
"pdauditlog-2021-10-01",
"pddebuglog-2021-10-01",
],
)
def test_filter_empty_indices(
self, unit_count: int = 10, today_timestring: str = "2021-10-04"
):
print(f"\nIndices: {self.indices}")
print(f"Today ==> {today_timestring}")
fn = build_filter_function(
unit_count,
today_timeobj=datetime.strptime(str(today_timestring), "%Y-%m-%d"),
)
indices = filter_by_age(fn, self.indices)
print(f"Filter {unit_count} days ago indices.")
print(f"Found {len(indices)} indices {indices}")
self.assertEqual(indices, [])
if __name__ == "__main__":
unittest.main()