diff options
| author | jvoisin | 2019-05-08 21:27:28 +0200 |
|---|---|---|
| committer | jvoisin | 2019-05-08 21:30:54 +0200 |
| commit | 911d822c44f62b208cbb4db873576bbd5c59e2d4 (patch) | |
| tree | 9b0af2d7630809da1abb98f9d261c31a0f628c03 /tests | |
| parent | 7e031c975782da0668cfb9ed11adee3869c360ee (diff) | |
Add tests to find possible race-conditions in the cli
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_climat2.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/test_climat2.py b/tests/test_climat2.py index e17da86..61f342b 100644 --- a/tests/test_climat2.py +++ b/tests/test_climat2.py | |||
| @@ -2,6 +2,9 @@ import os | |||
| 2 | import shutil | 2 | import shutil |
| 3 | import subprocess | 3 | import subprocess |
| 4 | import unittest | 4 | import unittest |
| 5 | import glob | ||
| 6 | |||
| 7 | from libmat2 import images, parser_factory | ||
| 5 | 8 | ||
| 6 | 9 | ||
| 7 | mat2_binary = ['./mat2'] | 10 | mat2_binary = ['./mat2'] |
| @@ -181,3 +184,39 @@ class TestControlCharInjection(unittest.TestCase): | |||
| 181 | stdout=subprocess.PIPE) | 184 | stdout=subprocess.PIPE) |
| 182 | stdout, _ = proc.communicate() | 185 | stdout, _ = proc.communicate() |
| 183 | self.assertIn(b'Comment: GQ\n', stdout) | 186 | self.assertIn(b'Comment: GQ\n', stdout) |
| 187 | |||
| 188 | |||
| 189 | class TestCommandLineParallel(unittest.TestCase): | ||
| 190 | iterations = 24 | ||
| 191 | |||
| 192 | def test_same(self): | ||
| 193 | for i in range(self.iterations): | ||
| 194 | shutil.copy('./tests/data/dirty.jpg', './tests/data/dirty_%d.jpg' % i) | ||
| 195 | |||
| 196 | proc = subprocess.Popen(mat2_binary + ['./tests/data/dirty_%d.jpg' % i for i in range(self.iterations)], | ||
| 197 | stdout=subprocess.PIPE) | ||
| 198 | stdout, _ = proc.communicate() | ||
| 199 | |||
| 200 | for i in range(self.iterations): | ||
| 201 | path = './tests/data/dirty_%d.jpg' % i | ||
| 202 | p = images.JPGParser('./tests/data/dirty_%d.cleaned.jpg' % i) | ||
| 203 | self.assertEqual(p.get_meta(), {}) | ||
| 204 | os.remove('./tests/data/dirty_%d.cleaned.jpg' % i) | ||
| 205 | os.remove(path) | ||
| 206 | |||
| 207 | def test_different(self): | ||
| 208 | shutil.copytree('./tests/data/', './tests/data/parallel') | ||
| 209 | |||
| 210 | proc = subprocess.Popen(mat2_binary + glob.glob('./tests/data/parallel/dirty.*'), | ||
| 211 | stdout=subprocess.PIPE) | ||
| 212 | stdout, _ = proc.communicate() | ||
| 213 | |||
| 214 | for i in glob.glob('./test/data/parallel/dirty.cleaned.*'): | ||
| 215 | p, mime = parser_factory.get_parser(i) | ||
| 216 | self.assertIsNotNone(mime) | ||
| 217 | self.assertIsNotNone(p) | ||
| 218 | p = parser_factory.get_parser(p.output_filename) | ||
| 219 | self.assertEqual(p.get_meta(), {}) | ||
| 220 | print('DELET: %s' % i) | ||
| 221 | shutil.rmtree('./tests/data/parallel') | ||
| 222 | |||
