diff options
author | matt <matt@xcolour.net> | 2013-01-28 11:32:18 -0500 |
---|---|---|
committer | matt <matt@xcolour.net> | 2013-01-28 11:32:18 -0500 |
commit | 1afcb52d73271bbbd78f885451aa1b0e78c09871 (patch) | |
tree | 9145840d6036fcbc0b6647c88f679a567fa8c54d /tests/test_exceptions/test_reporter.py | |
download | paste-git-stringio.tar.gz |
Import StringIO so it can be used.stringio
Diffstat (limited to 'tests/test_exceptions/test_reporter.py')
-rw-r--r-- | tests/test_exceptions/test_reporter.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/test_exceptions/test_reporter.py b/tests/test_exceptions/test_reporter.py new file mode 100644 index 0000000..8f4dc7a --- /dev/null +++ b/tests/test_exceptions/test_reporter.py @@ -0,0 +1,50 @@ +import sys +import os +from paste.exceptions.reporter import * +from paste.exceptions import collector + +def setup_file(fn, content=None): + dir = os.path.join(os.path.dirname(__file__), 'reporter_output') + fn = os.path.join(dir, fn) + if os.path.exists(dir): + if os.path.exists(fn): + os.unlink(fn) + else: + os.mkdir(dir) + 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, len(content.splitlines()) + 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 + |