Add TestCase assertion methods for testing checks

This patch adds assertCheckPasses and assertCheckFails methods to make
it easier to write tests for more complicated checks that we want to
add.

We rely on checks being generators at this point, meaning this will not
work on flake8 class based plugins.

Change-Id: I37ecec271006084211e37c4fc9c89d71df01dc97
This commit is contained in:
Nikola Dipanov 2014-04-29 11:36:59 +02:00
parent 316a9e511c
commit 03c62a6474

View File

@ -43,3 +43,16 @@ class TestCase(testtools.TestCase):
if os.environ.get('OS_STDERR_CAPTURE') in _TRUE_VALUES:
stderr = self.useFixture(fixtures.StringStream('stderr')).stream
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
def assertCheckFails(self, check_func, *args, **kwargs):
if not list(check_func(*args, **kwargs)):
raise AssertionError("Check %s did not fail." %
check_func.__name__)
def assertCheckPasses(self, check_func, *args, **kwargs):
try:
self.assertCheckFails(check_func, *args, **kwargs)
except AssertionError:
return
else:
raise AssertionError("Check %s failed." % check_func.__name__)