[apparmor] [patch] enable testloops for nosetests
Christian Boltz
apparmor at cboltz.de
Thu Apr 2 21:19:29 UTC 2015
Hello,
this patch ensures nosetests sees all tests in the tests[] tuples. This
requires some name changes because nosetests thinks all function names
containing "test" are tests. (A "not a test" docorator would be an
alternative, but that would require some try/except magic to avoid a
dependency on nose.)
To avoid nosetests thinks the functions are a test,
- rename setup_all_tests() to setup_all_loops()
- rename regex_test() to _regex_test() (in test-regex_matches.py)
Also add the module_name as parameter to setup_all_loops and always run
it (not only if __name__ == '__main__').
Known issue: nosetests errors out with
ValueError: no such test method in <class ...>: stub_test
when trying to run a single test generated out of tests[].
(debugging hint: stub_test is the name used in setup_test_loop().)
But that's still an improvement over not seeing those tests at all ;-)
Again, I propose this patch for trunk and 2.9.
[ 31-enable-testloops-for-nosetests.diff ]
=== modified file utils/test/common_test.py
--- utils/test/common_test.py 2015-03-31 15:14:17.340896455 +0200
+++ utils/test/common_test.py 2015-04-02 22:56:33.673799305 +0200
@@ -51,10 +51,9 @@
'parse object %s returned "%s", expected "%s"' \
%(self.parse_function.__doc__, parsed.serialize(), rule))
-
-def setup_all_tests():
+def setup_all_loops(module_name):
'''call setup_tests_loop() for each class in module_name'''
- for name, obj in inspect.getmembers(sys.modules['__main__']):
+ for name, obj in inspect.getmembers(sys.modules[module_name]):
if inspect.isclass(obj):
if issubclass(obj, unittest.TestCase):
setup_tests_loop(obj)
=== modified file utils/test/test-aa.py
--- utils/test/test-aa.py 2015-04-02 22:29:43.179349354 +0200
+++ utils/test/test-aa.py 2015-04-02 22:53:04.753079748 +0200
@@ -10,7 +10,7 @@
# ------------------------------------------------------------------
import unittest
-from common_test import AATest, setup_all_tests
+from common_test import AATest, setup_all_loops
import os
import shutil
import tempfile
@@ -476,6 +476,6 @@
serialize_parse_profile_start(line, 'somefile', 1, profile, hat, prof_data_profile, prof_data_external, True)
+setup_all_loops(__name__)
if __name__ == '__main__':
- setup_all_tests()
unittest.main(verbosity=2)
=== modified file utils/test/test-example.py
--- utils/test/test-example.py 2015-04-02 11:44:42.194482000 +0200
+++ utils/test/test-example.py 2015-04-02 22:52:18.913774868 +0200
@@ -10,7 +10,7 @@
# ------------------------------------------------------------------
import unittest
-from common_test import AATest, setup_all_tests
+from common_test import AATest, setup_all_loops
class TestFoo(AATest):
tests = [
@@ -40,6 +40,6 @@
+setup_all_loops(__name__)
if __name__ == '__main__':
- setup_all_tests()
unittest.main(verbosity=2)
=== modified file utils/test/test-regex_matches.py
--- utils/test/test-regex_matches.py 2015-04-02 22:29:43.061356247 +0200
+++ utils/test/test-regex_matches.py 2015-04-02 22:55:41.328875700 +0200
@@ -11,7 +11,7 @@
import apparmor.aa as aa
import unittest
-from common_test import AATest, setup_all_tests
+from common_test import AATest, setup_all_loops
from apparmor.common import AppArmorBug
from apparmor.regex import strip_quotes, parse_profile_start_line, RE_PROFILE_START
@@ -19,7 +19,7 @@
class AARegexTest(AATest):
def _run_test(self, params, expected):
- return regex_test(self, params, expected)
+ return _regex_test(self, params, expected)
class AANamedRegexTest(AATest):
def _run_test(self, line, expected):
@@ -173,7 +173,7 @@
setattr(AARegexSplitComment, 'test_split_comment_%d' % (i), stub_test)
-def regex_test(self, line, expected):
+def _regex_test(self, line, expected):
'''Run a line through self.regex.search() and verify the result
Keyword arguments:
@@ -484,10 +484,10 @@
+setup_all_loops(__name__)
if __name__ == '__main__':
# these two are not converted to a tests[] loop yet
setup_has_comma_testcases()
setup_split_comment_testcases()
- setup_all_tests()
unittest.main(verbosity=2)
Regards,
Christian Boltz
--
Eine Katze hat einen Schwanz mehr als keine Katze. Keine Katze hat
zwei Schwänze, also hat eine Katze drei Schwänze.
[Bernd Brodesser in suse-linux]
More information about the AppArmor
mailing list