mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-10-13 14:06:11 +00:00
utils: re-work the severity.db unit tests
This patch is a re-work of the severity_test.py tests, to break them up into individual unit tests, and to add coverage for detecting an invalid severity database (it does reduce the coverage for walking profiles to find variable declarations, but that should be pulled out of the severity handling code anyway). Note that the last test case will fail, because even though the code path in Severity.__init__() looks like it will return None if no path is given, a Severity object in a half-state of initialization will actually be returned. Signed-off-by: Steve Beattie <steve@nxnw.org> Acked-by: Christian Boltz <apparmor@cboltz.de>
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#
|
||||
# ----------------------------------------------------------------------
|
||||
import unittest
|
||||
import os
|
||||
import re
|
||||
|
||||
import apparmor.common
|
||||
@@ -55,6 +56,13 @@ def setup_regex_tests(test_class):
|
||||
stub_test.__doc__ = "test '%s': %s" % (line, desc)
|
||||
setattr(test_class, 'test_%d' % (i), stub_test)
|
||||
|
||||
def write_file(directory, file, contents):
|
||||
'''construct path, write contents to it, and return the constructed path'''
|
||||
path = os.path.join(directory, file)
|
||||
with open(path, 'w+') as f:
|
||||
f.write(contents)
|
||||
return path
|
||||
|
||||
if __name__ == "__main__":
|
||||
#import sys;sys.argv = ['', 'Test.test_RegexParser']
|
||||
unittest.main()
|
||||
|
Reference in New Issue
Block a user