source: trunk/test/test_logging.py@ 2689

Last change on this file since 2689 was 2521, checked in by Malte Marquarding, 13 years ago

We are only logging to stdout when rcParams['verbose

File size: 1.6 KB
Line 
1import sys
2import os
3from nose.tools import *
4from nose.plugins.skip import Skip, SkipTest
5from asap.logging import asaplog
6from asap.env import is_casapy
7from asap import rcParams
8
9# no logging if not verbose
10rcParams['verbose'] = True
11
12if is_casapy():
13 raise SkipTest("Can't test against casalog")
14
15
16class WritableObject:
17 def __init__(self):
18 self.content = []
19
20 def write(self, string):
21 self.content.append(string)
22
23 def clear(self):
24 self.content = []
25
26stdout_redirect = WritableObject()
27
28def redirect_setup():
29 sys.stdout = stdout_redirect
30
31def redirect_teardown():
32 stdout_redirect.clear()
33 sys.stdout = sys.__stdout__
34
35@with_setup(redirect_setup, redirect_teardown)
36def test_enabled():
37 asaplog.enable()
38 msg = "TEST"
39 asaplog.push(msg)
40 asaplog.post()
41 out = "".join(stdout_redirect.content).strip()
42 assert_equals(out, msg)
43
44@with_setup(redirect_setup, redirect_teardown)
45def test_disabled():
46 asaplog.disable()
47 msg = "TEST"
48 asaplog.push(msg)
49 asaplog.post()
50 out = "".join(stdout_redirect.content).strip()
51 assert_equals(out, '')
52
53@with_setup(redirect_setup, redirect_teardown)
54def test_push():
55 asaplog.enable()
56 msg = "TEST"
57 asaplog.push(msg)
58 asaplog.push(msg)
59 asaplog.post()
60 input = "\n".join([msg]*2)
61 out = "".join(stdout_redirect.content).strip()
62 assert_equals(out, input)
63
64
65@with_setup(redirect_setup, redirect_teardown)
66def test_level():
67 asaplog.enable()
68 msg = "TEST"
69 asaplog.push(msg)
70 asaplog.post('ERROR')
71 out = "".join(stdout_redirect.content).strip()
72 assert_equals(out, "SEVERE: "+msg)
Note: See TracBrowser for help on using the repository browser.