diff options
| author | jvoisin | 2018-10-25 11:56:46 +0200 |
|---|---|---|
| committer | jvoisin | 2018-10-25 11:56:46 +0200 |
| commit | 3a070b0ab70c4d4a456bdd12d0cd490ad127e320 (patch) | |
| tree | 2a6e5a913136a49e9a70393fa030ea4eb67cbab0 /tests/test_libmat2.py | |
| parent | 283e5e57877b21e34eb4612d3201c2e0682190d5 (diff) | |
Add support for zip files
Diffstat (limited to 'tests/test_libmat2.py')
| -rw-r--r-- | tests/test_libmat2.py | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/tests/test_libmat2.py b/tests/test_libmat2.py index 46d6aaa..1602480 100644 --- a/tests/test_libmat2.py +++ b/tests/test_libmat2.py | |||
| @@ -6,7 +6,7 @@ import os | |||
| 6 | import zipfile | 6 | import zipfile |
| 7 | 7 | ||
| 8 | from libmat2 import pdf, images, audio, office, parser_factory, torrent, harmless | 8 | from libmat2 import pdf, images, audio, office, parser_factory, torrent, harmless |
| 9 | from libmat2 import check_dependencies, video | 9 | from libmat2 import check_dependencies, video, archive |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | class TestCheckDependencies(unittest.TestCase): | 12 | class TestCheckDependencies(unittest.TestCase): |
| @@ -153,6 +153,18 @@ class TestGetMeta(unittest.TestCase): | |||
| 153 | meta = p.get_meta() | 153 | meta = p.get_meta() |
| 154 | self.assertEqual(meta, {}) | 154 | self.assertEqual(meta, {}) |
| 155 | 155 | ||
| 156 | def test_zip(self): | ||
| 157 | with zipfile.ZipFile('./tests/data/dirty.zip', 'w') as zout: | ||
| 158 | zout.write('./tests/data/dirty.flac') | ||
| 159 | zout.write('./tests/data/dirty.docx') | ||
| 160 | zout.write('./tests/data/dirty.jpg') | ||
| 161 | p, mimetype = parser_factory.get_parser('./tests/data/dirty.zip') | ||
| 162 | self.assertEqual(mimetype, 'application/zip') | ||
| 163 | meta = p.get_meta() | ||
| 164 | self.assertEqual(meta['tests/data/dirty.flac']['comments'], 'Thank you for using MAT !') | ||
| 165 | self.assertEqual(meta['tests/data/dirty.docx']['word/media/image1.png']['Comment'], 'This is a comment, be careful!') | ||
| 166 | os.remove('./tests/data/dirty.zip') | ||
| 167 | |||
| 156 | 168 | ||
| 157 | class TestRemovingThumbnails(unittest.TestCase): | 169 | class TestRemovingThumbnails(unittest.TestCase): |
| 158 | def test_odt(self): | 170 | def test_odt(self): |
| @@ -488,3 +500,24 @@ class TestCleaning(unittest.TestCase): | |||
| 488 | os.remove('./tests/data/clean.avi') | 500 | os.remove('./tests/data/clean.avi') |
| 489 | os.remove('./tests/data/clean.cleaned.avi') | 501 | os.remove('./tests/data/clean.cleaned.avi') |
| 490 | os.remove('./tests/data/clean.cleaned.cleaned.avi') | 502 | os.remove('./tests/data/clean.cleaned.cleaned.avi') |
| 503 | |||
| 504 | def test_zip(self): | ||
| 505 | with zipfile.ZipFile('./tests/data/dirty.zip', 'w') as zout: | ||
| 506 | zout.write('./tests/data/dirty.flac') | ||
| 507 | zout.write('./tests/data/dirty.docx') | ||
| 508 | zout.write('./tests/data/dirty.jpg') | ||
| 509 | p = archive.ZipParser('./tests/data/dirty.zip') | ||
| 510 | meta = p.get_meta() | ||
| 511 | self.assertEqual(meta['tests/data/dirty.docx']['word/media/image1.png']['Comment'], 'This is a comment, be careful!') | ||
| 512 | |||
| 513 | ret = p.remove_all() | ||
| 514 | self.assertTrue(ret) | ||
| 515 | |||
| 516 | p = archive.ZipParser('./tests/data/dirty.cleaned.zip') | ||
| 517 | self.assertEqual(p.get_meta(), {}) | ||
| 518 | self.assertTrue(p.remove_all()) | ||
| 519 | |||
| 520 | os.remove('./tests/data/dirty.zip') | ||
| 521 | os.remove('./tests/data/dirty.cleaned.zip') | ||
| 522 | os.remove('./tests/data/dirty.cleaned.cleaned.zip') | ||
| 523 | |||
