summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjvoisin2015-12-30 13:12:39 +0100
committerjvoisin2015-12-30 15:11:37 +0100
commit3ac3f353c64d406aa2fa46c5c9841346408e1e01 (patch)
tree562f27ff88253c693d4adc3acfe82693737c78a4
parentb9d66ed2e07d0a40161c88d0ba52d59ac601c76e (diff)
Hopefully make test suite work once copied out of the build tree
This should fix https://labs.riseup.net/code/issues/10065
-rwxr-xr-xsetup.py1
-rw-r--r--test/__init__.py3
-rw-r--r--test/clitest.py39
-rw-r--r--test/libtest.py5
-rw-r--r--test/test.py21
5 files changed, 31 insertions, 38 deletions
diff --git a/setup.py b/setup.py
index 295afb5..ad798d7 100755
--- a/setup.py
+++ b/setup.py
@@ -25,6 +25,7 @@ class PyTest(Command):
25 def run(self): 25 def run(self):
26 os.chdir('test') 26 os.chdir('test')
27 import test 27 import test
28 test.test.set_local()
28 test.test.run_all_tests() 29 test.test.run_all_tests()
29 30
30setup( 31setup(
diff --git a/test/__init__.py b/test/__init__.py
index d046cd3..6ec2813 100644
--- a/test/__init__.py
+++ b/test/__init__.py
@@ -1,2 +1 @@
1import clitest import test
2import libtest
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
diff --git a/test/libtest.py b/test/libtest.py
index 64b2c78..98cb4ea 100644
--- a/test/libtest.py
+++ b/test/libtest.py
@@ -14,11 +14,6 @@ import tempfile
14import unittest 14import unittest
15 15
16import test 16import test
17if test.IS_LOCAL is True:
18 # Are we testing the _local_ version of MAT?
19 sys.path.insert(0, '..')
20# else it will be in the path
21
22import libmat 17import libmat
23 18
24 19
diff --git a/test/test.py b/test/test.py
index 3f259a7..fbbdcf4 100644
--- a/test/test.py
+++ b/test/test.py
@@ -15,8 +15,6 @@ import sys
15import tempfile 15import tempfile
16import unittest 16import unittest
17 17
18IS_LOCAL = True
19
20VERBOSITY = 15 18VERBOSITY = 15
21 19
22clean = glob.glob('clean*') 20clean = glob.glob('clean*')
@@ -80,10 +78,9 @@ def run_all_tests():
80 """ 78 """
81 This method will run all tests, both for cli and lib. 79 This method will run all tests, both for cli and lib.
82 The imports of clitest and libtest are done here because 80 The imports of clitest and libtest are done here because
83 of dependencie on the IS_LOCAL variable. 81 we're modifying the PATH (technically, it's two path:
84 82 the one used to spawn the `mat` process, and the one for Python import)
85 If set to true, the tests will be done on the _local_ instance 83 in the main function.
86 of MAT, else, on the _system-wide_ one.
87 """ 84 """
88 import clitest 85 import clitest
89 import libtest 86 import libtest
@@ -93,6 +90,14 @@ def run_all_tests():
93 90
94 return unittest.TextTestRunner(verbosity=VERBOSITY).run(SUITE).wasSuccessful() 91 return unittest.TextTestRunner(verbosity=VERBOSITY).run(SUITE).wasSuccessful()
95 92
93def set_local():
94 ''' Monkey patch pathes to run the testsuite on the _local_
95 version of MAT. See `run_all_tests` for more information about
96 what pathes we're changing and why.
97 '''
98 os.environ['PATH'] = '..:' + os.environ['PATH']
99 sys.path.append('..')
100
96if __name__ == '__main__': 101if __name__ == '__main__':
97 import argparse 102 import argparse
98 103
@@ -100,7 +105,7 @@ if __name__ == '__main__':
100 parser.add_argument('-s', '--system', action='store_true', 105 parser.add_argument('-s', '--system', action='store_true',
101 help='Test the system-wide version of mat') 106 help='Test the system-wide version of mat')
102 107
103 if parser.parse_args().system is True: 108 if parser.parse_args().system is False:
104 IS_LOCAL = False 109 set_local()
105 110
106 sys.exit(run_all_tests() is False) 111 sys.exit(run_all_tests() is False)