summaryrefslogtreecommitdiff
path: root/tests/test_climat2.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_climat2.py')
-rw-r--r--tests/test_climat2.py55
1 files changed, 32 insertions, 23 deletions
diff --git a/tests/test_climat2.py b/tests/test_climat2.py
index b84afdf..e9955db 100644
--- a/tests/test_climat2.py
+++ b/tests/test_climat2.py
@@ -2,18 +2,27 @@ import os
2import shutil 2import shutil
3import subprocess 3import subprocess
4import unittest 4import unittest
5import sys
6
7
8mat2_binary = ['./mat2']
9
10if 'MAT2_GLOBAL_PATH_TESTSUITE' in os.environ:
11 # Debian runs tests after installing the package
12 # https://0xacab.org/jvoisin/mat2/issues/16#note_153878
13 mat2_binary = ['/usr/bin/env', 'mat2']
5 14
6 15
7class TestHelp(unittest.TestCase): 16class TestHelp(unittest.TestCase):
8 def test_help(self): 17 def test_help(self):
9 proc = subprocess.Popen(['./mat2', '--help'], stdout=subprocess.PIPE) 18 proc = subprocess.Popen(mat2_binary + ['--help'], stdout=subprocess.PIPE)
10 stdout, _ = proc.communicate() 19 stdout, _ = proc.communicate()
11 self.assertIn(b'usage: mat2 [-h] [-v] [-l] [--check-dependencies] [-V]', 20 self.assertIn(b'usage: mat2 [-h] [-v] [-l] [--check-dependencies] [-V]',
12 stdout) 21 stdout)
13 self.assertIn(b'[--unknown-members policy] [-s | -L]', stdout) 22 self.assertIn(b'[--unknown-members policy] [-s | -L]', stdout)
14 23
15 def test_no_arg(self): 24 def test_no_arg(self):
16 proc = subprocess.Popen(['./mat2'], stdout=subprocess.PIPE) 25 proc = subprocess.Popen(mat2_binary, stdout=subprocess.PIPE)
17 stdout, _ = proc.communicate() 26 stdout, _ = proc.communicate()
18 self.assertIn(b'usage: mat2 [-h] [-v] [-l] [--check-dependencies] [-V]', 27 self.assertIn(b'usage: mat2 [-h] [-v] [-l] [--check-dependencies] [-V]',
19 stdout) 28 stdout)
@@ -22,29 +31,29 @@ class TestHelp(unittest.TestCase):
22 31
23class TestVersion(unittest.TestCase): 32class TestVersion(unittest.TestCase):
24 def test_version(self): 33 def test_version(self):
25 proc = subprocess.Popen(['./mat2', '--version'], stdout=subprocess.PIPE) 34 proc = subprocess.Popen(mat2_binary + ['--version'], stdout=subprocess.PIPE)
26 stdout, _ = proc.communicate() 35 stdout, _ = proc.communicate()
27 self.assertTrue(stdout.startswith(b'MAT2 ')) 36 self.assertTrue(stdout.startswith(b'MAT2 '))
28 37
29class TestDependencies(unittest.TestCase): 38class TestDependencies(unittest.TestCase):
30 def test_dependencies(self): 39 def test_dependencies(self):
31 proc = subprocess.Popen(['./mat2', '--check-dependencies'], stdout=subprocess.PIPE) 40 proc = subprocess.Popen(mat2_binary + ['--check-dependencies'], stdout=subprocess.PIPE)
32 stdout, _ = proc.communicate() 41 stdout, _ = proc.communicate()
33 self.assertTrue(b'MAT2' in stdout) 42 self.assertTrue(b'MAT2' in stdout)
34 43
35class TestReturnValue(unittest.TestCase): 44class TestReturnValue(unittest.TestCase):
36 def test_nonzero(self): 45 def test_nonzero(self):
37 ret = subprocess.call(['./mat2', './mat2'], stdout=subprocess.DEVNULL) 46 ret = subprocess.call(mat2_binary + ['mat2'], stdout=subprocess.DEVNULL)
38 self.assertEqual(255, ret) 47 self.assertEqual(255, ret)
39 48
40 ret = subprocess.call(['./mat2', '--whololo'], stderr=subprocess.DEVNULL) 49 ret = subprocess.call(mat2_binary + ['--whololo'], stderr=subprocess.DEVNULL)
41 self.assertEqual(2, ret) 50 self.assertEqual(2, ret)
42 51
43 def test_zero(self): 52 def test_zero(self):
44 ret = subprocess.call(['./mat2'], stdout=subprocess.DEVNULL) 53 ret = subprocess.call(mat2_binary, stdout=subprocess.DEVNULL)
45 self.assertEqual(0, ret) 54 self.assertEqual(0, ret)
46 55
47 ret = subprocess.call(['./mat2', '--show', './mat2'], stdout=subprocess.DEVNULL) 56 ret = subprocess.call(mat2_binary + ['--show', 'mat2'], stdout=subprocess.DEVNULL)
48 self.assertEqual(0, ret) 57 self.assertEqual(0, ret)
49 58
50 59
@@ -57,19 +66,19 @@ class TestCleanFolder(unittest.TestCase):
57 shutil.copy('./tests/data/dirty.jpg', './tests/data/folder/clean1.jpg') 66 shutil.copy('./tests/data/dirty.jpg', './tests/data/folder/clean1.jpg')
58 shutil.copy('./tests/data/dirty.jpg', './tests/data/folder/clean2.jpg') 67 shutil.copy('./tests/data/dirty.jpg', './tests/data/folder/clean2.jpg')
59 68
60 proc = subprocess.Popen(['./mat2', '--show', './tests/data/folder/'], 69 proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/folder/'],
61 stdout=subprocess.PIPE) 70 stdout=subprocess.PIPE)
62 stdout, _ = proc.communicate() 71 stdout, _ = proc.communicate()
63 self.assertIn(b'Comment: Created with GIMP', stdout) 72 self.assertIn(b'Comment: Created with GIMP', stdout)
64 73
65 proc = subprocess.Popen(['./mat2', './tests/data/folder/'], 74 proc = subprocess.Popen(mat2_binary + ['./tests/data/folder/'],
66 stdout=subprocess.PIPE) 75 stdout=subprocess.PIPE)
67 stdout, _ = proc.communicate() 76 stdout, _ = proc.communicate()
68 77
69 os.remove('./tests/data/folder/clean1.jpg') 78 os.remove('./tests/data/folder/clean1.jpg')
70 os.remove('./tests/data/folder/clean2.jpg') 79 os.remove('./tests/data/folder/clean2.jpg')
71 80
72 proc = subprocess.Popen(['./mat2', '--show', './tests/data/folder/'], 81 proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/folder/'],
73 stdout=subprocess.PIPE) 82 stdout=subprocess.PIPE)
74 stdout, _ = proc.communicate() 83 stdout, _ = proc.communicate()
75 self.assertNotIn(b'Comment: Created with GIMP', stdout) 84 self.assertNotIn(b'Comment: Created with GIMP', stdout)
@@ -81,16 +90,16 @@ class TestCleanMeta(unittest.TestCase):
81 def test_jpg(self): 90 def test_jpg(self):
82 shutil.copy('./tests/data/dirty.jpg', './tests/data/clean.jpg') 91 shutil.copy('./tests/data/dirty.jpg', './tests/data/clean.jpg')
83 92
84 proc = subprocess.Popen(['./mat2', '--show', './tests/data/clean.jpg'], 93 proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/clean.jpg'],
85 stdout=subprocess.PIPE) 94 stdout=subprocess.PIPE)
86 stdout, _ = proc.communicate() 95 stdout, _ = proc.communicate()
87 self.assertIn(b'Comment: Created with GIMP', stdout) 96 self.assertIn(b'Comment: Created with GIMP', stdout)
88 97
89 proc = subprocess.Popen(['./mat2', './tests/data/clean.jpg'], 98 proc = subprocess.Popen(mat2_binary + ['./tests/data/clean.jpg'],
90 stdout=subprocess.PIPE) 99 stdout=subprocess.PIPE)
91 stdout, _ = proc.communicate() 100 stdout, _ = proc.communicate()
92 101
93 proc = subprocess.Popen(['./mat2', '--show', './tests/data/clean.cleaned.jpg'], 102 proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/clean.cleaned.jpg'],
94 stdout=subprocess.PIPE) 103 stdout=subprocess.PIPE)
95 stdout, _ = proc.communicate() 104 stdout, _ = proc.communicate()
96 self.assertNotIn(b'Comment: Created with GIMP', stdout) 105 self.assertNotIn(b'Comment: Created with GIMP', stdout)
@@ -100,32 +109,32 @@ class TestCleanMeta(unittest.TestCase):
100 109
101class TestIsSupported(unittest.TestCase): 110class TestIsSupported(unittest.TestCase):
102 def test_pdf(self): 111 def test_pdf(self):
103 proc = subprocess.Popen(['./mat2', '--show', './tests/data/dirty.pdf'], 112 proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/dirty.pdf'],
104 stdout=subprocess.PIPE) 113 stdout=subprocess.PIPE)
105 stdout, _ = proc.communicate() 114 stdout, _ = proc.communicate()
106 self.assertNotIn(b"isn't supported", stdout) 115 self.assertNotIn(b"isn't supported", stdout)
107 116
108class TestGetMeta(unittest.TestCase): 117class TestGetMeta(unittest.TestCase):
109 def test_pdf(self): 118 def test_pdf(self):
110 proc = subprocess.Popen(['./mat2', '--show', './tests/data/dirty.pdf'], 119 proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/dirty.pdf'],
111 stdout=subprocess.PIPE) 120 stdout=subprocess.PIPE)
112 stdout, _ = proc.communicate() 121 stdout, _ = proc.communicate()
113 self.assertIn(b'producer: pdfTeX-1.40.14', stdout) 122 self.assertIn(b'producer: pdfTeX-1.40.14', stdout)
114 123
115 def test_png(self): 124 def test_png(self):
116 proc = subprocess.Popen(['./mat2', '--show', './tests/data/dirty.png'], 125 proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/dirty.png'],
117 stdout=subprocess.PIPE) 126 stdout=subprocess.PIPE)
118 stdout, _ = proc.communicate() 127 stdout, _ = proc.communicate()
119 self.assertIn(b'Comment: This is a comment, be careful!', stdout) 128 self.assertIn(b'Comment: This is a comment, be careful!', stdout)
120 129
121 def test_jpg(self): 130 def test_jpg(self):
122 proc = subprocess.Popen(['./mat2', '--show', './tests/data/dirty.jpg'], 131 proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/dirty.jpg'],
123 stdout=subprocess.PIPE) 132 stdout=subprocess.PIPE)
124 stdout, _ = proc.communicate() 133 stdout, _ = proc.communicate()
125 self.assertIn(b'Comment: Created with GIMP', stdout) 134 self.assertIn(b'Comment: Created with GIMP', stdout)
126 135
127 def test_docx(self): 136 def test_docx(self):
128 proc = subprocess.Popen(['./mat2', '--show', './tests/data/dirty.docx'], 137 proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/dirty.docx'],
129 stdout=subprocess.PIPE) 138 stdout=subprocess.PIPE)
130 stdout, _ = proc.communicate() 139 stdout, _ = proc.communicate()
131 self.assertIn(b'Application: LibreOffice/5.4.5.1$Linux_X86_64', stdout) 140 self.assertIn(b'Application: LibreOffice/5.4.5.1$Linux_X86_64', stdout)
@@ -133,7 +142,7 @@ class TestGetMeta(unittest.TestCase):
133 self.assertIn(b'revision: 1', stdout) 142 self.assertIn(b'revision: 1', stdout)
134 143
135 def test_odt(self): 144 def test_odt(self):
136 proc = subprocess.Popen(['./mat2', '--show', './tests/data/dirty.odt'], 145 proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/dirty.odt'],
137 stdout=subprocess.PIPE) 146 stdout=subprocess.PIPE)
138 stdout, _ = proc.communicate() 147 stdout, _ = proc.communicate()
139 self.assertIn(b'generator: LibreOffice/3.3$Unix', stdout) 148 self.assertIn(b'generator: LibreOffice/3.3$Unix', stdout)
@@ -141,14 +150,14 @@ class TestGetMeta(unittest.TestCase):
141 self.assertIn(b'date_time: 2011-07-26 02:40:16', stdout) 150 self.assertIn(b'date_time: 2011-07-26 02:40:16', stdout)
142 151
143 def test_mp3(self): 152 def test_mp3(self):
144 proc = subprocess.Popen(['./mat2', '--show', './tests/data/dirty.mp3'], 153 proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/dirty.mp3'],
145 stdout=subprocess.PIPE) 154 stdout=subprocess.PIPE)
146 stdout, _ = proc.communicate() 155 stdout, _ = proc.communicate()
147 self.assertIn(b'TALB: harmfull', stdout) 156 self.assertIn(b'TALB: harmfull', stdout)
148 self.assertIn(b'COMM::: Thank you for using MAT !', stdout) 157 self.assertIn(b'COMM::: Thank you for using MAT !', stdout)
149 158
150 def test_flac(self): 159 def test_flac(self):
151 proc = subprocess.Popen(['./mat2', '--show', './tests/data/dirty.flac'], 160 proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/dirty.flac'],
152 stdout=subprocess.PIPE) 161 stdout=subprocess.PIPE)
153 stdout, _ = proc.communicate() 162 stdout, _ = proc.communicate()
154 self.assertIn(b'comments: Thank you for using MAT !', stdout) 163 self.assertIn(b'comments: Thank you for using MAT !', stdout)
@@ -156,7 +165,7 @@ class TestGetMeta(unittest.TestCase):
156 self.assertIn(b'title: I am so', stdout) 165 self.assertIn(b'title: I am so', stdout)
157 166
158 def test_ogg(self): 167 def test_ogg(self):
159 proc = subprocess.Popen(['./mat2', '--show', './tests/data/dirty.ogg'], 168 proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/dirty.ogg'],
160 stdout=subprocess.PIPE) 169 stdout=subprocess.PIPE)
161 stdout, _ = proc.communicate() 170 stdout, _ = proc.communicate()
162 self.assertIn(b'comments: Thank you for using MAT !', stdout) 171 self.assertIn(b'comments: Thank you for using MAT !', stdout)