diff options
Diffstat (limited to 'tests/test_libmat2.py')
| -rw-r--r-- | tests/test_libmat2.py | 63 |
1 files changed, 60 insertions, 3 deletions
diff --git a/tests/test_libmat2.py b/tests/test_libmat2.py index 8753e09..249c56d 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, archive, html | 9 | from libmat2 import check_dependencies, video, archive, web, epub |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | class TestCheckDependencies(unittest.TestCase): | 12 | class TestCheckDependencies(unittest.TestCase): |
| @@ -177,6 +177,23 @@ class TestGetMeta(unittest.TestCase): | |||
| 177 | meta = p.get_meta() | 177 | meta = p.get_meta() |
| 178 | self.assertEqual(meta['Comment'], 'this is a test comment') | 178 | self.assertEqual(meta['Comment'], 'this is a test comment') |
| 179 | 179 | ||
| 180 | def test_epub(self): | ||
| 181 | p, mimetype = parser_factory.get_parser('./tests/data/dirty.epub') | ||
| 182 | self.assertEqual(mimetype, 'application/epub+zip') | ||
| 183 | meta = p.get_meta() | ||
| 184 | self.assertEqual(meta['OEBPS/content.opf']['dc:creator'], 'Dorothy L. Sayers') | ||
| 185 | self.assertEqual(meta['OEBPS/toc.ncx']['dtb:generator'], 'Ebookmaker 0.4.0a5 by Marcello Perathoner <webmaster@gutenberg.org>') | ||
| 186 | self.assertEqual(meta['OEBPS/@public@vhost@g@gutenberg@html@files@58820@58820-h@images@shield25.jpg']['CreatorTool'], 'Adobe Photoshop CS5 Macintosh') | ||
| 187 | self.assertEqual(meta['OEBPS/@public@vhost@g@gutenberg@html@files@58820@58820-h@58820-h-2.htm.html']['generator'], 'Ebookmaker 0.4.0a5 by Marcello Perathoner <webmaster@gutenberg.org>') | ||
| 188 | |||
| 189 | def test_css(self): | ||
| 190 | p, mimetype = parser_factory.get_parser('./tests/data/dirty.css') | ||
| 191 | self.assertEqual(mimetype, 'text/css') | ||
| 192 | meta = p.get_meta() | ||
| 193 | self.assertEqual(meta['author'], 'jvoisin') | ||
| 194 | self.assertEqual(meta['version'], '1.0') | ||
| 195 | self.assertEqual(meta['harmful data'], 'underline is cool') | ||
| 196 | |||
| 180 | class TestRemovingThumbnails(unittest.TestCase): | 197 | class TestRemovingThumbnails(unittest.TestCase): |
| 181 | def test_odt(self): | 198 | def test_odt(self): |
| 182 | shutil.copy('./tests/data/revision.odt', './tests/data/clean.odt') | 199 | shutil.copy('./tests/data/revision.odt', './tests/data/clean.odt') |
| @@ -599,7 +616,7 @@ class TestCleaning(unittest.TestCase): | |||
| 599 | 616 | ||
| 600 | def test_html(self): | 617 | def test_html(self): |
| 601 | shutil.copy('./tests/data/dirty.html', './tests/data/clean.html') | 618 | shutil.copy('./tests/data/dirty.html', './tests/data/clean.html') |
| 602 | p = html.HTMLParser('./tests/data/clean.html') | 619 | p = web.HTMLParser('./tests/data/clean.html') |
| 603 | 620 | ||
| 604 | meta = p.get_meta() | 621 | meta = p.get_meta() |
| 605 | self.assertEqual(meta['author'], 'jvoisin') | 622 | self.assertEqual(meta['author'], 'jvoisin') |
| @@ -607,10 +624,50 @@ class TestCleaning(unittest.TestCase): | |||
| 607 | ret = p.remove_all() | 624 | ret = p.remove_all() |
| 608 | self.assertTrue(ret) | 625 | self.assertTrue(ret) |
| 609 | 626 | ||
| 610 | p = html.HTMLParser('./tests/data/clean.cleaned.html') | 627 | p = web.HTMLParser('./tests/data/clean.cleaned.html') |
| 611 | self.assertEqual(p.get_meta(), {}) | 628 | self.assertEqual(p.get_meta(), {}) |
| 612 | self.assertTrue(p.remove_all()) | 629 | self.assertTrue(p.remove_all()) |
| 613 | 630 | ||
| 614 | os.remove('./tests/data/clean.html') | 631 | os.remove('./tests/data/clean.html') |
| 615 | os.remove('./tests/data/clean.cleaned.html') | 632 | os.remove('./tests/data/clean.cleaned.html') |
| 616 | os.remove('./tests/data/clean.cleaned.cleaned.html') | 633 | os.remove('./tests/data/clean.cleaned.cleaned.html') |
| 634 | |||
| 635 | |||
| 636 | def test_epub(self): | ||
| 637 | shutil.copy('./tests/data/dirty.epub', './tests/data/clean.epub') | ||
| 638 | p = epub.EPUBParser('./tests/data/clean.epub') | ||
| 639 | |||
| 640 | meta = p.get_meta() | ||
| 641 | self.assertEqual(meta['OEBPS/content.opf']['dc:source'], 'http://www.gutenberg.org/files/58820/58820-h/58820-h.htm') | ||
| 642 | |||
| 643 | ret = p.remove_all() | ||
| 644 | self.assertTrue(ret) | ||
| 645 | |||
| 646 | p = epub.EPUBParser('./tests/data/clean.cleaned.epub') | ||
| 647 | self.assertEqual(p.get_meta(), {}) | ||
| 648 | self.assertTrue(p.remove_all()) | ||
| 649 | |||
| 650 | os.remove('./tests/data/clean.epub') | ||
| 651 | os.remove('./tests/data/clean.cleaned.epub') | ||
| 652 | os.remove('./tests/data/clean.cleaned.cleaned.epub') | ||
| 653 | |||
| 654 | |||
| 655 | def test_css(self): | ||
| 656 | shutil.copy('./tests/data/dirty.css', './tests/data/clean.css') | ||
| 657 | p = web.CSSParser('./tests/data/clean.css') | ||
| 658 | |||
| 659 | self.assertEqual(p.get_meta(), { | ||
| 660 | 'harmful data': 'underline is cool', | ||
| 661 | 'version': '1.0', | ||
| 662 | 'author': 'jvoisin'}) | ||
| 663 | |||
| 664 | ret = p.remove_all() | ||
| 665 | self.assertTrue(ret) | ||
| 666 | |||
| 667 | p = web.CSSParser('./tests/data/clean.cleaned.css') | ||
| 668 | self.assertEqual(p.get_meta(), {}) | ||
| 669 | self.assertTrue(p.remove_all()) | ||
| 670 | |||
| 671 | os.remove('./tests/data/clean.css') | ||
| 672 | os.remove('./tests/data/clean.cleaned.css') | ||
| 673 | os.remove('./tests/data/clean.cleaned.cleaned.css') | ||
