[apparmor] [patch] simplify setup_all_tests() call in utils test

Seth Arnold seth.arnold at canonical.com
Wed Mar 4 23:15:26 UTC 2015


On Thu, Mar 05, 2015 at 12:06:06AM +0100, Christian Boltz wrote:
> Hello,
> 
> this patch simplifies the setup_all_tests() call and avoids that every
> test needs to import sys.
> 
> The patch applies on top of my previous patches, and as usual, I 
> propose it for trunk and 2.9.

I don't this I like this one much it feels like it is increasing the
coupling between modules / files without any obvious benefits.

Which standard tool didn't work before that now works, or whst other
problem is being solved?

Thanks

> 
> 
> [ test-loop-simplify.diff ]
> 
> diff -u -p -r ../HEAD-patches-applied/utils/test/common_test.py utils/test/common_test.py
> --- utils/test/common_test.py   2015-03-04 23:40:36.989571615 +0100
> +++ utils/test/common_test.py   2015-03-04 23:59:16.293444334 +0100
> @@ -16,6 +16,7 @@ import unittest
>  import inspect
>  import os
>  import re
> +import sys
>  
>  import apparmor.common
>  import apparmor.config
> @@ -51,9 +52,9 @@ class AAParseTest(unittest.TestCase):
>              %(self.parse_function.__doc__, parsed.serialize(), rule))
>  
>  
> -def setup_all_tests(module_name):
> +def setup_all_tests():
>      '''call setup_tests_loop() for each class in module_name'''
> -    for name, obj in inspect.getmembers(module_name):
> +    for name, obj in inspect.getmembers(sys.modules['__main__']):
>          if inspect.isclass(obj) and (isinstance(obj(), unittest.TestCase)):
>              setup_tests_loop(obj)
>  
> diff -u -p -r ../HEAD-patches-applied/utils/test/test-example.py utils/test/test-example.py
> --- utils/test/test-example.py  2015-03-04 23:40:36.989571615 +0100
> +++ utils/test/test-example.py  2015-03-05 00:00:55.532573628 +0100
> @@ -10,7 +10,6 @@
>  # ------------------------------------------------------------------
>  
>  import unittest
> -import sys
>  from common_test import AATest, setup_all_tests
>  
>  class TestFoo(AATest):
> @@ -42,5 +41,5 @@ class TestBaz(AATest):
>  
>  
>  if __name__ == '__main__':
> -    setup_all_tests(sys.modules[__name__])
> +    setup_all_tests()
>      unittest.main(verbosity=2)
> diff -u -p -r ../HEAD-patches-applied/utils/test/test-regex_matches.py utils/test/test-regex_matches.py
> --- utils/test/test-regex_matches.py    2015-03-04 23:40:37.099565168 +0100
> +++ utils/test/test-regex_matches.py    2015-03-05 00:01:00.070305085 +0100
> @@ -11,7 +11,6 @@
>  
>  import apparmor.aa as aa
>  import unittest
> -import sys
>  from common_test import AATest, setup_all_tests
>  from apparmor.common import AppArmorBug
>  
> @@ -489,5 +538,5 @@ if __name__ == '__main__':
>      setup_has_comma_testcases()
>      setup_split_comment_testcases()
>  
> -    setup_all_tests(sys.modules[__name__])
> +    setup_all_tests()
>      unittest.main(verbosity=2)
> 
> 
> Regards,
> 
> Christian Boltz
> -- 
> > [Verpackungsidee für SUSE Linux] Dazu vielleicht noch die
> > "Super-Turbo-Schickimiki-Gold-Edition" mit extra eingepackten
> > vergoldeten CDs, in einer Naturholzschatulle mit Messingbeschlag für
> > kostenintensive 250 Euronen für den eingebildeten Geldsack.
> Aber dann bitte mit eingeschnitztem Pinguin auf der Vorderseite und
> Chamäleon auf der Rückseite. :-)
> [> Andreas Graf und Bernhard Walle in suse-linux]
> 
> 
> -- 
> AppArmor mailing list
> AppArmor at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/apparmor
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20150304/181e43b0/attachment-0001.pgp>


More information about the AppArmor mailing list