[apparmor] [patch] Move str_to_mode() tests to test-aamode.py
Christian Boltz
apparmor at cboltz.de
Tue Oct 11 20:39:22 UTC 2016
Hello,
Am Dienstag, 11. Oktober 2016, 12:39:58 CEST schrieb Seth Arnold:
> On Sun, Oct 09, 2016 at 08:32:48PM +0200, Christian Boltz wrote:
> > +class AamodeTest_str_to_mode(AATest):
> > + tests = [
> > + ('x', apparmor.aamode.AA_MAY_EXEC),
> > + ('w', apparmor.aamode.AA_MAY_WRITE),
> I didn't find where this 'tests' array is actually used in the patch.
>
> Also, 'tests' is a bit generic -- is there a better description of
> what this array mapping actually provides?
It always needs to be named "tests" because this is expected by other
code, see below. However, the class name should tell what it's about.
> A dictionary would allow quicker lookups from key to value; an array
> makes more sense if it's only ever iterated, or if lookups can go both
> directions. But since I didn't find any use of this array it's hard
> to guess which would be better. :)
Is this the first time you read a test-*.py file? ;-)
I'm using these tests[] arrays since 2015-03-31 (r2976)...
Short version:
Each item of tests[] contains a pair of params, expected
and these get passed to _run_test().
Long version:
The most interesting detail is that test-*.py calls
setup_all_loops(__name__) before running unittest.main().
Now have a look at common_test.py.
setup_all_loops() calls setup_tests_loop() for all test classes it finds.
setup_tests_loop() then looks at the tests[] array and creates a
test_NN() [1] function for each (params, expected) pair in tests[].
Back to test-*.py: unittest.main() will run all tests - including the
test_NN() functions added by setup_all_loops().
If you want to study this in a simplified setup, have a look at
test-example.py which contains some dummy tests.
BTW: The test classes in test-*.py are based on AATest [2] (which
extends unittest.TestCase with some useful functions like tempdir
handling) - but that's not relevant for the tests[] array.
Regards,
Christian Boltz
[1] "NN" is a serial number for each item in tests[]
[2] For historical reasons, test-aa-decode.py, test-aa-easyprof.py,
test-config.py and test-logparser.py still use unittest.TestCase.
I usually migrate them when I need to add the first tests[] array,
but I won't object if you do that migration now ;-)
--
dies ist aber nur meine ganz persönliche Meinung, welche aber Spuren
von Erfahrungswerten enthalten kann ;) [Markus Heinze in opensuse-de]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: This is a digitally signed message part.
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20161011/f93b7c28/attachment.pgp>
More information about the AppArmor
mailing list