Make it possible to call custom functions in Declarative tests

Sometimes, we will want to do more than just call IPA commands and
check the output. This patch makes it possible to add arbitrary
functions to Declarative tests. They will be called as part of
the sequence of tests.

Reviewed-By: Martin Kosek <mkosek@redhat.com>
This commit is contained in:
Petr Viktorin 2013-09-13 16:08:22 +02:00
parent 2f3ab2914a
commit eb14f99ece

View File

@ -278,11 +278,18 @@ class Declarative(XMLRPC_test):
# Iterate through the tests: # Iterate through the tests:
name = self.__class__.__name__ name = self.__class__.__name__
for (i, test) in enumerate(self.tests): for (i, test) in enumerate(self.tests):
nice = '%s[%d]: %s: %s' % ( if callable(test):
name, i, test['command'][0], test.get('desc', '') func = lambda: test(self)
) nice = '%s[%d]: call %s: %s' % (
func = lambda: self.check(nice, **test) name, i, test.__name__, test.__doc__
func.description = nice )
func.description = nice
else:
nice = '%s[%d]: %s: %s' % (
name, i, test['command'][0], test.get('desc', '')
)
func = lambda: self.check(nice, **test)
func.description = nice
yield (func,) yield (func,)
# Iterate through post-cleanup: # Iterate through post-cleanup: