From 4b1323af17f144724d5ca0c8c35f1aa5253655f6 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Thu, 30 Jun 2011 18:15:26 +0200 Subject: Secure removal of the temp file used by the testing suite --- test/test.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'test/test.py') diff --git a/test/test.py b/test/test.py index f095157..f856394 100644 --- a/test/test.py +++ b/test/test.py @@ -6,6 +6,7 @@ ''' import shutil +import os import glob import sys import tempfile @@ -18,14 +19,18 @@ FILE_LIST = zip(glob.glob('clean*'), glob.glob('dirty*')) class MATTest(unittest.TestCase): def setUp(self): '''create working copy of the clean and the dirty file in the TMP dir''' - self.file_list = [] - self.tmpdir = tempfile.mkdtemp() + self.file_list = [] + self.tmpdir = tempfile.mkdtemp() - for clean, dirty in FILE_LIST: - shutil.copy2(clean, self.tmpdir + clean) - shutil.copy2(dirty, self.tmpdir + dirty) - self.file_list.append((self.tmpdir + clean, self.tmpdir + dirty)) + for clean, dirty in FILE_LIST: + shutil.copy2(clean, self.tmpdir + clean) + shutil.copy2(dirty, self.tmpdir + dirty) + self.file_list.append((self.tmpdir + clean, self.tmpdir + dirty)) def tearDown(self): '''Remove the tmp folder''' - shutil.rmtree(self.tmpdir) + for root, dirs, files in os.walk(self.tmpdir, topdown=False): + for name in files: + mat.secure_remove(os.path.join(toor, name)) + for name in dirs: + os.rmdir(os.path.join(root, name)) -- cgit v1.3