-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
66 lines (50 loc) · 1.82 KB
/
tests.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
60
61
62
63
64
65
66
import unittest
import logit
class LogItBasicTestCase(unittest.TestCase):
def setUp(self):
self.root = logit.Log()
self.events = []
self.root.sinks.append(self.events.append)
def test_get(self):
result = self.root.get('something')
assert isinstance(result, logit.Log)
assert result is not None
def test_getitem(self):
assert self.root['red'] == self.root.get('red')
def test_getattr(self):
assert self.root.red == self.root.get('red')
def test_get_empty(self):
assert self.root is self.root.get('')
assert self.root is self.root.get(u'')
def test_get_path(self):
assert self.root.get('a.b.c') is self.root.a.b.c
def test_path(self):
assert self.root.a.b.c.path() == 'a.b.c'
def test_parent(self):
assert self.root.something.parent() is self.root
def test_log_level(self):
sublogger = self.root.sublogger
sublogger_events = []
sublogger.sinks.append(sublogger_events.append)
self.root.sublogger.level = logit.Level.WARNING
self.root.sublogger.info('hey')
assert len(sublogger_events) == 0
# Warning events should go through:
sublogger.warning('hey')
assert len(self.events) == 1
def test_filter(self):
sublogger = self.root.sublogger
def always_false(event):
return False
# Make sure errors normally go through:
sublogger.error('some error')
assert len(self.events) == 1
del self.events[:]
# Now add a filter that always blocks events:
sublogger.filters.append(always_false)
sublogger.error('some error')
assert len(self.events) == 0
def test_info(self):
self.root.info("info")
if __name__ == '__main__':
unittest.main()