From 87bdcd1a9501e398bccb03fce606cf6925a75d16 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sun, 10 Jun 2018 00:56:55 +0200 Subject: Improve a bit our coverage wrt. torrent files handling --- tests/test_libmat2.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests') diff --git a/tests/test_libmat2.py b/tests/test_libmat2.py index 3d08dea..7deeadc 100644 --- a/tests/test_libmat2.py +++ b/tests/test_libmat2.py @@ -57,6 +57,20 @@ class TestCorruptedFiles(unittest.TestCase): images.PNGParser('./tests/data/clean.pdf') os.remove('./tests/data/clean.pdf') + def test_torrent(self): + shutil.copy('./tests/data/dirty.png', './tests/data/clean.torrent') + p = torrent.TorrentParser('./tests/data/clean.torrent') + self.assertFalse(p.remove_all()) + expected = {'Unknown meta': 'Unable to parse torrent file "./tests/data/clean.torrent".'} + self.assertEqual(p.get_meta(), expected) + + with open("./tests/data/clean.torrent", "a") as f: + f.write("trailing garbage") + p = torrent.TorrentParser('./tests/data/clean.torrent') + self.assertEqual(p.get_meta(), expected) + + os.remove('./tests/data/clean.torrent') + class TestGetMeta(unittest.TestCase): def test_pdf(self): p = pdf.PDFParser('./tests/data/dirty.pdf') -- cgit v1.3