mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-31 22:35:35 +00:00
parser testlib - write_file() argument adjustments
This patch modifies testlib.write_file() to take a directory and a file name instead of a path and return the joined result for callers to use if necessary. Signed-off-by: Steve Beattie <steve@nxnw.org> Acked-by: Christian Boltz <apparmor@cboltz.de>
This commit is contained in:
@@ -59,8 +59,7 @@ class AAParserCachingCommon(testlib.AATestTemplate):
|
|||||||
os.mkdir(self.cache_dir)
|
os.mkdir(self.cache_dir)
|
||||||
|
|
||||||
# write our sample profile out
|
# write our sample profile out
|
||||||
self.profile = os.path.join(self.tmp_dir, PROFILE)
|
self.profile = testlib.write_file(self.tmp_dir, PROFILE, PROFILE_CONTENTS)
|
||||||
testlib.write_file(self.profile, PROFILE_CONTENTS)
|
|
||||||
|
|
||||||
if config.debug:
|
if config.debug:
|
||||||
self.do_cleanup = False
|
self.do_cleanup = False
|
||||||
@@ -256,7 +255,7 @@ class AAParserCachingTests(AAParserCachingCommon):
|
|||||||
|
|
||||||
self._generate_cache_file()
|
self._generate_cache_file()
|
||||||
|
|
||||||
testlib.write_file(os.path.join(self.cache_dir, '.features'), 'monkey\n')
|
testlib.write_file(self.cache_dir, '.features', 'monkey\n')
|
||||||
|
|
||||||
cmd = list(self.cmd_prefix)
|
cmd = list(self.cmd_prefix)
|
||||||
cmd.extend(['-v', '-r', self.profile])
|
cmd.extend(['-v', '-r', self.profile])
|
||||||
@@ -266,8 +265,7 @@ class AAParserCachingTests(AAParserCachingCommon):
|
|||||||
def test_cache_writing_does_not_overwrite_features_when_features_differ(self):
|
def test_cache_writing_does_not_overwrite_features_when_features_differ(self):
|
||||||
'''test cache writing does not overwrite the features files when it differs and --skip-bad-cache is given'''
|
'''test cache writing does not overwrite the features files when it differs and --skip-bad-cache is given'''
|
||||||
|
|
||||||
features_file = os.path.join(self.cache_dir, '.features')
|
features_file = testlib.write_file(self.cache_dir, '.features', 'monkey\n')
|
||||||
testlib.write_file(features_file, 'monkey\n')
|
|
||||||
|
|
||||||
cmd = list(self.cmd_prefix)
|
cmd = list(self.cmd_prefix)
|
||||||
cmd.extend(['-v', '--write-cache', '--skip-bad-cache', '-r', self.profile])
|
cmd.extend(['-v', '--write-cache', '--skip-bad-cache', '-r', self.profile])
|
||||||
@@ -280,7 +278,7 @@ class AAParserCachingTests(AAParserCachingCommon):
|
|||||||
def test_cache_writing_skipped_when_features_differ(self):
|
def test_cache_writing_skipped_when_features_differ(self):
|
||||||
'''test cache writing is skipped when features file differs'''
|
'''test cache writing is skipped when features file differs'''
|
||||||
|
|
||||||
testlib.write_file(os.path.join(self.cache_dir, '.features'), 'monkey\n')
|
testlib.write_file(self.cache_dir, '.features', 'monkey\n')
|
||||||
|
|
||||||
cmd = list(self.cmd_prefix)
|
cmd = list(self.cmd_prefix)
|
||||||
cmd.extend(['-v', '--write-cache', '--skip-bad-cache', '-r', self.profile])
|
cmd.extend(['-v', '--write-cache', '--skip-bad-cache', '-r', self.profile])
|
||||||
@@ -291,8 +289,7 @@ class AAParserCachingTests(AAParserCachingCommon):
|
|||||||
def test_cache_writing_updates_features(self):
|
def test_cache_writing_updates_features(self):
|
||||||
'''test cache writing updates features'''
|
'''test cache writing updates features'''
|
||||||
|
|
||||||
features_file = os.path.join(self.cache_dir, '.features')
|
features_file = testlib.write_file(self.cache_dir, '.features', 'monkey\n')
|
||||||
testlib.write_file(features_file, 'monkey\n')
|
|
||||||
|
|
||||||
cmd = list(self.cmd_prefix)
|
cmd = list(self.cmd_prefix)
|
||||||
cmd.extend(['-v', '--write-cache', '-r', self.profile])
|
cmd.extend(['-v', '--write-cache', '-r', self.profile])
|
||||||
@@ -304,8 +301,7 @@ class AAParserCachingTests(AAParserCachingCommon):
|
|||||||
def test_cache_writing_updates_cache_file(self):
|
def test_cache_writing_updates_cache_file(self):
|
||||||
'''test cache writing updates cache file'''
|
'''test cache writing updates cache file'''
|
||||||
|
|
||||||
cache_file = os.path.join(self.cache_dir, PROFILE)
|
cache_file = testlib.write_file(self.cache_dir, PROFILE, 'monkey\n')
|
||||||
testlib.write_file(cache_file, 'monkey\n')
|
|
||||||
orig_size = os.stat(cache_file).st_size
|
orig_size = os.stat(cache_file).st_size
|
||||||
|
|
||||||
cmd = list(self.cmd_prefix)
|
cmd = list(self.cmd_prefix)
|
||||||
@@ -323,8 +319,7 @@ class AAParserCachingTests(AAParserCachingCommon):
|
|||||||
def test_cache_writing_clears_all_files(self):
|
def test_cache_writing_clears_all_files(self):
|
||||||
'''test cache writing clears all cache files'''
|
'''test cache writing clears all cache files'''
|
||||||
|
|
||||||
check_file = os.path.join(self.cache_dir, 'monkey')
|
check_file = testlib.write_file(self.cache_dir, 'monkey', 'monkey\n')
|
||||||
testlib.write_file(check_file, 'monkey\n')
|
|
||||||
|
|
||||||
cmd = list(self.cmd_prefix)
|
cmd = list(self.cmd_prefix)
|
||||||
cmd.extend(['-v', '--write-cache', '-r', self.profile])
|
cmd.extend(['-v', '--write-cache', '-r', self.profile])
|
||||||
@@ -362,8 +357,7 @@ class AAParserCachingTests(AAParserCachingCommon):
|
|||||||
|
|
||||||
def _purge_cache_test(self, location):
|
def _purge_cache_test(self, location):
|
||||||
|
|
||||||
cache_file = os.path.join(self.cache_dir, location)
|
cache_file = testlib.write_file(self.cache_dir, location, 'monkey\n')
|
||||||
testlib.write_file(cache_file, 'monkey\n')
|
|
||||||
|
|
||||||
cmd = list(self.cmd_prefix)
|
cmd = list(self.cmd_prefix)
|
||||||
cmd.extend(['-v', '--purge-cache', '-r', self.profile])
|
cmd.extend(['-v', '--purge-cache', '-r', self.profile])
|
||||||
@@ -415,7 +409,7 @@ class AAParserAltCacheTests(AAParserCachingTests):
|
|||||||
filelist = [PROFILE, '.features', 'monkey']
|
filelist = [PROFILE, '.features', 'monkey']
|
||||||
|
|
||||||
for f in filelist:
|
for f in filelist:
|
||||||
testlib.write_file(os.path.join(self.orig_cache_dir, f), 'monkey\n')
|
testlib.write_file(self.orig_cache_dir, f, 'monkey\n')
|
||||||
|
|
||||||
self._purge_cache_test(PROFILE)
|
self._purge_cache_test(PROFILE)
|
||||||
|
|
||||||
|
@@ -165,10 +165,12 @@ def touch(path):
|
|||||||
return os.utime(path, None)
|
return os.utime(path, None)
|
||||||
|
|
||||||
|
|
||||||
def write_file(path, contents):
|
def write_file(directory, file, contents):
|
||||||
'''write contents to path'''
|
'''construct path, write contents to it, and return the constructed path'''
|
||||||
|
path = os.path.join(directory, file)
|
||||||
with open(path, 'w+') as f:
|
with open(path, 'w+') as f:
|
||||||
f.write(contents)
|
f.write(contents)
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
def keep_on_fail(unittest_func):
|
def keep_on_fail(unittest_func):
|
||||||
|
Reference in New Issue
Block a user