diff options
| author | jvoisin | 2011-06-30 18:15:26 +0200 |
|---|---|---|
| committer | jvoisin | 2011-06-30 18:15:26 +0200 |
| commit | 4b1323af17f144724d5ca0c8c35f1aa5253655f6 (patch) | |
| tree | 48cdf2b7eb4d60e0a82d4d828a16ee707c54c957 /test/test.py | |
| parent | a62aab0c52c0826097f2f883c9c9aa8f9b66a5e8 (diff) | |
Secure removal of the temp file used by the testing suite
Diffstat (limited to 'test/test.py')
| -rw-r--r-- | test/test.py | 19 |
1 files changed, 12 insertions, 7 deletions
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 @@ | |||
| 6 | ''' | 6 | ''' |
| 7 | 7 | ||
| 8 | import shutil | 8 | import shutil |
| 9 | import os | ||
| 9 | import glob | 10 | import glob |
| 10 | import sys | 11 | import sys |
| 11 | import tempfile | 12 | import tempfile |
| @@ -18,14 +19,18 @@ FILE_LIST = zip(glob.glob('clean*'), glob.glob('dirty*')) | |||
| 18 | class MATTest(unittest.TestCase): | 19 | class MATTest(unittest.TestCase): |
| 19 | def setUp(self): | 20 | def setUp(self): |
| 20 | '''create working copy of the clean and the dirty file in the TMP dir''' | 21 | '''create working copy of the clean and the dirty file in the TMP dir''' |
| 21 | self.file_list = [] | 22 | self.file_list = [] |
| 22 | self.tmpdir = tempfile.mkdtemp() | 23 | self.tmpdir = tempfile.mkdtemp() |
| 23 | 24 | ||
| 24 | for clean, dirty in FILE_LIST: | 25 | for clean, dirty in FILE_LIST: |
| 25 | shutil.copy2(clean, self.tmpdir + clean) | 26 | shutil.copy2(clean, self.tmpdir + clean) |
| 26 | shutil.copy2(dirty, self.tmpdir + dirty) | 27 | shutil.copy2(dirty, self.tmpdir + dirty) |
| 27 | self.file_list.append((self.tmpdir + clean, self.tmpdir + dirty)) | 28 | self.file_list.append((self.tmpdir + clean, self.tmpdir + dirty)) |
| 28 | 29 | ||
| 29 | def tearDown(self): | 30 | def tearDown(self): |
| 30 | '''Remove the tmp folder''' | 31 | '''Remove the tmp folder''' |
| 31 | shutil.rmtree(self.tmpdir) | 32 | for root, dirs, files in os.walk(self.tmpdir, topdown=False): |
| 33 | for name in files: | ||
| 34 | mat.secure_remove(os.path.join(toor, name)) | ||
| 35 | for name in dirs: | ||
| 36 | os.rmdir(os.path.join(root, name)) | ||
