diff options
| author | jvoisin | 2015-07-25 17:14:23 +0200 |
|---|---|---|
| committer | jvoisin | 2015-07-25 17:14:23 +0200 |
| commit | 6ba3e3f20d7d52895bc44f9fc35b068cfce47133 (patch) | |
| tree | 15df2aca17d56d941c6376ef729e0c1fea4c396f /test | |
| parent | 85e6279d16af063e5150c7cf4bd491185b8ae788 (diff) | |
_MASSIVE_ pep8 revamp
Thank you so much PyCharm
Diffstat (limited to 'test')
| -rw-r--r-- | test/clitest.py | 68 | ||||
| -rw-r--r-- | test/libtest.py | 79 | ||||
| -rw-r--r-- | test/test.py | 30 |
3 files changed, 95 insertions, 82 deletions
diff --git a/test/clitest.py b/test/clitest.py index 13d545a..0a29c02 100644 --- a/test/clitest.py +++ b/test/clitest.py | |||
| @@ -1,9 +1,9 @@ | |||
| 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python |
| 2 | # -*- coding: utf-8 -* | 2 | # -*- coding: utf-8 -* |
| 3 | 3 | ||
| 4 | ''' | 4 | """ |
| 5 | Unit test for the CLI interface | 5 | Unit test for the CLI interface |
| 6 | ''' | 6 | """ |
| 7 | 7 | ||
| 8 | import os | 8 | import os |
| 9 | import unittest | 9 | import unittest |
| @@ -17,18 +17,19 @@ import test | |||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | class TestRemovecli(test.MATTest): | 19 | class TestRemovecli(test.MATTest): |
| 20 | ''' | 20 | """ |
| 21 | test if cli correctly remove metadatas | 21 | test if cli correctly remove metadatas |
| 22 | ''' | 22 | """ |
| 23 | |||
| 23 | def test_remove(self): | 24 | def test_remove(self): |
| 24 | '''make sure that the cli remove all compromizing meta''' | 25 | """make sure that the cli remove all compromizing meta""" |
| 25 | for _, dirty in self.file_list: | 26 | for _, dirty in self.file_list: |
| 26 | subprocess.call(['../mat', '--add2archive', dirty]) | 27 | subprocess.call(['../mat', '--add2archive', dirty]) |
| 27 | current_file = mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True) | 28 | current_file = mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True) |
| 28 | self.assertTrue(current_file.is_clean()) | 29 | self.assertTrue(current_file.is_clean()) |
| 29 | 30 | ||
| 30 | def test_remove_empty(self): | 31 | def test_remove_empty(self): |
| 31 | '''Test removal with clean files\n''' | 32 | """Test removal with clean files\n""" |
| 32 | for clean, _ in self.file_list: | 33 | for clean, _ in self.file_list: |
| 33 | subprocess.call(['../mat', '--add2archive', clean]) | 34 | subprocess.call(['../mat', '--add2archive', clean]) |
| 34 | current_file = mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True) | 35 | current_file = mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True) |
| @@ -36,77 +37,81 @@ class TestRemovecli(test.MATTest): | |||
| 36 | 37 | ||
| 37 | 38 | ||
| 38 | class TestListcli(test.MATTest): | 39 | class TestListcli(test.MATTest): |
| 39 | ''' | 40 | """ |
| 40 | test if cli correctly display metadatas | 41 | test if cli correctly display metadatas |
| 41 | ''' | 42 | """ |
| 43 | |||
| 42 | def test_list_clean(self): | 44 | def test_list_clean(self): |
| 43 | '''check if get_meta returns meta''' | 45 | """check if get_meta returns meta""" |
| 44 | for clean, _ in self.file_list: | 46 | for clean, _ in self.file_list: |
| 45 | proc = subprocess.Popen(['../mat', '-d', clean], | 47 | proc = subprocess.Popen(['../mat', '-d', clean], |
| 46 | stdout=subprocess.PIPE) | 48 | stdout=subprocess.PIPE) |
| 47 | stdout, _ = proc.communicate() | 49 | stdout, _ = proc.communicate() |
| 48 | self.assertEqual(str(stdout).strip('\n'), "[+] File %s \ | 50 | self.assertEqual(str(stdout).strip('\n'), "[+] File %s \ |
| 49 | :\nNo harmful metadata found" % clean) | 51 | :\nNo harmful metadata found" % clean) |
| 50 | 52 | ||
| 51 | def test_list_dirty(self): | 53 | def test_list_dirty(self): |
| 52 | '''check if get_meta returns all the expected meta''' | 54 | """check if get_meta returns all the expected meta""" |
| 53 | for _, dirty in self.file_list: | 55 | for _, dirty in self.file_list: |
| 54 | proc = subprocess.Popen(['../mat', '-d', dirty], | 56 | proc = subprocess.Popen(['../mat', '-d', dirty], |
| 55 | stdout=subprocess.PIPE) | 57 | stdout=subprocess.PIPE) |
| 56 | stdout, _ = proc.communicate() | 58 | stdout, _ = proc.communicate() |
| 57 | self.assertNotEqual(str(stdout), "[+] File %s :\n No\ | 59 | self.assertNotEqual(str(stdout), "[+] File %s :\n No\ |
| 58 | harmul metadata found" % dirty) | 60 | harmul metadata found" % dirty) |
| 59 | 61 | ||
| 60 | 62 | ||
| 61 | class TestisCleancli(test.MATTest): | 63 | class TestisCleancli(test.MATTest): |
| 62 | ''' | 64 | """ |
| 63 | check if cli correctly check if a file is clean or not | 65 | check if cli correctly check if a file is clean or not |
| 64 | ''' | 66 | """ |
| 67 | |||
| 65 | def test_clean(self): | 68 | def test_clean(self): |
| 66 | '''test is_clean on clean files''' | 69 | """test is_clean on clean files""" |
| 67 | for clean, _ in self.file_list: | 70 | for clean, _ in self.file_list: |
| 68 | proc = subprocess.Popen(['../mat', '-c', clean], | 71 | proc = subprocess.Popen(['../mat', '-c', clean], |
| 69 | stdout=subprocess.PIPE) | 72 | stdout=subprocess.PIPE) |
| 70 | stdout, _ = proc.communicate() | 73 | stdout, _ = proc.communicate() |
| 71 | self.assertEqual(str(stdout).strip('\n'), '[+] %s is clean' % clean) | 74 | self.assertEqual(str(stdout).strip('\n'), '[+] %s is clean' % clean) |
| 72 | 75 | ||
| 73 | def test_dirty(self): | 76 | def test_dirty(self): |
| 74 | '''test is_clean on dirty files''' | 77 | """test is_clean on dirty files""" |
| 75 | for _, dirty in self.file_list: | 78 | for _, dirty in self.file_list: |
| 76 | proc = subprocess.Popen(['../mat', '-c', dirty], | 79 | proc = subprocess.Popen(['../mat', '-c', dirty], |
| 77 | stdout=subprocess.PIPE) | 80 | stdout=subprocess.PIPE) |
| 78 | stdout, _ = proc.communicate() | 81 | stdout, _ = proc.communicate() |
| 79 | self.assertEqual(str(stdout).strip('\n'), '[+] %s is not clean' % dirty) | 82 | self.assertEqual(str(stdout).strip('\n'), '[+] %s is not clean' % dirty) |
| 80 | 83 | ||
| 81 | 84 | ||
| 82 | class TestFileAttributes(unittest.TestCase): | 85 | class TestFileAttributes(unittest.TestCase): |
| 83 | ''' | 86 | """ |
| 84 | test various stuffs about files (readable, writable, exist, ...) | 87 | test various stuffs about files (readable, writable, exist, ...) |
| 85 | ''' | 88 | """ |
| 89 | |||
| 86 | def test_not_writtable(self): | 90 | def test_not_writtable(self): |
| 87 | ''' test MAT's behaviour on non-writable file''' | 91 | """ test MAT's behaviour on non-writable file""" |
| 88 | proc = subprocess.Popen(['../mat', 'not_writtable'], | 92 | proc = subprocess.Popen(['../mat', 'not_writtable'], |
| 89 | stdout=subprocess.PIPE) | 93 | stdout=subprocess.PIPE) |
| 90 | stdout, _ = proc.communicate() | 94 | stdout, _ = proc.communicate() |
| 91 | self.assertEqual(str(stdout).strip('\n'), '[-] %s is not writable' % 'not_writtable') | 95 | self.assertEqual(str(stdout).strip('\n'), '[-] %s is not writable' % 'not_writtable') |
| 92 | 96 | ||
| 93 | def test_not_exist(self): | 97 | def test_not_exist(self): |
| 94 | ''' test MAT's behaviour on non-existent file''' | 98 | """ test MAT's behaviour on non-existent file""" |
| 95 | proc = subprocess.Popen(['../mat', 'ilikecookies'], | 99 | proc = subprocess.Popen(['../mat', 'ilikecookies'], |
| 96 | stdout=subprocess.PIPE) | 100 | stdout=subprocess.PIPE) |
| 97 | stdout, _ = proc.communicate() | 101 | stdout, _ = proc.communicate() |
| 98 | self.assertEqual(str(stdout).strip('\n'), 'Unable to process %s' % 'ilikecookies') | 102 | self.assertEqual(str(stdout).strip('\n'), 'Unable to process %s' % 'ilikecookies') |
| 99 | 103 | ||
| 100 | def test_empty(self): | 104 | def test_empty(self): |
| 101 | ''' test MAT's behaviour on empty file''' | 105 | """ test MAT's behaviour on empty file""" |
| 102 | proc = subprocess.Popen(['../mat', 'empty_file'], stdout=subprocess.PIPE) | 106 | proc = subprocess.Popen(['../mat', 'empty_file'], stdout=subprocess.PIPE) |
| 103 | stdout, _ = proc.communicate() | 107 | stdout, _ = proc.communicate() |
| 104 | self.assertEqual(str(stdout).strip('\n'), 'Unable to process %s' % 'ilikecookies') | 108 | self.assertEqual(str(stdout).strip('\n'), 'Unable to process %s' % 'ilikecookies') |
| 105 | 109 | ||
| 110 | |||
| 106 | class TestUnsupported(test.MATTest): | 111 | class TestUnsupported(test.MATTest): |
| 107 | def test_abort_unsupported(self): | 112 | def test_abort_unsupported(self): |
| 108 | ''' test if the cli aborts on unsupported files | 113 | """ test if the cli aborts on unsupported files |
| 109 | ''' | 114 | """ |
| 110 | tarpath = os.path.join(self.tmpdir, "test.tar.bz2") | 115 | tarpath = os.path.join(self.tmpdir, "test.tar.bz2") |
| 111 | tar = tarfile.open(tarpath, "w") | 116 | tar = tarfile.open(tarpath, "w") |
| 112 | for f in ('../mat.desktop', '../README.security', '../setup.py'): | 117 | for f in ('../mat.desktop', '../README.security', '../setup.py'): |
| @@ -114,12 +119,13 @@ class TestUnsupported(test.MATTest): | |||
| 114 | tar.close() | 119 | tar.close() |
| 115 | proc = subprocess.Popen(['../mat', tarpath], stdout=subprocess.PIPE) | 120 | proc = subprocess.Popen(['../mat', tarpath], stdout=subprocess.PIPE) |
| 116 | stdout, _ = proc.communicate() | 121 | stdout, _ = proc.communicate() |
| 117 | self.assertTrue('It contains unsupported filetypes:'\ | 122 | self.assertTrue('It contains unsupported filetypes:' \ |
| 118 | '\n- mat.desktop\n- README.security\n- setup.py\n' | 123 | '\n- mat.desktop\n- README.security\n- setup.py\n' |
| 119 | in str(stdout)) | 124 | in str(stdout)) |
| 125 | |||
| 120 | 126 | ||
| 121 | def get_tests(): | 127 | def get_tests(): |
| 122 | ''' Return every clitests''' | 128 | """ Return every clitests""" |
| 123 | suite = unittest.TestSuite() | 129 | suite = unittest.TestSuite() |
| 124 | suite.addTest(unittest.makeSuite(TestRemovecli)) | 130 | suite.addTest(unittest.makeSuite(TestRemovecli)) |
| 125 | suite.addTest(unittest.makeSuite(TestListcli)) | 131 | suite.addTest(unittest.makeSuite(TestListcli)) |
diff --git a/test/libtest.py b/test/libtest.py index 1b25f86..25d7426 100644 --- a/test/libtest.py +++ b/test/libtest.py | |||
| @@ -1,9 +1,9 @@ | |||
| 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python |
| 2 | # -*- coding: utf-8 -* | 2 | # -*- coding: utf-8 -* |
| 3 | 3 | ||
| 4 | ''' | 4 | """ |
| 5 | Unit test for the library | 5 | Unit test for the library |
| 6 | ''' | 6 | """ |
| 7 | 7 | ||
| 8 | import os | 8 | import os |
| 9 | import sys | 9 | import sys |
| @@ -18,10 +18,11 @@ import libmat | |||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | class TestRemovelib(test.MATTest): | 20 | class TestRemovelib(test.MATTest): |
| 21 | ''' test the remove_all() method | 21 | """ test the remove_all() method |
| 22 | ''' | 22 | """ |
| 23 | |||
| 23 | def test_remove(self): | 24 | def test_remove(self): |
| 24 | '''make sure that the lib remove all compromizing meta''' | 25 | """make sure that the lib remove all compromizing meta""" |
| 25 | for _, dirty in self.file_list: | 26 | for _, dirty in self.file_list: |
| 26 | current_file = libmat.mat.create_class_file(dirty, False, add2archive=True) | 27 | current_file = libmat.mat.create_class_file(dirty, False, add2archive=True) |
| 27 | current_file.remove_all() | 28 | current_file.remove_all() |
| @@ -29,7 +30,7 @@ class TestRemovelib(test.MATTest): | |||
| 29 | self.assertTrue(current_file.is_clean()) | 30 | self.assertTrue(current_file.is_clean()) |
| 30 | 31 | ||
| 31 | def test_remove_empty(self): | 32 | def test_remove_empty(self): |
| 32 | '''Test removal with clean files''' | 33 | """Test removal with clean files""" |
| 33 | for clean, _ in self.file_list: | 34 | for clean, _ in self.file_list: |
| 34 | current_file = libmat.mat.create_class_file(clean, False, add2archive=True) | 35 | current_file = libmat.mat.create_class_file(clean, False, add2archive=True) |
| 35 | current_file.remove_all() | 36 | current_file.remove_all() |
| @@ -38,73 +39,78 @@ class TestRemovelib(test.MATTest): | |||
| 38 | 39 | ||
| 39 | 40 | ||
| 40 | class TestListlib(test.MATTest): | 41 | class TestListlib(test.MATTest): |
| 41 | ''' test the get_meta() method | 42 | """ test the get_meta() method |
| 42 | ''' | 43 | """ |
| 44 | |||
| 43 | def test_list(self): | 45 | def test_list(self): |
| 44 | '''check if get_meta returns metadata''' | 46 | """check if get_meta returns metadata""" |
| 45 | for _, dirty in self.file_list: | 47 | for _, dirty in self.file_list: |
| 46 | current_file = libmat.mat.create_class_file(dirty, False, add2archive=True) | 48 | current_file = libmat.mat.create_class_file(dirty, False, add2archive=True) |
| 47 | self.assertIsNotNone(current_file.get_meta()) | 49 | self.assertIsNotNone(current_file.get_meta()) |
| 48 | 50 | ||
| 49 | def testlist_list_empty(self): | 51 | def testlist_list_empty(self): |
| 50 | '''check that a listing of a clean file returns an empty dict''' | 52 | """check that a listing of a clean file returns an empty dict""" |
| 51 | for clean, _ in self.file_list: | 53 | for clean, _ in self.file_list: |
| 52 | current_file = libmat.mat.create_class_file(clean, False, add2archive=True) | 54 | current_file = libmat.mat.create_class_file(clean, False, add2archive=True) |
| 53 | self.assertEqual(current_file.get_meta(), dict()) | 55 | self.assertEqual(current_file.get_meta(), dict()) |
| 54 | 56 | ||
| 55 | 57 | ||
| 56 | class TestisCleanlib(test.MATTest): | 58 | class TestisCleanlib(test.MATTest): |
| 57 | ''' Test the is_clean() method | 59 | """ Test the is_clean() method |
| 58 | ''' | 60 | """ |
| 61 | |||
| 59 | def test_dirty(self): | 62 | def test_dirty(self): |
| 60 | '''test is_clean on dirty files''' | 63 | """test is_clean on dirty files""" |
| 61 | for _, dirty in self.file_list: | 64 | for _, dirty in self.file_list: |
| 62 | current_file = libmat.mat.create_class_file(dirty, False, add2archive=True) | 65 | current_file = libmat.mat.create_class_file(dirty, False, add2archive=True) |
| 63 | self.assertFalse(current_file.is_clean()) | 66 | self.assertFalse(current_file.is_clean()) |
| 64 | 67 | ||
| 65 | def test_clean(self): | 68 | def test_clean(self): |
| 66 | '''test is_clean on clean files''' | 69 | """test is_clean on clean files""" |
| 67 | for clean, _ in self.file_list: | 70 | for clean, _ in self.file_list: |
| 68 | current_file = libmat.mat.create_class_file(clean, False, add2archive=True) | 71 | current_file = libmat.mat.create_class_file(clean, False, add2archive=True) |
| 69 | self.assertTrue(current_file.is_clean()) | 72 | self.assertTrue(current_file.is_clean()) |
| 70 | 73 | ||
| 71 | 74 | ||
| 72 | class TestFileAttributes(unittest.TestCase): | 75 | class TestFileAttributes(unittest.TestCase): |
| 73 | ''' | 76 | """ |
| 74 | test various stuffs about files (readable, writable, exist, ...) | 77 | test various stuffs about files (readable, writable, exist, ...) |
| 75 | ''' | 78 | """ |
| 79 | |||
| 76 | def test_not_exist(self): | 80 | def test_not_exist(self): |
| 77 | ''' test MAT's behaviour on non-existent file''' | 81 | """ test MAT's behaviour on non-existent file""" |
| 78 | self.assertFalse(libmat.mat.create_class_file('non_existent_file', False, add2archive=True)) | 82 | self.assertFalse(libmat.mat.create_class_file('non_existent_file', False, add2archive=True)) |
| 79 | 83 | ||
| 80 | def test_empty(self): | 84 | def test_empty(self): |
| 81 | ''' test MAT's behaviour on empty file''' | 85 | """ test MAT's behaviour on empty file""" |
| 82 | open('empty_file', 'a').close() | 86 | open('empty_file', 'a').close() |
| 83 | self.assertFalse(libmat.mat.create_class_file('empty_file', False, add2archive=True)) | 87 | self.assertFalse(libmat.mat.create_class_file('empty_file', False, add2archive=True)) |
| 84 | os.remove('empty_file') | 88 | os.remove('empty_file') |
| 85 | 89 | ||
| 86 | 90 | ||
| 87 | class TestSecureRemove(unittest.TestCase): | 91 | class TestSecureRemove(unittest.TestCase): |
| 88 | ''' Test the secure_remove function | 92 | """ Test the secure_remove function |
| 89 | ''' | 93 | """ |
| 94 | |||
| 90 | def test_remove_existing(self): | 95 | def test_remove_existing(self): |
| 91 | ''' test the secure removal of an existing file | 96 | """ test the secure removal of an existing file |
| 92 | ''' | 97 | """ |
| 93 | _, file_to_remove = tempfile.mkstemp() | 98 | _, file_to_remove = tempfile.mkstemp() |
| 94 | self.assertTrue(libmat.mat.secure_remove(file_to_remove)) | 99 | self.assertTrue(libmat.mat.secure_remove(file_to_remove)) |
| 95 | 100 | ||
| 96 | def test_remove_fail(self): | 101 | def test_remove_fail(self): |
| 97 | ''' test the secure removal of an non-removable file | 102 | """ test the secure removal of an non-removable file |
| 98 | ''' | 103 | """ |
| 99 | self.assertRaises(libmat.exceptions.UnableToWriteFile, libmat.mat.secure_remove, '/NOTREMOVABLE') | 104 | self.assertRaises(libmat.exceptions.UnableToWriteFile, libmat.mat.secure_remove, '/NOTREMOVABLE') |
| 100 | 105 | ||
| 101 | 106 | ||
| 102 | class TestArchiveProcessing(test.MATTest): | 107 | class TestArchiveProcessing(test.MATTest): |
| 103 | ''' Test archives processing | 108 | """ Test archives processing |
| 104 | ''' | 109 | """ |
| 110 | |||
| 105 | def test_remove_bz2(self): | 111 | def test_remove_bz2(self): |
| 106 | ''' Test MAT's ability to process .tar.bz2 | 112 | """ Test MAT's ability to process .tar.bz2 |
| 107 | ''' | 113 | """ |
| 108 | tarpath = os.path.join(self.tmpdir, "test.tar.bz2") | 114 | tarpath = os.path.join(self.tmpdir, "test.tar.bz2") |
| 109 | tar = tarfile.open(tarpath, "w:bz2") | 115 | tar = tarfile.open(tarpath, "w:bz2") |
| 110 | for clean, dirty in self.file_list: | 116 | for clean, dirty in self.file_list: |
| @@ -117,8 +123,8 @@ class TestArchiveProcessing(test.MATTest): | |||
| 117 | self.assertTrue(current_file.is_clean()) | 123 | self.assertTrue(current_file.is_clean()) |
| 118 | 124 | ||
| 119 | def test_remove_tar(self): | 125 | def test_remove_tar(self): |
| 120 | ''' Test MAT on tar files | 126 | """ Test MAT on tar files |
| 121 | ''' | 127 | """ |
| 122 | tarpath = os.path.join(self.tmpdir, "test.tar") | 128 | tarpath = os.path.join(self.tmpdir, "test.tar") |
| 123 | tar = tarfile.open(tarpath, "w") | 129 | tar = tarfile.open(tarpath, "w") |
| 124 | for clean, dirty in self.file_list: | 130 | for clean, dirty in self.file_list: |
| @@ -131,8 +137,8 @@ class TestArchiveProcessing(test.MATTest): | |||
| 131 | self.assertTrue(current_file.is_clean()) | 137 | self.assertTrue(current_file.is_clean()) |
| 132 | 138 | ||
| 133 | def test_remove_gz(self): | 139 | def test_remove_gz(self): |
| 134 | ''' Test MAT on tar.gz files | 140 | """ Test MAT on tar.gz files |
| 135 | ''' | 141 | """ |
| 136 | tarpath = os.path.join(self.tmpdir, "test.tar.gz") | 142 | tarpath = os.path.join(self.tmpdir, "test.tar.gz") |
| 137 | tar = tarfile.open(tarpath, "w") | 143 | tar = tarfile.open(tarpath, "w") |
| 138 | for clean, dirty in self.file_list: | 144 | for clean, dirty in self.file_list: |
| @@ -145,8 +151,8 @@ class TestArchiveProcessing(test.MATTest): | |||
| 145 | self.assertTrue(current_file.is_clean()) | 151 | self.assertTrue(current_file.is_clean()) |
| 146 | 152 | ||
| 147 | def test_get_unsupported(self): | 153 | def test_get_unsupported(self): |
| 148 | ''' Test the get_unsupported feature, used by the GUI | 154 | """ Test the get_unsupported feature, used by the GUI |
| 149 | ''' | 155 | """ |
| 150 | tarpath = os.path.join(self.tmpdir, "test.tar.bz2") | 156 | tarpath = os.path.join(self.tmpdir, "test.tar.bz2") |
| 151 | tar = tarfile.open(tarpath, "w") | 157 | tar = tarfile.open(tarpath, "w") |
| 152 | for f in ('../mat.desktop', '../README.security', '../setup.py'): | 158 | for f in ('../mat.desktop', '../README.security', '../setup.py'): |
| @@ -154,7 +160,7 @@ class TestArchiveProcessing(test.MATTest): | |||
| 154 | tar.close() | 160 | tar.close() |
| 155 | current_file = libmat.mat.create_class_file(tarpath, False, add2archive=False) | 161 | current_file = libmat.mat.create_class_file(tarpath, False, add2archive=False) |
| 156 | unsupported_files = set(current_file.is_clean(list_unsupported=True)) | 162 | unsupported_files = set(current_file.is_clean(list_unsupported=True)) |
| 157 | self.assertEqual(unsupported_files, set(('mat.desktop', 'README.security', 'setup.py'))) | 163 | self.assertEqual(unsupported_files, {'mat.desktop', 'README.security', 'setup.py'}) |
| 158 | 164 | ||
| 159 | def test_archive_unwritable_content(self): | 165 | def test_archive_unwritable_content(self): |
| 160 | path = os.path.join(self.tmpdir, './unwritable_content.zip') | 166 | path = os.path.join(self.tmpdir, './unwritable_content.zip') |
| @@ -164,8 +170,9 @@ class TestArchiveProcessing(test.MATTest): | |||
| 164 | current_file = libmat.mat.create_class_file(path, False, add2archive=False) | 170 | current_file = libmat.mat.create_class_file(path, False, add2archive=False) |
| 165 | self.assertTrue(current_file.is_clean()) | 171 | self.assertTrue(current_file.is_clean()) |
| 166 | 172 | ||
| 173 | |||
| 167 | def get_tests(): | 174 | def get_tests(): |
| 168 | ''' Returns every libtests''' | 175 | """ Returns every libtests""" |
| 169 | suite = unittest.TestSuite() | 176 | suite = unittest.TestSuite() |
| 170 | suite.addTest(unittest.makeSuite(TestRemovelib)) | 177 | suite.addTest(unittest.makeSuite(TestRemovelib)) |
| 171 | suite.addTest(unittest.makeSuite(TestListlib)) | 178 | suite.addTest(unittest.makeSuite(TestListlib)) |
diff --git a/test/test.py b/test/test.py index ed68e13..40cbf0c 100644 --- a/test/test.py +++ b/test/test.py | |||
| @@ -1,13 +1,12 @@ | |||
| 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python |
| 2 | # -*- coding: utf-8 -* | 2 | # -*- coding: utf-8 -* |
| 3 | 3 | ||
| 4 | ''' | 4 | """ |
| 5 | Class for the testing suite : | 5 | Class for the testing suite : |
| 6 | - get the list of all test files | 6 | - get the list of all test files |
| 7 | - create a copy of them on start | 7 | - create a copy of them on start |
| 8 | - remove the copy on end | 8 | - remove the copy on end |
| 9 | ''' | 9 | """ |
| 10 | |||
| 11 | 10 | ||
| 12 | import shutil | 11 | import shutil |
| 13 | import os | 12 | import os |
| @@ -42,27 +41,28 @@ except ImportError: | |||
| 42 | 41 | ||
| 43 | 42 | ||
| 44 | class MATTest(unittest.TestCase): | 43 | class MATTest(unittest.TestCase): |
| 45 | ''' | 44 | """ |
| 46 | Parent class of all test-functions | 45 | Parent class of all test-functions |
| 47 | ''' | 46 | """ |
| 47 | |||
| 48 | def setUp(self): | 48 | def setUp(self): |
| 49 | ''' | 49 | """ |
| 50 | Create working copy of the clean and the dirty file in the TMP dir | 50 | Create working copy of the clean and the dirty file in the TMP dir |
| 51 | ''' | 51 | """ |
| 52 | self.file_list = [] | 52 | self.file_list = [] |
| 53 | self.tmpdir = tempfile.mkdtemp() | 53 | self.tmpdir = tempfile.mkdtemp() |
| 54 | 54 | ||
| 55 | for clean, dirty in FILE_LIST: | 55 | for clean_file, dirty_file in FILE_LIST: |
| 56 | clean_dir = os.path.join(self.tmpdir, clean) | 56 | clean_dir = os.path.join(self.tmpdir, clean_file) |
| 57 | dirty_dir = os.path.join(self.tmpdir, dirty) | 57 | dirty_dir = os.path.join(self.tmpdir, dirty_file) |
| 58 | shutil.copy2(clean, clean_dir) | 58 | shutil.copy2(clean_file, clean_dir) |
| 59 | shutil.copy2(dirty, dirty_dir) | 59 | shutil.copy2(dirty_file, dirty_dir) |
| 60 | self.file_list.append((clean_dir, dirty_dir)) | 60 | self.file_list.append((clean_dir, dirty_dir)) |
| 61 | 61 | ||
| 62 | def tearDown(self): | 62 | def tearDown(self): |
| 63 | ''' | 63 | """ |
| 64 | Remove the tmp folder | 64 | Remove the tmp folder |
| 65 | ''' | 65 | """ |
| 66 | for root, dirs, files in os.walk(self.tmpdir): | 66 | for root, dirs, files in os.walk(self.tmpdir): |
| 67 | for d in dirs + files: | 67 | for d in dirs + files: |
| 68 | os.chmod(os.path.join(root, d), 0o777) | 68 | os.chmod(os.path.join(root, d), 0o777) |
| @@ -78,4 +78,4 @@ if __name__ == '__main__': | |||
| 78 | SUITE.addTests(libtest.get_tests()) | 78 | SUITE.addTests(libtest.get_tests()) |
| 79 | 79 | ||
| 80 | ret = unittest.TextTestRunner(verbosity=VERBOSITY).run(SUITE).wasSuccessful() | 80 | ret = unittest.TextTestRunner(verbosity=VERBOSITY).run(SUITE).wasSuccessful() |
| 81 | sys.exit(ret == False) | 81 | sys.exit(ret is False) |
