summaryrefslogtreecommitdiff
path: root/test/clitest.py
diff options
context:
space:
mode:
authorjvoisin2015-12-30 13:12:39 +0100
committerjvoisin2015-12-30 15:11:37 +0100
commit3ac3f353c64d406aa2fa46c5c9841346408e1e01 (patch)
tree562f27ff88253c693d4adc3acfe82693737c78a4 /test/clitest.py
parentb9d66ed2e07d0a40161c88d0ba52d59ac601c76e (diff)
Hopefully make test suite work once copied out of the build tree
This should fix https://labs.riseup.net/code/issues/10065
Diffstat (limited to 'test/clitest.py')
-rw-r--r--test/clitest.py39
1 files changed, 16 insertions, 23 deletions
diff --git a/test/clitest.py b/test/clitest.py
index 195defa..e186531 100644
--- a/test/clitest.py
+++ b/test/clitest.py
@@ -13,13 +13,6 @@ import tarfile
13import stat 13import stat
14 14
15import test 15import test
16MAT_PATH = 'mat'
17if test.IS_LOCAL is True:
18 # Are we testing the _local_ version of MAT?
19 sys.path.insert(0, '..')
20 MAT_PATH = '../mat'
21# else it will be in the path
22
23from libmat import mat 16from libmat import mat
24 17
25 18
@@ -31,7 +24,7 @@ class TestRemovecli(test.MATTest):
31 def test_remove(self): 24 def test_remove(self):
32 """make sure that the cli remove all compromizing meta""" 25 """make sure that the cli remove all compromizing meta"""
33 for _, dirty in self.file_list: 26 for _, dirty in self.file_list:
34 subprocess.call([MAT_PATH, '--add2archive', dirty]) 27 subprocess.call(['mat', '--add2archive', dirty])
35 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)
36 self.assertTrue(current_file.is_clean()) 29 self.assertTrue(current_file.is_clean())
37 30
@@ -39,14 +32,14 @@ class TestRemovecli(test.MATTest):
39 """ test metadata removal with fileformat-specific options """ 32 """ test metadata removal with fileformat-specific options """
40 for _, dirty in self.file_list: # can't be faster than that :/ 33 for _, dirty in self.file_list: # can't be faster than that :/
41 if dirty.endswith('pdf'): 34 if dirty.endswith('pdf'):
42 subprocess.call([MAT_PATH, '--low-pdf-quality', dirty]) 35 subprocess.call(['mat', '--low-pdf-quality', dirty])
43 current_file = mat.create_class_file(dirty, False, low_pdf_quality=True) 36 current_file = mat.create_class_file(dirty, False, low_pdf_quality=True)
44 self.assertTrue(current_file.is_clean()) 37 self.assertTrue(current_file.is_clean())
45 38
46 def test_remove_empty(self): 39 def test_remove_empty(self):
47 """Test removal with clean files\n""" 40 """Test removal with clean files\n"""
48 for clean, _ in self.file_list: 41 for clean, _ in self.file_list:
49 subprocess.call([MAT_PATH, '--add2archive', clean]) 42 subprocess.call(['mat', '--add2archive', clean])
50 current_file = mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True) 43 current_file = mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True)
51 self.assertTrue(current_file.is_clean()) 44 self.assertTrue(current_file.is_clean())
52 45
@@ -59,7 +52,7 @@ class TestListcli(test.MATTest):
59 def test_list_clean(self): 52 def test_list_clean(self):
60 """check if get_meta returns meta""" 53 """check if get_meta returns meta"""
61 for clean, _ in self.file_list: 54 for clean, _ in self.file_list:
62 proc = subprocess.Popen([MAT_PATH, '-d', clean], 55 proc = subprocess.Popen(['mat', '-d', clean],
63 stdout=subprocess.PIPE) 56 stdout=subprocess.PIPE)
64 stdout, _ = proc.communicate() 57 stdout, _ = proc.communicate()
65 self.assertEqual(str(stdout).strip('\n'), "[+] File %s \ 58 self.assertEqual(str(stdout).strip('\n'), "[+] File %s \
@@ -68,7 +61,7 @@ class TestListcli(test.MATTest):
68 def test_list_dirty(self): 61 def test_list_dirty(self):
69 """check if get_meta returns all the expected meta""" 62 """check if get_meta returns all the expected meta"""
70 for _, dirty in self.file_list: 63 for _, dirty in self.file_list:
71 proc = subprocess.Popen([MAT_PATH, '-d', dirty], 64 proc = subprocess.Popen(['mat', '-d', dirty],
72 stdout=subprocess.PIPE) 65 stdout=subprocess.PIPE)
73 stdout, _ = proc.communicate() 66 stdout, _ = proc.communicate()
74 self.assertNotEqual(str(stdout), "[+] File %s :\n No\ 67 self.assertNotEqual(str(stdout), "[+] File %s :\n No\
@@ -83,7 +76,7 @@ class TestisCleancli(test.MATTest):
83 def test_clean(self): 76 def test_clean(self):
84 """test is_clean on clean files""" 77 """test is_clean on clean files"""
85 for clean, _ in self.file_list: 78 for clean, _ in self.file_list:
86 proc = subprocess.Popen([MAT_PATH, '-c', clean], 79 proc = subprocess.Popen(['mat', '-c', clean],
87 stdout=subprocess.PIPE) 80 stdout=subprocess.PIPE)
88 stdout, _ = proc.communicate() 81 stdout, _ = proc.communicate()
89 self.assertEqual(str(stdout).strip('\n'), '[+] %s is clean' % clean) 82 self.assertEqual(str(stdout).strip('\n'), '[+] %s is clean' % clean)
@@ -91,7 +84,7 @@ class TestisCleancli(test.MATTest):
91 def test_dirty(self): 84 def test_dirty(self):
92 """test is_clean on dirty files""" 85 """test is_clean on dirty files"""
93 for _, dirty in self.file_list: 86 for _, dirty in self.file_list:
94 proc = subprocess.Popen([MAT_PATH, '-c', dirty], 87 proc = subprocess.Popen(['mat', '-c', dirty],
95 stdout=subprocess.PIPE) 88 stdout=subprocess.PIPE)
96 stdout, _ = proc.communicate() 89 stdout, _ = proc.communicate()
97 self.assertEqual(str(stdout).strip('\n'), '[+] %s is not clean' % dirty) 90 self.assertEqual(str(stdout).strip('\n'), '[+] %s is not clean' % dirty)
@@ -104,21 +97,21 @@ class TestFileAttributes(unittest.TestCase):
104 97
105 def test_not_writtable(self): 98 def test_not_writtable(self):
106 """ test MAT's behaviour on non-writable file""" 99 """ test MAT's behaviour on non-writable file"""
107 proc = subprocess.Popen([MAT_PATH, 'not_writtable'], 100 proc = subprocess.Popen(['mat', 'not_writtable'],
108 stdout=subprocess.PIPE) 101 stdout=subprocess.PIPE)
109 stdout, _ = proc.communicate() 102 stdout, _ = proc.communicate()
110 self.assertEqual(str(stdout).strip('\n'), '[-] Unable to process not_writtable') 103 self.assertEqual(str(stdout).strip('\n'), '[-] Unable to process not_writtable')
111 104
112 def test_not_exist(self): 105 def test_not_exist(self):
113 """ test MAT's behaviour on non-existent file""" 106 """ test MAT's behaviour on non-existent file"""
114 proc = subprocess.Popen([MAT_PATH, 'ilikecookies'], 107 proc = subprocess.Popen(['mat', 'ilikecookies'],
115 stdout=subprocess.PIPE) 108 stdout=subprocess.PIPE)
116 stdout, _ = proc.communicate() 109 stdout, _ = proc.communicate()
117 self.assertEqual(str(stdout).strip('\n'), '[-] Unable to process ilikecookies') 110 self.assertEqual(str(stdout).strip('\n'), '[-] Unable to process ilikecookies')
118 111
119 def test_empty(self): 112 def test_empty(self):
120 """ test MAT's behaviour on empty file""" 113 """ test MAT's behaviour on empty file"""
121 proc = subprocess.Popen([MAT_PATH, 'empty_file'], stdout=subprocess.PIPE) 114 proc = subprocess.Popen(['mat', 'empty_file'], stdout=subprocess.PIPE)
122 stdout, _ = proc.communicate() 115 stdout, _ = proc.communicate()
123 self.assertEqual(str(stdout).strip('\n'), '[-] Unable to process empty_file') 116 self.assertEqual(str(stdout).strip('\n'), '[-] Unable to process empty_file')
124 117
@@ -126,7 +119,7 @@ class TestFileAttributes(unittest.TestCase):
126 """ test MAT's behaviour on non-writable file""" 119 """ test MAT's behaviour on non-writable file"""
127 open('non_readable', 'a').close() 120 open('non_readable', 'a').close()
128 os.chmod('non_readable', 0 & stat.S_IWRITE) 121 os.chmod('non_readable', 0 & stat.S_IWRITE)
129 proc = subprocess.Popen([MAT_PATH, 'non_readable'], stdout=subprocess.PIPE) 122 proc = subprocess.Popen(['mat', 'non_readable'], stdout=subprocess.PIPE)
130 stdout, _ = proc.communicate() 123 stdout, _ = proc.communicate()
131 os.remove('non_readable') 124 os.remove('non_readable')
132 125
@@ -141,7 +134,7 @@ class TestUnsupported(test.MATTest):
141 for f in ('libtest.py', 'test.py', 'clitest.py'): 134 for f in ('libtest.py', 'test.py', 'clitest.py'):
142 tar.add(f, f) 135 tar.add(f, f)
143 tar.close() 136 tar.close()
144 proc = subprocess.Popen([MAT_PATH, tarpath], stdout=subprocess.PIPE) 137 proc = subprocess.Popen(['mat', tarpath], stdout=subprocess.PIPE)
145 stdout, _ = proc.communicate() 138 stdout, _ = proc.communicate()
146 self.assertTrue('It contains unsupported filetypes:' \ 139 self.assertTrue('It contains unsupported filetypes:' \
147 '\n- libtest.py\n- test.py\n- clitest.py\n' 140 '\n- libtest.py\n- test.py\n- clitest.py\n'
@@ -151,23 +144,23 @@ class TestHelp(test.MATTest):
151 """ Test the different ways to trigger help """ 144 """ Test the different ways to trigger help """
152 def test_dash_h(self): 145 def test_dash_h(self):
153 """ test help invocation with `-h` and `--help` """ 146 """ test help invocation with `-h` and `--help` """
154 proc = subprocess.Popen([MAT_PATH, '-h'], stdout=subprocess.PIPE) 147 proc = subprocess.Popen(['mat', '-h'], stdout=subprocess.PIPE)
155 stdout, _ = proc.communicate() 148 stdout, _ = proc.communicate()
156 self.assertTrue('show this help message and exit' in stdout) 149 self.assertTrue('show this help message and exit' in stdout)
157 150
158 proc = subprocess.Popen([MAT_PATH, '--help'], stdout=subprocess.PIPE) 151 proc = subprocess.Popen(['mat', '--help'], stdout=subprocess.PIPE)
159 stdout, _ = proc.communicate() 152 stdout, _ = proc.communicate()
160 self.assertTrue('show this help message and exit' in stdout) 153 self.assertTrue('show this help message and exit' in stdout)
161 154
162 def test_no_argument(self): 155 def test_no_argument(self):
163 """ test help invocation when no argument is provided """ 156 """ test help invocation when no argument is provided """
164 proc = subprocess.Popen([MAT_PATH], stdout=subprocess.PIPE) 157 proc = subprocess.Popen(['mat'], stdout=subprocess.PIPE)
165 stdout, _ = proc.communicate() 158 stdout, _ = proc.communicate()
166 self.assertTrue('show this help message and exit' in stdout) 159 self.assertTrue('show this help message and exit' in stdout)
167 160
168 def test_wrong_argument(self): 161 def test_wrong_argument(self):
169 """ Test MAT's behaviour on wrong argument """ 162 """ Test MAT's behaviour on wrong argument """
170 proc = subprocess.Popen([MAT_PATH, '--obviously-wrong-argument'], stderr=subprocess.PIPE) 163 proc = subprocess.Popen(['mat', '--obviously-wrong-argument'], stderr=subprocess.PIPE)
171 _, stderr = proc.communicate() 164 _, stderr = proc.communicate()
172 self.assertTrue(('usage: mat [-h]' and ' error: unrecognized arguments:') in stderr) 165 self.assertTrue(('usage: mat [-h]' and ' error: unrecognized arguments:') in stderr)
173 166