summaryrefslogtreecommitdiff
path: root/test/clitest.py
diff options
context:
space:
mode:
authorjvoisin2015-07-25 17:14:23 +0200
committerjvoisin2015-07-25 17:14:23 +0200
commit6ba3e3f20d7d52895bc44f9fc35b068cfce47133 (patch)
tree15df2aca17d56d941c6376ef729e0c1fea4c396f /test/clitest.py
parent85e6279d16af063e5150c7cf4bd491185b8ae788 (diff)
_MASSIVE_ pep8 revamp
Thank you so much PyCharm
Diffstat (limited to 'test/clitest.py')
-rw-r--r--test/clitest.py68
1 files changed, 37 insertions, 31 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
8import os 8import os
9import unittest 9import unittest
@@ -17,18 +17,19 @@ import test
17 17
18 18
19class TestRemovecli(test.MATTest): 19class 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
38class TestListcli(test.MATTest): 39class 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\
58harmul metadata found" % dirty) 60harmul metadata found" % dirty)
59 61
60 62
61class TestisCleancli(test.MATTest): 63class 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
82class TestFileAttributes(unittest.TestCase): 85class 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
106class TestUnsupported(test.MATTest): 111class 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
121def get_tests(): 127def 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))