[apparmor] [patch] add better loop support to common_test.py

Steve Beattie steve at nxnw.org
Tue Mar 31 08:43:12 UTC 2015


On Fri, Mar 06, 2015 at 11:57:11PM +0100, Christian Boltz wrote:
> Here's v3, this time with the number included in the filename ;-)
> 
> 
> [ 07-common_test_better_loop_support.diff ]

Oh, one other comment:

> === modified file 'utils/test/common_test.py'
> --- utils/test/common_test.py   2014-11-06 20:32:49 +0000
> +++ utils/test/common_test.py   2015-03-03 23:37:48 +0000
> +def setup_tests_loop(test_class):
> +    '''Create tests in test_class using test_class.tests and self._run_test()
> +
> +    test_class.tests should be tuples of (test_data, expected_results)
> +    test_data and expected_results can be of any type as long as test_class._run_test()
> +    know how to handle them.
> +
> +    A typical definition for _run_test() is:
> +        def test_class._run_test(self, test_data, expected)
> +        '''
> +
> +    for (i, (test_data, expected)) in enumerate(test_class.tests):
> +        def stub_test(self, test_data=test_data, expected=expected):
> +            self._run_test(test_data, expected)
> +
> +        stub_test.__doc__ = "test '%s'" % (test_data)
> +        setattr(test_class, 'test_%d' % (i), stub_test)

It'd kind of be nice to support an optional third tuple item that's
used as the __doc__ string for the function, if it's present. I also
wonder about only allowing _run_test() to take two arguments being
limiting somehow in test construction, but perhaps we can work around
it by passing complex data structures as the test_data.

-- 
Steve Beattie
<sbeattie at ubuntu.com>
http://NxNW.org/~steve/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20150331/dbff4140/attachment-0001.pgp>


More information about the AppArmor mailing list