From 57bf89e035609c39506372cc9deed92dfbd42716 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sun, 22 Apr 2018 22:02:00 +0200 Subject: Add support for torrent files cleaning --- tests/data/dirty.torrent | Bin 0 -> 93903 bytes tests/test_libmat2.py | 23 ++++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/data/dirty.torrent (limited to 'tests') diff --git a/tests/data/dirty.torrent b/tests/data/dirty.torrent new file mode 100644 index 0000000..472371b Binary files /dev/null and b/tests/data/dirty.torrent differ diff --git a/tests/test_libmat2.py b/tests/test_libmat2.py index ae04dc2..ff5c196 100644 --- a/tests/test_libmat2.py +++ b/tests/test_libmat2.py @@ -6,7 +6,7 @@ import os import zipfile import tempfile -from src import pdf, images, audio, office, parser_factory +from src import pdf, images, audio, office, parser_factory, torrent class TestParserFactory(unittest.TestCase): @@ -28,6 +28,11 @@ class TestGetMeta(unittest.TestCase): "3.1415926-2.5-1.40.14 (TeX Live 2013/Debian) kpathsea " \ "version 6.1.1") + def test_torrent(self): + p = torrent.TorrentParser('./tests/data/dirty.torrent') + meta = p.get_meta() + self.assertEqual(meta['created by'], b'mktorrent 1.0') + def test_png(self): p = images.PNGParser('./tests/data/dirty.png') meta = p.get_meta() @@ -322,3 +327,19 @@ class TestCleaning(unittest.TestCase): self.assertEqual(p.get_meta(), {}) os.remove('./tests/data/clean.bmp') + + + def test_torrent(self): + shutil.copy('./tests/data/dirty.torrent', './tests/data/clean.torrent') + p = torrent.TorrentParser('./tests/data/clean.torrent') + + meta = p.get_meta() + self.assertEqual(meta, {'created by': b'mktorrent 1.0', 'creation date': 1522397702}) + + ret = p.remove_all() + self.assertTrue(ret) + + p = torrent.TorrentParser('./tests/data/clean.torrent.cleaned') + self.assertEqual(p.get_meta(), {}) + + os.remove('./tests/data/clean.torrent') -- cgit v1.3