summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_corrupted_files.py7
-rw-r--r--tests/test_libmat2.py36
-rw-r--r--tests/test_lightweigh_cleaning.py65
3 files changed, 72 insertions, 36 deletions
diff --git a/tests/test_corrupted_files.py b/tests/test_corrupted_files.py
index 82c6c3b..181d4d2 100644
--- a/tests/test_corrupted_files.py
+++ b/tests/test_corrupted_files.py
@@ -194,6 +194,13 @@ class TestCorruptedFiles(unittest.TestCase):
194 images.JPGParser('./tests/data/clean.jpg') 194 images.JPGParser('./tests/data/clean.jpg')
195 os.remove('./tests/data/clean.jpg') 195 os.remove('./tests/data/clean.jpg')
196 196
197 def test_png_lightweight(self):
198 return
199 shutil.copy('./tests/data/dirty.torrent', './tests/data/clean.png')
200 p = images.PNGParser('./tests/data/clean.png')
201 self.assertTrue(p.remove_all())
202 os.remove('./tests/data/clean.png')
203
197 def test_avi(self): 204 def test_avi(self):
198 try: 205 try:
199 video._get_ffmpeg_path() 206 video._get_ffmpeg_path()
diff --git a/tests/test_libmat2.py b/tests/test_libmat2.py
index f5fc9e8..46d6aaa 100644
--- a/tests/test_libmat2.py
+++ b/tests/test_libmat2.py
@@ -212,42 +212,6 @@ class TestRevisionsCleaning(unittest.TestCase):
212 os.remove('./tests/data/revision_clean.docx') 212 os.remove('./tests/data/revision_clean.docx')
213 os.remove('./tests/data/revision_clean.cleaned.docx') 213 os.remove('./tests/data/revision_clean.cleaned.docx')
214 214
215class TestLightWeightCleaning(unittest.TestCase):
216 def test_pdf(self):
217 shutil.copy('./tests/data/dirty.pdf', './tests/data/clean.pdf')
218 p = pdf.PDFParser('./tests/data/clean.pdf')
219
220 meta = p.get_meta()
221 self.assertEqual(meta['producer'], 'pdfTeX-1.40.14')
222
223 p.lightweight_cleaning = True
224 ret = p.remove_all()
225 self.assertTrue(ret)
226
227 p = pdf.PDFParser('./tests/data/clean.cleaned.pdf')
228 expected_meta = {'creation-date': -1, 'format': 'PDF-1.5', 'mod-date': -1}
229 self.assertEqual(p.get_meta(), expected_meta)
230
231 os.remove('./tests/data/clean.pdf')
232 os.remove('./tests/data/clean.cleaned.pdf')
233
234 def test_png(self):
235 shutil.copy('./tests/data/dirty.png', './tests/data/clean.png')
236 p = images.PNGParser('./tests/data/clean.png')
237
238 meta = p.get_meta()
239 self.assertEqual(meta['Comment'], 'This is a comment, be careful!')
240
241 p.lightweight_cleaning = True
242 ret = p.remove_all()
243 self.assertTrue(ret)
244
245 p = images.PNGParser('./tests/data/clean.cleaned.png')
246 self.assertEqual(p.get_meta(), {})
247
248 os.remove('./tests/data/clean.png')
249 os.remove('./tests/data/clean.cleaned.png')
250
251class TestCleaning(unittest.TestCase): 215class TestCleaning(unittest.TestCase):
252 def test_pdf(self): 216 def test_pdf(self):
253 shutil.copy('./tests/data/dirty.pdf', './tests/data/clean.pdf') 217 shutil.copy('./tests/data/dirty.pdf', './tests/data/clean.pdf')
diff --git a/tests/test_lightweigh_cleaning.py b/tests/test_lightweigh_cleaning.py
new file mode 100644
index 0000000..7af31ad
--- /dev/null
+++ b/tests/test_lightweigh_cleaning.py
@@ -0,0 +1,65 @@
1#!/usr/bin/env python3
2
3import unittest
4import shutil
5import os
6
7from libmat2 import pdf, images
8
9class TestLightWeightCleaning(unittest.TestCase):
10 def test_pdf(self):
11 shutil.copy('./tests/data/dirty.pdf', './tests/data/clean.pdf')
12 p = pdf.PDFParser('./tests/data/clean.pdf')
13
14 meta = p.get_meta()
15 self.assertEqual(meta['producer'], 'pdfTeX-1.40.14')
16
17 p.lightweight_cleaning = True
18 ret = p.remove_all()
19 self.assertTrue(ret)
20
21 p = pdf.PDFParser('./tests/data/clean.cleaned.pdf')
22 expected_meta = {'creation-date': -1, 'format': 'PDF-1.5', 'mod-date': -1}
23 self.assertEqual(p.get_meta(), expected_meta)
24
25 os.remove('./tests/data/clean.pdf')
26 os.remove('./tests/data/clean.cleaned.pdf')
27
28 def test_png(self):
29 shutil.copy('./tests/data/dirty.png', './tests/data/clean.png')
30 p = images.PNGParser('./tests/data/clean.png')
31
32 meta = p.get_meta()
33 self.assertEqual(meta['Comment'], 'This is a comment, be careful!')
34
35 p.lightweight_cleaning = True
36 ret = p.remove_all()
37 self.assertTrue(ret)
38
39 p = images.PNGParser('./tests/data/clean.cleaned.png')
40 self.assertEqual(p.get_meta(), {})
41
42 p = images.PNGParser('./tests/data/clean.png')
43 p.lightweight_cleaning = True
44 ret = p.remove_all()
45 self.assertTrue(ret)
46
47 os.remove('./tests/data/clean.png')
48 os.remove('./tests/data/clean.cleaned.png')
49
50 def test_jpg(self):
51 shutil.copy('./tests/data/dirty.jpg', './tests/data/clean.jpg')
52 p = images.JPGParser('./tests/data/clean.jpg')
53
54 meta = p.get_meta()
55 self.assertEqual(meta['Comment'], 'Created with GIMP')
56
57 p.lightweight_cleaning = True
58 ret = p.remove_all()
59 self.assertTrue(ret)
60
61 p = images.JPGParser('./tests/data/clean.cleaned.jpg')
62 self.assertEqual(p.get_meta(), {})
63
64 os.remove('./tests/data/clean.jpg')
65 os.remove('./tests/data/clean.cleaned.jpg')