2010-12-22 02:09:04 +02:00

48 lines
1.6 KiB
Python

# Test suite for ubuntutools
#
# Copyright (C) 2010, Stefano Rivera <stefanor@ubuntu.com>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
import logging
import os
import sys
if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest
def discover():
# import __main__ triggers code re-execution
__main__ = sys.modules['__main__']
setupDir = os.path.abspath(os.path.dirname(__main__.__file__))
return unittest.defaultTestLoader.discover(setupDir)
class LoggingCatcher(logging.Handler):
def __init__(self):
logging.Handler.__init__(self)
self.m = {'critical': [],
'error': [],
'warning': [],
'info': [],
'debug': [],
'notset': []}
def emit(self, record):
self.m[record.levelname.lower()].append(record.getMessage())
def __getitem__(self, key):
return self.m[key]