diff options
| author | jvoisin | 2018-06-22 21:16:55 +0200 |
|---|---|---|
| committer | jvoisin | 2018-06-22 21:16:55 +0200 |
| commit | 74f2d50433a831787fe7ab791748c8efa854ada2 (patch) | |
| tree | 69e55499a8ce97f943c33dcedf0de7a2ade6981f /tests/test_corrupted_files.py | |
| parent | b4ef0c9622a0741bcfa0da1f65d9082251fb4107 (diff) | |
Split the testsuite a bit and add more tests
Diffstat (limited to 'tests/test_corrupted_files.py')
| -rw-r--r-- | tests/test_corrupted_files.py | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/test_corrupted_files.py b/tests/test_corrupted_files.py new file mode 100644 index 0000000..b784b0e --- /dev/null +++ b/tests/test_corrupted_files.py | |||
| @@ -0,0 +1,88 @@ | |||
| 1 | #!/usr/bin/python3 | ||
| 2 | |||
| 3 | import unittest | ||
| 4 | import shutil | ||
| 5 | import os | ||
| 6 | |||
| 7 | from libmat2 import pdf, images, audio, office, parser_factory, torrent | ||
| 8 | |||
| 9 | |||
| 10 | class TestUnsupportedFiles(unittest.TestCase): | ||
| 11 | def test_pdf(self): | ||
| 12 | shutil.copy('./tests/test_libmat2.py', './tests/clean.py') | ||
| 13 | parser, mimetype = parser_factory.get_parser('./tests/data/clean.py') | ||
| 14 | self.assertEqual(mimetype, 'text/x-python') | ||
| 15 | self.assertEqual(parser, None) | ||
| 16 | os.remove('./tests/clean.py') | ||
| 17 | |||
| 18 | |||
| 19 | class TestExplicitelyUnsupportedFiles(unittest.TestCase): | ||
| 20 | def test_pdf(self): | ||
| 21 | shutil.copy('./tests/test_libmat2.py', './tests/clean.txt') | ||
| 22 | parser, mimetype = parser_factory.get_parser('./tests/data/clean.txt') | ||
| 23 | self.assertEqual(mimetype, 'text/plain') | ||
| 24 | self.assertEqual(parser, None) | ||
| 25 | os.remove('./tests/clean.txt') | ||
| 26 | |||
| 27 | |||
| 28 | class TestCorruptedFiles(unittest.TestCase): | ||
| 29 | def test_pdf(self): | ||
| 30 | shutil.copy('./tests/data/dirty.png', './tests/data/clean.png') | ||
| 31 | with self.assertRaises(ValueError): | ||
| 32 | pdf.PDFParser('./tests/data/clean.png') | ||
| 33 | os.remove('./tests/data/clean.png') | ||
| 34 | |||
| 35 | def test_png(self): | ||
| 36 | shutil.copy('./tests/data/dirty.pdf', './tests/data/clean.pdf') | ||
| 37 | with self.assertRaises(ValueError): | ||
| 38 | images.PNGParser('./tests/data/clean.pdf') | ||
| 39 | os.remove('./tests/data/clean.pdf') | ||
| 40 | |||
| 41 | def test_png2(self): | ||
| 42 | shutil.copy('./tests/test_libmat2.py', './tests/clean.png') | ||
| 43 | parser, mimetype = parser_factory.get_parser('./tests/clean.png') | ||
| 44 | self.assertIsNone(parser) | ||
| 45 | os.remove('./tests/clean.png') | ||
| 46 | |||
| 47 | def test_torrent(self): | ||
| 48 | shutil.copy('./tests/data/dirty.png', './tests/data/clean.torrent') | ||
| 49 | p = torrent.TorrentParser('./tests/data/clean.torrent') | ||
| 50 | self.assertFalse(p.remove_all()) | ||
| 51 | expected = {'Unknown meta': 'Unable to parse torrent file "./tests/data/clean.torrent".'} | ||
| 52 | self.assertEqual(p.get_meta(), expected) | ||
| 53 | |||
| 54 | with open("./tests/data/clean.torrent", "a") as f: | ||
| 55 | f.write("trailing garbage") | ||
| 56 | p = torrent.TorrentParser('./tests/data/clean.torrent') | ||
| 57 | self.assertEqual(p.get_meta(), expected) | ||
| 58 | os.remove('./tests/data/clean.torrent') | ||
| 59 | |||
| 60 | def test_odg(self): | ||
| 61 | shutil.copy('./tests/data/dirty.png', './tests/data/clean.odg') | ||
| 62 | with self.assertRaises(ValueError): | ||
| 63 | office.LibreOfficeParser('./tests/data/clean.odg') | ||
| 64 | os.remove('./tests/data/clean.odg') | ||
| 65 | |||
| 66 | def test_bmp(self): | ||
| 67 | shutil.copy('./tests/data/dirty.png', './tests/data/clean.bmp') | ||
| 68 | with self.assertRaises(ValueError): | ||
| 69 | images.BMPParser('./tests/data/clean.bmp') | ||
| 70 | os.remove('./tests/data/clean.bmp') | ||
| 71 | |||
| 72 | def test_docx(self): | ||
| 73 | shutil.copy('./tests/data/dirty.png', './tests/data/clean.docx') | ||
| 74 | with self.assertRaises(ValueError): | ||
| 75 | office.MSOfficeParser('./tests/data/clean.docx') | ||
| 76 | os.remove('./tests/data/clean.docx') | ||
| 77 | |||
| 78 | def test_flac(self): | ||
| 79 | shutil.copy('./tests/data/dirty.png', './tests/data/clean.flac') | ||
| 80 | with self.assertRaises(ValueError): | ||
| 81 | audio.FLACParser('./tests/data/clean.flac') | ||
| 82 | os.remove('./tests/data/clean.flac') | ||
| 83 | |||
| 84 | def test_mp3(self): | ||
| 85 | shutil.copy('./tests/data/dirty.png', './tests/data/clean.mp3') | ||
| 86 | with self.assertRaises(ValueError): | ||
| 87 | audio.MP3Parser('./tests/data/clean.mp3') | ||
| 88 | os.remove('./tests/data/clean.mp3') | ||
