mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-09-01 14:55:10 +00:00
Enable testloops for nosetests
Ensure 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 ;-) Acked-by: Steve Beattie <steve@nxnw.org> for trunk and 2.9.
This commit is contained in:
@@ -51,10 +51,9 @@ class AAParseTest(unittest.TestCase):
|
|||||||
'parse object %s returned "%s", expected "%s"' \
|
'parse object %s returned "%s", expected "%s"' \
|
||||||
%(self.parse_function.__doc__, parsed.serialize(), rule))
|
%(self.parse_function.__doc__, parsed.serialize(), rule))
|
||||||
|
|
||||||
|
def setup_all_loops(module_name):
|
||||||
def setup_all_tests():
|
|
||||||
'''call setup_tests_loop() for each class in 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 inspect.isclass(obj):
|
||||||
if issubclass(obj, unittest.TestCase):
|
if issubclass(obj, unittest.TestCase):
|
||||||
setup_tests_loop(obj)
|
setup_tests_loop(obj)
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from common_test import AATest, setup_all_tests
|
from common_test import AATest, setup_all_loops
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
@@ -536,6 +536,6 @@ class AaTestInvalid_serialize_parse_profile_start(AATest):
|
|||||||
serialize_parse_profile_start(line, 'somefile', 1, profile, hat, prof_data_profile, prof_data_external, True)
|
serialize_parse_profile_start(line, 'somefile', 1, profile, hat, prof_data_profile, prof_data_external, True)
|
||||||
|
|
||||||
|
|
||||||
|
setup_all_loops(__name__)
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
setup_all_tests()
|
|
||||||
unittest.main(verbosity=2)
|
unittest.main(verbosity=2)
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from common_test import AATest, setup_all_tests
|
from common_test import AATest, setup_all_loops
|
||||||
|
|
||||||
class TestFoo(AATest):
|
class TestFoo(AATest):
|
||||||
tests = [
|
tests = [
|
||||||
@@ -40,6 +40,6 @@ class TestBaz(AATest):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
setup_all_loops(__name__)
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
setup_all_tests()
|
|
||||||
unittest.main(verbosity=2)
|
unittest.main(verbosity=2)
|
||||||
|
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
import apparmor.aa as aa
|
import apparmor.aa as aa
|
||||||
import unittest
|
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.common import AppArmorBug
|
||||||
|
|
||||||
from apparmor.regex import strip_quotes, parse_profile_start_line, RE_PROFILE_START
|
from apparmor.regex import strip_quotes, parse_profile_start_line, RE_PROFILE_START
|
||||||
@@ -19,7 +19,7 @@ from apparmor.regex import strip_quotes, parse_profile_start_line, RE_PROFILE_ST
|
|||||||
|
|
||||||
class AARegexTest(AATest):
|
class AARegexTest(AATest):
|
||||||
def _run_test(self, params, expected):
|
def _run_test(self, params, expected):
|
||||||
return regex_test(self, params, expected)
|
return _regex_test(self, params, expected)
|
||||||
|
|
||||||
class AANamedRegexTest(AATest):
|
class AANamedRegexTest(AATest):
|
||||||
def _run_test(self, line, expected):
|
def _run_test(self, line, expected):
|
||||||
@@ -173,7 +173,7 @@ def setup_split_comment_testcases():
|
|||||||
setattr(AARegexSplitComment, 'test_split_comment_%d' % (i), stub_test)
|
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
|
'''Run a line through self.regex.search() and verify the result
|
||||||
|
|
||||||
Keyword arguments:
|
Keyword arguments:
|
||||||
@@ -484,10 +484,10 @@ class TestStripQuotes(AATest):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
setup_all_loops(__name__)
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# these two are not converted to a tests[] loop yet
|
# these two are not converted to a tests[] loop yet
|
||||||
setup_has_comma_testcases()
|
setup_has_comma_testcases()
|
||||||
setup_split_comment_testcases()
|
setup_split_comment_testcases()
|
||||||
|
|
||||||
setup_all_tests()
|
|
||||||
unittest.main(verbosity=2)
|
unittest.main(verbosity=2)
|
||||||
|
Reference in New Issue
Block a user