Last change
on this file since 2582 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 | |
---|
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 | from asap import rcParams
|
---|
8 |
|
---|
9 | # no logging if not verbose
|
---|
10 | rcParams['verbose'] = True
|
---|
11 |
|
---|
12 | if is_casapy():
|
---|
13 | raise SkipTest("Can't test against casalog")
|
---|
14 |
|
---|
15 |
|
---|
16 | class 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 |
|
---|
26 | stdout_redirect = WritableObject()
|
---|
27 |
|
---|
28 | def redirect_setup():
|
---|
29 | sys.stdout = stdout_redirect
|
---|
30 |
|
---|
31 | def redirect_teardown():
|
---|
32 | stdout_redirect.clear()
|
---|
33 | sys.stdout = sys.__stdout__
|
---|
34 |
|
---|
35 | @with_setup(redirect_setup, redirect_teardown)
|
---|
36 | def 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)
|
---|
45 | def 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)
|
---|
54 | def 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)
|
---|
66 | def 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.