Added: TorrentFileCreator and create_torrent_file
This commit is contained in:
8 files changed
+217
-22
No files matched your search
+2
-1
@@ -1 +1,2 @@
|
||||
from .test_all import *
|
||||
from .test_create import *
|
||||
from .test_parse import *
|
||||
@@ -0,0 +1,31 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import collections
|
||||
import hashlib
|
||||
import io
|
||||
import os.path
|
||||
import unittest
|
||||
|
||||
from torrent_parser import TorrentFileParser, TorrentFileCreator
|
||||
|
||||
|
||||
class TestCreate(unittest.TestCase):
|
||||
TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), 'test_files')
|
||||
REAL_FILE = os.path.join(TEST_FILES_DIR, 'real.torrent')
|
||||
|
||||
def test_simple_create(self):
|
||||
data = collections.OrderedDict()
|
||||
data['a'] = 1
|
||||
data['b'] = 2
|
||||
self.assertEqual(TorrentFileCreator(data).encode(), b'd1:ai1e1:bi2ee')
|
||||
|
||||
def test_same_output_if_no_edit(self):
|
||||
with open(self.REAL_FILE, 'rb') as fp:
|
||||
in_data = fp.read()
|
||||
data = TorrentFileParser(io.BytesIO(in_data), True).parse()
|
||||
out_data = TorrentFileCreator(data).encode()
|
||||
m1 = hashlib.md5()
|
||||
m1.update(in_data)
|
||||
m2 = hashlib.md5()
|
||||
m2.update(out_data)
|
||||
self.assertEqual(m1.digest(), m2.digest())
|
||||
File renamed without changes.
File renamed without changes.
@@ -1,14 +1,16 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import unittest
|
||||
import collections
|
||||
import os.path
|
||||
import unittest
|
||||
|
||||
from torrent_parser import TorrentFileParser, parse_torrent_file
|
||||
|
||||
|
||||
class Test(unittest.TestCase):
|
||||
REAL_FILE = 'tests/testfiles/real.torrent'
|
||||
NEG_FILE = 'tests/testfiles/neg.torrent'
|
||||
class TestParse(unittest.TestCase):
|
||||
TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), 'test_files')
|
||||
REAL_FILE = os.path.join(TEST_FILES_DIR, 'real.torrent')
|
||||
NEG_FILE = os.path.join(TEST_FILES_DIR, 'neg.torrent')
|
||||
|
||||
def test_parse_torrent_file_use_shortcut(self):
|
||||
parse_torrent_file(self.REAL_FILE)
|
||||
@@ -53,4 +55,4 @@ class Test(unittest.TestCase):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user