diff --git a/tests/__init__.py b/tests/__init__.py index 547e947..6c4d60c 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,38 +1,6 @@ import os import sys -import warnings sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), '../src')) -class _AssertWarnsContext(object): - def __init__(self, warningtype, testcase, msg=''): - self.warningtype = warningtype - warnings.filterwarnings('error') - self.failureException = testcase.failureException - - def __enter__(self): - return self - - def __exit__(self, exc_type, exc_value, tb): - if exc_type is None: - try: - exc_name = self.warningtype.__name__ - except AttributeError: - exc_name = str(self.warningtype) - raise self.failureException( - "{0} not raised".format(exc_name)) - - if not issubclass(exc_type, self.warningtype): - raise self.failureException('"%s" does not match "%s"' % - (self.warningtype.__name__, str(exc_type.__name__))) - - return True - -class CatchWarningsMixin(object): - def assertWarns(self, wrnClass, callableObj=None, *args, **kwargs): - context = _AssertWarnsContext(wrnClass, self) - if callableObj is None: - return context - with context: - callableObj(*args, **kwargs) diff --git a/tests/mixins.py b/tests/mixins.py new file mode 100644 index 0000000..49add16 --- /dev/null +++ b/tests/mixins.py @@ -0,0 +1,35 @@ +import warnings + +__unittest=True + +class _AssertWarnsContext(object): + def __init__(self, warningtype, testcase, msg=''): + self.warningtype = warningtype + warnings.filterwarnings('error') + self.failureException = testcase.failureException + + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_value, tb): + if exc_type is None: + try: + exc_name = self.warningtype.__name__ + except AttributeError: + exc_name = str(self.warningtype) + raise self.failureException( + "{0} not raised".format(exc_name)) + + if not issubclass(exc_type, self.warningtype): + raise self.failureException('"%s" does not match "%s"' % + (self.warningtype.__name__, str(exc_type.__name__))) + + return True + +class CatchWarningsMixin(object): + def assertWarns(self, wrnClass, callableObj=None, *args, **kwargs): + context = _AssertWarnsContext(wrnClass, self) + if callableObj is None: + return context + with context: + callableObj(*args, **kwargs) diff --git a/tests/test_distgit.py b/tests/test_distgit.py index 1cc9a9d..4081522 100644 --- a/tests/test_distgit.py +++ b/tests/test_distgit.py @@ -1,7 +1,6 @@ import unittest - -from . import CatchWarningsMixin +from mixins import CatchWarningsMixin from centpkg import DistGitDirectory class TestDistGitNothing(unittest.TestCase):