source: branches/hpc33/test/test_logging.py@ 2396

Last change on this file since 2396 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 
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
7
8if is_casapy():
9 raise SkipTest("Can't test against casalog")
10
11
12class 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
22stdout_redirect = WritableObject()
23
24def redirect_setup():
25 sys.stdout = stdout_redirect
26
27def redirect_teardown():
28 stdout_redirect.clear()
29 sys.stdout = sys.__stdout__
30
31@with_setup(redirect_setup, redirect_teardown)
32def 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)
41def 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)
50def 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)
62def 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.