From fe1950ac3ee8865e826b6d95a7f3bcf6260b9698 Mon Sep 17 00:00:00 2001
From: jvoisin <julien.voisin@dustri.org>
Date: Thu, 9 May 2019 21:08:52 +0200
Subject: [PATCH] Test the cli's behaviour with valid and invalid files

This should ensure that if we decide to implement
some threading in the cli, a faulty file
won't break everything.
---
 tests/test_climat2.py | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/tests/test_climat2.py b/tests/test_climat2.py
index 61f342b..4a46644 100644
--- a/tests/test_climat2.py
+++ b/tests/test_climat2.py
@@ -1,3 +1,4 @@
+import random
 import os
 import shutil
 import subprocess
@@ -217,6 +218,24 @@ class TestCommandLineParallel(unittest.TestCase):
             self.assertIsNotNone(p)
             p = parser_factory.get_parser(p.output_filename)
             self.assertEqual(p.get_meta(), {})
-            print('DELET: %s' % i)
         shutil.rmtree('./tests/data/parallel')
 
+    def test_faulty(self):
+        for i in range(self.iterations):
+            shutil.copy('./tests/data/dirty.jpg', './tests/data/dirty_%d.jpg' % i)
+            shutil.copy('./tests/data/dirty.torrent', './tests/data/dirty_%d.docx' % i)
+
+        to_process = ['./tests/data/dirty_%d.jpg' % i for i in range(self.iterations)]
+        to_process.extend(['./tests/data/dirty_%d.docx' % i for i in range(self.iterations)])
+        random.shuffle(to_process)
+        proc = subprocess.Popen(mat2_binary + to_process,
+                stdout=subprocess.PIPE)
+        stdout, _ = proc.communicate()
+
+        for i in range(self.iterations):
+            path = './tests/data/dirty_%d.jpg' % i
+            p = images.JPGParser('./tests/data/dirty_%d.cleaned.jpg' % i)
+            self.assertEqual(p.get_meta(), {})
+            os.remove('./tests/data/dirty_%d.cleaned.jpg' % i)
+            os.remove(path)
+            os.remove('./tests/data/dirty_%d.docx' % i)
-- 
GitLab