[apparmor] [patch] simplify setup_all_tests() call in utils test
Christian Boltz
apparmor at cboltz.de
Wed Mar 4 23:06:06 UTC 2015
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.
[ 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]
More information about the AppArmor
mailing list