-
Notifications
You must be signed in to change notification settings - Fork 490
/
test_retentions.py
41 lines (37 loc) · 1.41 KB
/
test_retentions.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
from unittest import TestCase
from carbon.util import parseRetentionDef
class TestParseRetentionDef(TestCase):
def test_valid_retentions(self):
retention_map = (
('60:10', (60, 10)),
('10:60', (10, 60)),
('10s:10h', (10, 3600)),
)
for retention, expected in retention_map:
results = parseRetentionDef(retention)
self.assertEqual(results, expected)
def test_invalid_retentions(self):
retention_map = (
# From getUnitString
('10x:10', ValueError("Invalid unit 'x'")),
('60:10x', ValueError("Invalid unit 'x'")),
# From parseRetentionDef
('10X:10', ValueError("Invalid precision specification '10X'")),
('10:10$', ValueError("Invalid retention specification '10$'")),
('60:10', (60, 10)),
)
for retention, expected_exc in retention_map:
try:
results = parseRetentionDef(retention)
except expected_exc.__class__ as exc:
self.assertEqual(
str(expected_exc),
str(exc),
)
self.assertEqual(
expected_exc.__class__,
exc.__class__,
)
else:
# When there isn't an exception raised
self.assertEqual(results, expected_exc)