From 6ba3e3f20d7d52895bc44f9fc35b068cfce47133 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 25 Jul 2015 17:14:23 +0200 Subject: _MASSIVE_ pep8 revamp Thank you so much PyCharm --- test/clitest.py | 68 +++++++++++++++++++++++++++---------------------- test/libtest.py | 79 +++++++++++++++++++++++++++++++-------------------------- test/test.py | 30 +++++++++++----------- 3 files changed, 95 insertions(+), 82 deletions(-) (limited to 'test') 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 @@ #!/usr/bin/env python # -*- coding: utf-8 -* -''' +""" Unit test for the CLI interface -''' +""" import os import unittest @@ -17,18 +17,19 @@ import test class TestRemovecli(test.MATTest): - ''' + """ test if cli correctly remove metadatas - ''' + """ + def test_remove(self): - '''make sure that the cli remove all compromizing meta''' + """make sure that the cli remove all compromizing meta""" for _, dirty in self.file_list: subprocess.call(['../mat', '--add2archive', dirty]) current_file = mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True) self.assertTrue(current_file.is_clean()) def test_remove_empty(self): - '''Test removal with clean files\n''' + """Test removal with clean files\n""" for clean, _ in self.file_list: subprocess.call(['../mat', '--add2archive', clean]) current_file = mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True) @@ -36,77 +37,81 @@ class TestRemovecli(test.MATTest): class TestListcli(test.MATTest): - ''' + """ test if cli correctly display metadatas - ''' + """ + def test_list_clean(self): - '''check if get_meta returns meta''' + """check if get_meta returns meta""" for clean, _ in self.file_list: proc = subprocess.Popen(['../mat', '-d', clean], - stdout=subprocess.PIPE) + stdout=subprocess.PIPE) stdout, _ = proc.communicate() self.assertEqual(str(stdout).strip('\n'), "[+] File %s \ :\nNo harmful metadata found" % clean) def test_list_dirty(self): - '''check if get_meta returns all the expected meta''' + """check if get_meta returns all the expected meta""" for _, dirty in self.file_list: proc = subprocess.Popen(['../mat', '-d', dirty], - stdout=subprocess.PIPE) + stdout=subprocess.PIPE) stdout, _ = proc.communicate() self.assertNotEqual(str(stdout), "[+] File %s :\n No\ harmul metadata found" % dirty) class TestisCleancli(test.MATTest): - ''' + """ check if cli correctly check if a file is clean or not - ''' + """ + def test_clean(self): - '''test is_clean on clean files''' + """test is_clean on clean files""" for clean, _ in self.file_list: proc = subprocess.Popen(['../mat', '-c', clean], - stdout=subprocess.PIPE) + stdout=subprocess.PIPE) stdout, _ = proc.communicate() self.assertEqual(str(stdout).strip('\n'), '[+] %s is clean' % clean) def test_dirty(self): - '''test is_clean on dirty files''' + """test is_clean on dirty files""" for _, dirty in self.file_list: proc = subprocess.Popen(['../mat', '-c', dirty], - stdout=subprocess.PIPE) + stdout=subprocess.PIPE) stdout, _ = proc.communicate() self.assertEqual(str(stdout).strip('\n'), '[+] %s is not clean' % dirty) class TestFileAttributes(unittest.TestCase): - ''' + """ test various stuffs about files (readable, writable, exist, ...) - ''' + """ + def test_not_writtable(self): - ''' test MAT's behaviour on non-writable file''' + """ test MAT's behaviour on non-writable file""" proc = subprocess.Popen(['../mat', 'not_writtable'], - stdout=subprocess.PIPE) + stdout=subprocess.PIPE) stdout, _ = proc.communicate() self.assertEqual(str(stdout).strip('\n'), '[-] %s is not writable' % 'not_writtable') def test_not_exist(self): - ''' test MAT's behaviour on non-existent file''' + """ test MAT's behaviour on non-existent file""" proc = subprocess.Popen(['../mat', 'ilikecookies'], - stdout=subprocess.PIPE) + stdout=subprocess.PIPE) stdout, _ = proc.communicate() self.assertEqual(str(stdout).strip('\n'), 'Unable to process %s' % 'ilikecookies') def test_empty(self): - ''' test MAT's behaviour on empty file''' + """ test MAT's behaviour on empty file""" proc = subprocess.Popen(['../mat', 'empty_file'], stdout=subprocess.PIPE) stdout, _ = proc.communicate() self.assertEqual(str(stdout).strip('\n'), 'Unable to process %s' % 'ilikecookies') + class TestUnsupported(test.MATTest): def test_abort_unsupported(self): - ''' test if the cli aborts on unsupported files - ''' + """ test if the cli aborts on unsupported files + """ tarpath = os.path.join(self.tmpdir, "test.tar.bz2") tar = tarfile.open(tarpath, "w") for f in ('../mat.desktop', '../README.security', '../setup.py'): @@ -114,12 +119,13 @@ class TestUnsupported(test.MATTest): tar.close() proc = subprocess.Popen(['../mat', tarpath], stdout=subprocess.PIPE) stdout, _ = proc.communicate() - self.assertTrue('It contains unsupported filetypes:'\ - '\n- mat.desktop\n- README.security\n- setup.py\n' - in str(stdout)) + self.assertTrue('It contains unsupported filetypes:' \ + '\n- mat.desktop\n- README.security\n- setup.py\n' + in str(stdout)) + def get_tests(): - ''' Return every clitests''' + """ Return every clitests""" suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(TestRemovecli)) 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 @@ #!/usr/bin/env python # -*- coding: utf-8 -* -''' +""" Unit test for the library -''' +""" import os import sys @@ -18,10 +18,11 @@ import libmat class TestRemovelib(test.MATTest): - ''' test the remove_all() method - ''' + """ test the remove_all() method + """ + def test_remove(self): - '''make sure that the lib remove all compromizing meta''' + """make sure that the lib remove all compromizing meta""" for _, dirty in self.file_list: current_file = libmat.mat.create_class_file(dirty, False, add2archive=True) current_file.remove_all() @@ -29,7 +30,7 @@ class TestRemovelib(test.MATTest): self.assertTrue(current_file.is_clean()) def test_remove_empty(self): - '''Test removal with clean files''' + """Test removal with clean files""" for clean, _ in self.file_list: current_file = libmat.mat.create_class_file(clean, False, add2archive=True) current_file.remove_all() @@ -38,73 +39,78 @@ class TestRemovelib(test.MATTest): class TestListlib(test.MATTest): - ''' test the get_meta() method - ''' + """ test the get_meta() method + """ + def test_list(self): - '''check if get_meta returns metadata''' + """check if get_meta returns metadata""" for _, dirty in self.file_list: current_file = libmat.mat.create_class_file(dirty, False, add2archive=True) self.assertIsNotNone(current_file.get_meta()) def testlist_list_empty(self): - '''check that a listing of a clean file returns an empty dict''' + """check that a listing of a clean file returns an empty dict""" for clean, _ in self.file_list: current_file = libmat.mat.create_class_file(clean, False, add2archive=True) self.assertEqual(current_file.get_meta(), dict()) class TestisCleanlib(test.MATTest): - ''' Test the is_clean() method - ''' + """ Test the is_clean() method + """ + def test_dirty(self): - '''test is_clean on dirty files''' + """test is_clean on dirty files""" for _, dirty in self.file_list: current_file = libmat.mat.create_class_file(dirty, False, add2archive=True) self.assertFalse(current_file.is_clean()) def test_clean(self): - '''test is_clean on clean files''' + """test is_clean on clean files""" for clean, _ in self.file_list: current_file = libmat.mat.create_class_file(clean, False, add2archive=True) self.assertTrue(current_file.is_clean()) class TestFileAttributes(unittest.TestCase): - ''' + """ test various stuffs about files (readable, writable, exist, ...) - ''' + """ + def test_not_exist(self): - ''' test MAT's behaviour on non-existent file''' + """ test MAT's behaviour on non-existent file""" self.assertFalse(libmat.mat.create_class_file('non_existent_file', False, add2archive=True)) def test_empty(self): - ''' test MAT's behaviour on empty file''' + """ test MAT's behaviour on empty file""" open('empty_file', 'a').close() self.assertFalse(libmat.mat.create_class_file('empty_file', False, add2archive=True)) os.remove('empty_file') class TestSecureRemove(unittest.TestCase): - ''' Test the secure_remove function - ''' + """ Test the secure_remove function + """ + def test_remove_existing(self): - ''' test the secure removal of an existing file - ''' + """ test the secure removal of an existing file + """ _, file_to_remove = tempfile.mkstemp() self.assertTrue(libmat.mat.secure_remove(file_to_remove)) def test_remove_fail(self): - ''' test the secure removal of an non-removable file - ''' + """ test the secure removal of an non-removable file + """ self.assertRaises(libmat.exceptions.UnableToWriteFile, libmat.mat.secure_remove, '/NOTREMOVABLE') class TestArchiveProcessing(test.MATTest): - ''' Test archives processing - ''' + """ Test archives processing + """ + def test_remove_bz2(self): - ''' Test MAT's ability to process .tar.bz2 - ''' + """ Test MAT's ability to process .tar.bz2 + """ tarpath = os.path.join(self.tmpdir, "test.tar.bz2") tar = tarfile.open(tarpath, "w:bz2") for clean, dirty in self.file_list: @@ -117,8 +123,8 @@ class TestArchiveProcessing(test.MATTest): self.assertTrue(current_file.is_clean()) def test_remove_tar(self): - ''' Test MAT on tar files - ''' + """ Test MAT on tar files + """ tarpath = os.path.join(self.tmpdir, "test.tar") tar = tarfile.open(tarpath, "w") for clean, dirty in self.file_list: @@ -131,8 +137,8 @@ class TestArchiveProcessing(test.MATTest): self.assertTrue(current_file.is_clean()) def test_remove_gz(self): - ''' Test MAT on tar.gz files - ''' + """ Test MAT on tar.gz files + """ tarpath = os.path.join(self.tmpdir, "test.tar.gz") tar = tarfile.open(tarpath, "w") for clean, dirty in self.file_list: @@ -145,8 +151,8 @@ class TestArchiveProcessing(test.MATTest): self.assertTrue(current_file.is_clean()) def test_get_unsupported(self): - ''' Test the get_unsupported feature, used by the GUI - ''' + """ Test the get_unsupported feature, used by the GUI + """ tarpath = os.path.join(self.tmpdir, "test.tar.bz2") tar = tarfile.open(tarpath, "w") for f in ('../mat.desktop', '../README.security', '../setup.py'): @@ -154,7 +160,7 @@ class TestArchiveProcessing(test.MATTest): tar.close() current_file = libmat.mat.create_class_file(tarpath, False, add2archive=False) unsupported_files = set(current_file.is_clean(list_unsupported=True)) - self.assertEqual(unsupported_files, set(('mat.desktop', 'README.security', 'setup.py'))) + self.assertEqual(unsupported_files, {'mat.desktop', 'README.security', 'setup.py'}) def test_archive_unwritable_content(self): path = os.path.join(self.tmpdir, './unwritable_content.zip') @@ -164,8 +170,9 @@ class TestArchiveProcessing(test.MATTest): current_file = libmat.mat.create_class_file(path, False, add2archive=False) self.assertTrue(current_file.is_clean()) + def get_tests(): - ''' Returns every libtests''' + """ Returns every libtests""" suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(TestRemovelib)) 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 @@ #!/usr/bin/env python # -*- coding: utf-8 -* -''' +""" Class for the testing suite : - get the list of all test files - create a copy of them on start - remove the copy on end -''' - +""" import shutil import os @@ -42,27 +41,28 @@ except ImportError: class MATTest(unittest.TestCase): - ''' + """ Parent class of all test-functions - ''' + """ + def setUp(self): - ''' + """ Create working copy of the clean and the dirty file in the TMP dir - ''' + """ self.file_list = [] self.tmpdir = tempfile.mkdtemp() - for clean, dirty in FILE_LIST: - clean_dir = os.path.join(self.tmpdir, clean) - dirty_dir = os.path.join(self.tmpdir, dirty) - shutil.copy2(clean, clean_dir) - shutil.copy2(dirty, dirty_dir) + for clean_file, dirty_file in FILE_LIST: + clean_dir = os.path.join(self.tmpdir, clean_file) + dirty_dir = os.path.join(self.tmpdir, dirty_file) + shutil.copy2(clean_file, clean_dir) + shutil.copy2(dirty_file, dirty_dir) self.file_list.append((clean_dir, dirty_dir)) def tearDown(self): - ''' + """ Remove the tmp folder - ''' + """ for root, dirs, files in os.walk(self.tmpdir): for d in dirs + files: os.chmod(os.path.join(root, d), 0o777) @@ -78,4 +78,4 @@ if __name__ == '__main__': SUITE.addTests(libtest.get_tests()) ret = unittest.TextTestRunner(verbosity=VERBOSITY).run(SUITE).wasSuccessful() - sys.exit(ret == False) + sys.exit(ret is False) -- cgit v1.3