Last change
on this file since 3128 was 1863, checked in by Malte Marquarding, 14 years ago |
Added logger test. It is skipped under casapy as it compares stdout logs.
|
File size:
1.5 KB
|
Line | |
---|
1 | import sys
|
---|
2 | import os
|
---|
3 | from nose.tools import *
|
---|
4 | from nose.plugins.skip import Skip, SkipTest
|
---|
5 | from asap.logging import asaplog
|
---|
6 | from asap.env import is_casapy
|
---|
7 |
|
---|
8 | if is_casapy():
|
---|
9 | raise SkipTest("Can't test against casalog")
|
---|
10 |
|
---|
11 |
|
---|
12 | class WritableObject:
|
---|
13 | def __init__(self):
|
---|
14 | self.content = []
|
---|
15 |
|
---|
16 | def write(self, string):
|
---|
17 | self.content.append(string)
|
---|
18 |
|
---|
19 | def clear(self):
|
---|
20 | self.content = []
|
---|
21 |
|
---|
22 | stdout_redirect = WritableObject()
|
---|
23 |
|
---|
24 | def redirect_setup():
|
---|
25 | sys.stdout = stdout_redirect
|
---|
26 |
|
---|
27 | def redirect_teardown():
|
---|
28 | stdout_redirect.clear()
|
---|
29 | sys.stdout = sys.__stdout__
|
---|
30 |
|
---|
31 | @with_setup(redirect_setup, redirect_teardown)
|
---|
32 | def test_enabled():
|
---|
33 | asaplog.enable()
|
---|
34 | msg = "TEST"
|
---|
35 | asaplog.push(msg)
|
---|
36 | asaplog.post()
|
---|
37 | out = "".join(stdout_redirect.content).strip()
|
---|
38 | assert_equals(out, msg)
|
---|
39 |
|
---|
40 | @with_setup(redirect_setup, redirect_teardown)
|
---|
41 | def test_disabled():
|
---|
42 | asaplog.disable()
|
---|
43 | msg = "TEST"
|
---|
44 | asaplog.push(msg)
|
---|
45 | asaplog.post()
|
---|
46 | out = "".join(stdout_redirect.content).strip()
|
---|
47 | assert_equals(out, '')
|
---|
48 |
|
---|
49 | @with_setup(redirect_setup, redirect_teardown)
|
---|
50 | def test_push():
|
---|
51 | asaplog.enable()
|
---|
52 | msg = "TEST"
|
---|
53 | asaplog.push(msg)
|
---|
54 | asaplog.push(msg)
|
---|
55 | asaplog.post()
|
---|
56 | input = "\n".join([msg]*2)
|
---|
57 | out = "".join(stdout_redirect.content).strip()
|
---|
58 | assert_equals(out, input)
|
---|
59 |
|
---|
60 |
|
---|
61 | @with_setup(redirect_setup, redirect_teardown)
|
---|
62 | def test_level():
|
---|
63 | asaplog.enable()
|
---|
64 | msg = "TEST"
|
---|
65 | asaplog.push(msg)
|
---|
66 | asaplog.post('ERROR')
|
---|
67 | out = "".join(stdout_redirect.content).strip()
|
---|
68 | assert_equals(out, "SEVERE: "+msg)
|
---|
Note:
See
TracBrowser
for help on using the repository browser.