File: test_reporter.py

package info (click to toggle)
python-weberror 0.10.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 392 kB
  • ctags: 427
  • sloc: python: 2,666; makefile: 18
file content (46 lines) | stat: -rw-r--r-- 1,148 bytes parent folder | download | duplicates (4)
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
import sys
import os
from weberror.reporter import *
from weberror import collector

def setup_file(fn, content=None):
    fn = os.path.join(os.path.dirname(__file__), 'reporter_output', fn)
    if os.path.exists(fn):
        os.unlink(fn)
    if content is not None:
        f = open(fn, 'wb')
        f.write(content)
        f.close()
    return fn
    
def test_logger():
    fn = setup_file('test_logger.log')
    rep = LogReporter(
        filename=fn,
        show_hidden_frames=False)
    try:
        int('a')
    except:
        exc_data = collector.collect_exception(*sys.exc_info())
    else:
        assert 0
    rep.report(exc_data)
    content = open(fn).read()
    assert len(content.splitlines()) == 4
    assert 'ValueError' in content
    assert 'int' in content
    assert 'test_reporter.py' in content
    assert 'test_logger' in content
    
    try:
        1 / 0
    except:
        exc_data = collector.collect_exception(*sys.exc_info())
    else:
        assert 0
    rep.report(exc_data)
    content = open(fn).read()
    print content
    assert len(content.splitlines()) == 8
    assert 'ZeroDivisionError' in content