lrossett / centos / centpkg

Forked from centos/centpkg 2 years ago
Clone
c0555c
import os
c0555c
import sys
5becc4
import unittest
5becc4
import warnings
c0555c
c0555c
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)),
c0555c
                                '../src'))
5becc4
5becc4
class CatchWarningsMixin(object):
5becc4
    class assertWarns(object):
5becc4
        def __init__(self, warningtype, msg=''):
5becc4
            self.warningtype = warningtype
5becc4
            warnings.filterwarnings('error')
5becc4
            self.failureException = unittest.TestCase.failureException
5becc4
5becc4
        def __enter__(self):
5becc4
            return self
5becc4
5becc4
        def __exit__(self, exc_type, exc_value, tb):
5becc4
            if exc_type is None:
5becc4
                try:
5becc4
                    exc_name = self.warningtype.__name__
5becc4
                except AttributeError:
5becc4
                    exc_name = str(self.warningtype)
5becc4
                raise self.failureException(
5becc4
                    "{0} not raised".format(exc_name))
5becc4
5becc4
            if not issubclass(exc_type, self.warningtype):
5becc4
                raise self.failureException('"%s" does not match "%s"' %
5becc4
                     (self.warningtype.__name__, str(exc_type.__name__)))
5becc4
5becc4
            return True