diff options
| author | jvoisin | 2018-10-23 16:14:21 +0200 |
|---|---|---|
| committer | jvoisin | 2018-10-23 16:22:11 +0200 |
| commit | f1a071d460507fd1bb1721deafd2a8d9f88f5b05 (patch) | |
| tree | e17067895ef1fc9b91b00c0ba56d2e86975ceef1 /tests/test_lightweigh_cleaning.py | |
| parent | 38df679a88a19db3a4a82fdb8e20a42c9a53d1a1 (diff) | |
Implement lightweight cleaning for png and tiff
Diffstat (limited to 'tests/test_lightweigh_cleaning.py')
| -rw-r--r-- | tests/test_lightweigh_cleaning.py | 65 |
1 files changed, 65 insertions, 0 deletions
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 | |||
| 3 | import unittest | ||
| 4 | import shutil | ||
| 5 | import os | ||
| 6 | |||
| 7 | from libmat2 import pdf, images | ||
| 8 | |||
| 9 | class 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') | ||
