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/libtest.py | |
| parent | 85e6279d16af063e5150c7cf4bd491185b8ae788 (diff) | |
_MASSIVE_ pep8 revamp
Thank you so much PyCharm
Diffstat (limited to '')
| -rw-r--r-- | test/libtest.py | 79 |
1 files changed, 43 insertions, 36 deletions
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)) |
