summaryrefslogtreecommitdiff
path: root/tests/test_lightweight_cleaning.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_lightweight_cleaning.py')
-rw-r--r--tests/test_lightweight_cleaning.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/test_lightweight_cleaning.py b/tests/test_lightweight_cleaning.py
new file mode 100644
index 0000000..38e06dc
--- /dev/null
+++ b/tests/test_lightweight_cleaning.py
@@ -0,0 +1,76 @@
1#!/usr/bin/env python3
2
3import unittest
4import shutil
5import os
6
7from libmat2 import pdf, images, torrent
8
9
10class TestLightWeightCleaning(unittest.TestCase):
11 data = [{
12 'name': 'pdf',
13 'parser': pdf.PDFParser,
14 'meta': {'producer': 'pdfTeX-1.40.14'},
15 'expected_meta': {'creation-date': -1, 'format': 'PDF-1.5', 'mod-date': -1},
16 }, {
17 'name': 'png',
18 'parser': images.PNGParser,
19 'meta': {'Comment': 'This is a comment, be careful!'},
20 'expected_meta': {},
21 }, {
22 'name': 'jpg',
23 'parser': images.JPGParser,
24 'meta': {'Comment': 'Created with GIMP'},
25 'expected_meta': {},
26 }, {
27 'name': 'torrent',
28 'parser': torrent.TorrentParser,
29 'meta': {'created by': b'mktorrent 1.0'},
30 'expected_meta': {},
31 },{
32 'name': 'tiff',
33 'parser': images.TiffParser,
34 'meta': {'ImageDescription': 'OLYMPUS DIGITAL CAMERA '},
35 'expected_meta': {
36 'Orientation': 'Horizontal (normal)',
37 'ResolutionUnit': 'inches',
38 'XResolution': 72,
39 'YResolution': 72
40 }
41 },
42 ]
43
44 def test_all(self):
45 for case in self.data:
46 target = './tests/data/clean.' + case['name']
47 shutil.copy('./tests/data/dirty.' + case['name'], target)
48 p1 = case['parser'](target)
49
50 meta = p1.get_meta()
51 for k, v in case['meta'].items():
52 self.assertEqual(meta[k], v)
53
54 p1.lightweight_cleaning = True
55 self.assertTrue(p1.remove_all())
56
57 p2 = case['parser'](p1.output_filename)
58 self.assertEqual(p2.get_meta(), case['expected_meta'])
59
60 os.remove(target)
61 os.remove(p1.output_filename)
62
63 def test_exiftool_overwrite(self):
64 target = './tests/data/clean.png'
65 shutil.copy('./tests/data/dirty.png', target)
66
67 p1 = images.PNGParser(target)
68 p1.lightweight_cleaning = True
69 shutil.copy('./tests/data/dirty.png', p1.output_filename)
70 self.assertTrue(p1.remove_all())
71
72 p2 = images.PNGParser(p1.output_filename)
73 self.assertEqual(p2.get_meta(), {})
74
75 os.remove(target)
76 os.remove(p1.output_filename)