summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorjvoisin2015-10-05 21:43:17 +0200
committerjvoisin2015-10-05 21:43:17 +0200
commit5b9c600ae96e63f1f7a7f9487512c3c9d8a356e7 (patch)
tree39a2f8e45f4c03f9884de876d44adb5995425b67 /test
parentbeeb5f3f2c43823f51a80c9245af74708c84daa0 (diff)
Tests can now target system-wide or global MAT
$ python test.py --local/--system
Diffstat (limited to 'test')
-rw-r--r--test/clitest.py36
-rw-r--r--test/libtest.py14
-rw-r--r--test/test.py18
3 files changed, 48 insertions, 20 deletions
diff --git a/test/clitest.py b/test/clitest.py
index 0a29c02..c913bdf 100644
--- a/test/clitest.py
+++ b/test/clitest.py
@@ -11,9 +11,15 @@ import subprocess
11import sys 11import sys
12import tarfile 12import tarfile
13 13
14sys.path.append('..')
15from libmat import mat
16import test 14import test
15MAT_PATH = 'mat'
16if test.IS_LOCAL is True:
17 # Are we testing the _local_ version of MAT?
18 sys.path.insert(0, '..')
19 MAT_PATH = '../mat'
20# else it will be in the path
21
22from libmat import mat
17 23
18 24
19class TestRemovecli(test.MATTest): 25class TestRemovecli(test.MATTest):
@@ -24,14 +30,14 @@ class TestRemovecli(test.MATTest):
24 def test_remove(self): 30 def test_remove(self):
25 """make sure that the cli remove all compromizing meta""" 31 """make sure that the cli remove all compromizing meta"""
26 for _, dirty in self.file_list: 32 for _, dirty in self.file_list:
27 subprocess.call(['../mat', '--add2archive', dirty]) 33 subprocess.call([MAT_PATH, '--add2archive', dirty])
28 current_file = mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True) 34 current_file = mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True)
29 self.assertTrue(current_file.is_clean()) 35 self.assertTrue(current_file.is_clean())
30 36
31 def test_remove_empty(self): 37 def test_remove_empty(self):
32 """Test removal with clean files\n""" 38 """Test removal with clean files\n"""
33 for clean, _ in self.file_list: 39 for clean, _ in self.file_list:
34 subprocess.call(['../mat', '--add2archive', clean]) 40 subprocess.call([MAT_PATH, '--add2archive', clean])
35 current_file = mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True) 41 current_file = mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True)
36 self.assertTrue(current_file.is_clean()) 42 self.assertTrue(current_file.is_clean())
37 43
@@ -44,7 +50,7 @@ class TestListcli(test.MATTest):
44 def test_list_clean(self): 50 def test_list_clean(self):
45 """check if get_meta returns meta""" 51 """check if get_meta returns meta"""
46 for clean, _ in self.file_list: 52 for clean, _ in self.file_list:
47 proc = subprocess.Popen(['../mat', '-d', clean], 53 proc = subprocess.Popen([MAT_PATH, '-d', clean],
48 stdout=subprocess.PIPE) 54 stdout=subprocess.PIPE)
49 stdout, _ = proc.communicate() 55 stdout, _ = proc.communicate()
50 self.assertEqual(str(stdout).strip('\n'), "[+] File %s \ 56 self.assertEqual(str(stdout).strip('\n'), "[+] File %s \
@@ -53,7 +59,7 @@ class TestListcli(test.MATTest):
53 def test_list_dirty(self): 59 def test_list_dirty(self):
54 """check if get_meta returns all the expected meta""" 60 """check if get_meta returns all the expected meta"""
55 for _, dirty in self.file_list: 61 for _, dirty in self.file_list:
56 proc = subprocess.Popen(['../mat', '-d', dirty], 62 proc = subprocess.Popen([MAT_PATH, '-d', dirty],
57 stdout=subprocess.PIPE) 63 stdout=subprocess.PIPE)
58 stdout, _ = proc.communicate() 64 stdout, _ = proc.communicate()
59 self.assertNotEqual(str(stdout), "[+] File %s :\n No\ 65 self.assertNotEqual(str(stdout), "[+] File %s :\n No\
@@ -68,7 +74,7 @@ class TestisCleancli(test.MATTest):
68 def test_clean(self): 74 def test_clean(self):
69 """test is_clean on clean files""" 75 """test is_clean on clean files"""
70 for clean, _ in self.file_list: 76 for clean, _ in self.file_list:
71 proc = subprocess.Popen(['../mat', '-c', clean], 77 proc = subprocess.Popen([MAT_PATH, '-c', clean],
72 stdout=subprocess.PIPE) 78 stdout=subprocess.PIPE)
73 stdout, _ = proc.communicate() 79 stdout, _ = proc.communicate()
74 self.assertEqual(str(stdout).strip('\n'), '[+] %s is clean' % clean) 80 self.assertEqual(str(stdout).strip('\n'), '[+] %s is clean' % clean)
@@ -76,7 +82,7 @@ class TestisCleancli(test.MATTest):
76 def test_dirty(self): 82 def test_dirty(self):
77 """test is_clean on dirty files""" 83 """test is_clean on dirty files"""
78 for _, dirty in self.file_list: 84 for _, dirty in self.file_list:
79 proc = subprocess.Popen(['../mat', '-c', dirty], 85 proc = subprocess.Popen([MAT_PATH, '-c', dirty],
80 stdout=subprocess.PIPE) 86 stdout=subprocess.PIPE)
81 stdout, _ = proc.communicate() 87 stdout, _ = proc.communicate()
82 self.assertEqual(str(stdout).strip('\n'), '[+] %s is not clean' % dirty) 88 self.assertEqual(str(stdout).strip('\n'), '[+] %s is not clean' % dirty)
@@ -89,21 +95,21 @@ class TestFileAttributes(unittest.TestCase):
89 95
90 def test_not_writtable(self): 96 def test_not_writtable(self):
91 """ test MAT's behaviour on non-writable file""" 97 """ test MAT's behaviour on non-writable file"""
92 proc = subprocess.Popen(['../mat', 'not_writtable'], 98 proc = subprocess.Popen([MAT_PATH, 'not_writtable'],
93 stdout=subprocess.PIPE) 99 stdout=subprocess.PIPE)
94 stdout, _ = proc.communicate() 100 stdout, _ = proc.communicate()
95 self.assertEqual(str(stdout).strip('\n'), '[-] %s is not writable' % 'not_writtable') 101 self.assertEqual(str(stdout).strip('\n'), '[-] %s is not writable' % 'not_writtable')
96 102
97 def test_not_exist(self): 103 def test_not_exist(self):
98 """ test MAT's behaviour on non-existent file""" 104 """ test MAT's behaviour on non-existent file"""
99 proc = subprocess.Popen(['../mat', 'ilikecookies'], 105 proc = subprocess.Popen([MAT_PATH, 'ilikecookies'],
100 stdout=subprocess.PIPE) 106 stdout=subprocess.PIPE)
101 stdout, _ = proc.communicate() 107 stdout, _ = proc.communicate()
102 self.assertEqual(str(stdout).strip('\n'), 'Unable to process %s' % 'ilikecookies') 108 self.assertEqual(str(stdout).strip('\n'), 'Unable to process %s' % 'ilikecookies')
103 109
104 def test_empty(self): 110 def test_empty(self):
105 """ test MAT's behaviour on empty file""" 111 """ test MAT's behaviour on empty file"""
106 proc = subprocess.Popen(['../mat', 'empty_file'], stdout=subprocess.PIPE) 112 proc = subprocess.Popen([MAT_PATH, 'empty_file'], stdout=subprocess.PIPE)
107 stdout, _ = proc.communicate() 113 stdout, _ = proc.communicate()
108 self.assertEqual(str(stdout).strip('\n'), 'Unable to process %s' % 'ilikecookies') 114 self.assertEqual(str(stdout).strip('\n'), 'Unable to process %s' % 'ilikecookies')
109 115
@@ -114,13 +120,13 @@ class TestUnsupported(test.MATTest):
114 """ 120 """
115 tarpath = os.path.join(self.tmpdir, "test.tar.bz2") 121 tarpath = os.path.join(self.tmpdir, "test.tar.bz2")
116 tar = tarfile.open(tarpath, "w") 122 tar = tarfile.open(tarpath, "w")
117 for f in ('../mat.desktop', '../README.security', '../setup.py'): 123 for f in ('libtest.py', 'test.py', 'clitest.py'):
118 tar.add(f, f[3:]) # trim '../' 124 tar.add(f, f)
119 tar.close() 125 tar.close()
120 proc = subprocess.Popen(['../mat', tarpath], stdout=subprocess.PIPE) 126 proc = subprocess.Popen([MAT_PATH, tarpath], stdout=subprocess.PIPE)
121 stdout, _ = proc.communicate() 127 stdout, _ = proc.communicate()
122 self.assertTrue('It contains unsupported filetypes:' \ 128 self.assertTrue('It contains unsupported filetypes:' \
123 '\n- mat.desktop\n- README.security\n- setup.py\n' 129 '\n- libtest.py\n- test.py\n- clitest.py\n'
124 in str(stdout)) 130 in str(stdout))
125 131
126 132
diff --git a/test/libtest.py b/test/libtest.py
index 25d7426..03ae4a1 100644
--- a/test/libtest.py
+++ b/test/libtest.py
@@ -10,10 +10,14 @@ import sys
10import shutil 10import shutil
11import tarfile 11import tarfile
12import tempfile 12import tempfile
13import test
14import unittest 13import unittest
15 14
16sys.path.append('..') 15import test
16if test.IS_LOCAL is True:
17 # Are we testing the _local_ version of MAT?
18 sys.path.insert(0, '..')
19# else it will be in the path
20
17import libmat 21import libmat
18 22
19 23
@@ -155,12 +159,12 @@ class TestArchiveProcessing(test.MATTest):
155 """ 159 """
156 tarpath = os.path.join(self.tmpdir, "test.tar.bz2") 160 tarpath = os.path.join(self.tmpdir, "test.tar.bz2")
157 tar = tarfile.open(tarpath, "w") 161 tar = tarfile.open(tarpath, "w")
158 for f in ('../mat.desktop', '../README.security', '../setup.py'): 162 for f in ('libtest.py', 'test.py', 'clitest.py'):
159 tar.add(f, f[3:]) # trim '../' 163 tar.add(f, f)
160 tar.close() 164 tar.close()
161 current_file = libmat.mat.create_class_file(tarpath, False, add2archive=False) 165 current_file = libmat.mat.create_class_file(tarpath, False, add2archive=False)
162 unsupported_files = set(current_file.is_clean(list_unsupported=True)) 166 unsupported_files = set(current_file.is_clean(list_unsupported=True))
163 self.assertEqual(unsupported_files, {'mat.desktop', 'README.security', 'setup.py'}) 167 self.assertEqual(unsupported_files, {'libtest.py', 'test.py', 'clitest.py'})
164 168
165 def test_archive_unwritable_content(self): 169 def test_archive_unwritable_content(self):
166 path = os.path.join(self.tmpdir, './unwritable_content.zip') 170 path = os.path.join(self.tmpdir, './unwritable_content.zip')
diff --git a/test/test.py b/test/test.py
index 40cbf0c..e45912e 100644
--- a/test/test.py
+++ b/test/test.py
@@ -15,6 +15,8 @@ import sys
15import tempfile 15import tempfile
16import unittest 16import unittest
17 17
18IS_LOCAL = True
19
18VERBOSITY = 15 20VERBOSITY = 15
19 21
20clean = glob.glob('clean*') 22clean = glob.glob('clean*')
@@ -72,6 +74,22 @@ class MATTest(unittest.TestCase):
72if __name__ == '__main__': 74if __name__ == '__main__':
73 import clitest 75 import clitest
74 import libtest 76 import libtest
77 import argparse
78
79 parser = argparse.ArgumentParser(description='MAT testsuite')
80 parser.add_argument('-l', '--local', action='store_true',
81 help='Test the local version of mat')
82 parser.add_argument('-s', '--system', action='store_true',
83 help='Test the system-wide version of mat')
84
85 if parser.parse_args().local is True:
86 IS_LOCAL = True
87 elif parser.parse_args().system is True:
88 IS_LOCAL = False
89 else:
90 print('Please specify either --local or --system')
91 sys.exit(1)
92
75 93
76 SUITE = unittest.TestSuite() 94 SUITE = unittest.TestSuite()
77 SUITE.addTests(clitest.get_tests()) 95 SUITE.addTests(clitest.get_tests())