def test_dump_multi(self): tname = 'multi_bytes.torrent' tp = self.torrent_path(tname) ns = self.arg_namespace('-n -e %s' % tp) return_string = '\n'.join([tname, ' announce', ' fake.com/announce', ' created by', ' mktorrent 1.0', ' creation date', ' 1363528361', ' info', ' files', ' 0', ' length', ' 1048576', ' path', ' megabyte', ' 1', ' length', ' 2097152', ' path', ' two_megabytes', ' name', ' multibyte', ' piece length', ' 262144', ' pieces', ' [240 UTF-8 Bytes]\n\n']) torrentinfo.main(alt_args=ns, out=self.out, err=self.err) assert self.err.getvalue() == '' self.assertEqual(self.out.getvalue(), return_string)
def test_list_files_multi(self): tname = 'multi_bytes.torrent' tp = self.torrent_path(tname) ns = self.arg_namespace('-n -d %s' % tp) return_string = '\n'.join([tname, ' files ', ' 0', ' path ', ' megabyte', ' length ', ' 1048576', ' 1', ' path ', ' two_megabytes', ' length ', ' 2097152', ' piece length ', ' 262144', ' pieces ', ' [240 UTF-8 Bytes]\n\n']) torrentinfo.main(alt_args=ns, out=self.out, err=self.err) assert self.err.getvalue() == '' self.assertEqual(self.out.getvalue(), return_string)
def test_dump_single(self): tname = 'regular.torrent' tp = self.torrent_path(tname) ns = self.arg_namespace('-n -e %s' % tp) return_string = '\n'.join([tname, ' announce', ' fake.com/announce', ' created by', ' mktorrent 1.0', ' creation date', ' 1363530756', ' info', ' length', ' 22602', ' name', ' torrentinfo.py', ' piece length', ' 262144', ' pieces', ' [20 UTF-8 Bytes]\n\n']) torrentinfo.main(alt_args=ns, out=self.out, err=self.err) assert self.err.getvalue() == '' self.assertEqual(self.out.getvalue(), return_string)
def test_top_multi(self): tname = 'multi_bytes.torrent' tp = self.torrent_path(tname) ns = self.arg_namespace('-n -t %s' % tp) return_string = '\n'.join([tname, 'multibyte\n']) torrentinfo.main(alt_args=ns, out=self.out, err=self.err) assert self.err.getvalue() == '' self.assertEqual(self.out.getvalue(), return_string)
def test_empty(self): tname = 'empty.torrent' tp = self.torrent_path(tname) return_string = 'Could not parse %s ' % tp return_string += 'as a valid torrent file.\n' ns = self.arg_namespace(tp) try: torrentinfo.main(alt_args=ns, out=self.out, err=self.err) except SystemExit as se: assert se.code == 1 assert self.out.getvalue() == '' self.assertEqual(self.err.getvalue(), return_string)
def test_list_files_single(self): tname = 'regular.torrent' tp = self.torrent_path(tname) ns = self.arg_namespace('-n -d %s' % tp) return_string = '\n'.join([tname, ' files ', ' 0', ' torrentinfo.py', ' 22.1KB', ' piece length ', ' 262144', ' pieces ', ' [20 UTF-8 Bytes]\n\n']) torrentinfo.main(alt_args=ns, out=self.out, err=self.err) assert self.err.getvalue() == '' self.assertEqual(self.out.getvalue(), return_string)
def test_basic_multi(self): tname = 'multi_bytes.torrent' tp = self.torrent_path(tname) ns = self.arg_namespace('-n %s' % tp) return_string = '\n'.join([tname, ' name multibyte', ' comment ', ' tracker url fake.com/announce', ' created by mktorrent 1.0', r' created on \d{4}/\d\d/\d\d \d\d:\d\d:\d\d \w+?', ' num files 2', ' total size 3.0MB\n\n']) pattern = re.compile(return_string) torrentinfo.main(alt_args=ns, out=self.out, err=self.err) assert self.err.getvalue() == '' self.assertTrue(re.match(pattern, self.out.getvalue()) != None)
def test_basic_comment_single(self): tname = 'comment.torrent' tp = self.torrent_path(tname) ns = self.arg_namespace('-n %s' % tp) return_string = '\n'.join([tname, ' name nothinghere', ' comment Some comment', ' tracker url fake.com', ' created by mktorrent 1.0', r' created on \d{4}/\d\d/\d\d \d\d:\d\d:\d\d \w+?', ' file name nothinghere', ' file size 0.0B']) pattern = re.compile(return_string) torrentinfo.main(alt_args=ns, out=self.out, err=self.err) assert self.err.getvalue() == '' self.assertTrue(re.match(pattern, self.out.getvalue()) != None)
def test_basic_files_single_unicode(self): tname = 'unicode.torrent' tp = self.torrent_path(tname) ns = self.arg_namespace('-n -f %s' % tp) return_string = '\n'.join([tname, ' name 灼眼のシャナ', ' comment Hello Unicode!', ' tracker url fake.com', ' created by mktorrent 1.0', r' created on \d{4}/\d\d/\d\d \d\d:\d\d:\d\d \w+?', ' files ', ' 0', ' 灼眼のシャナ', ' 0.0B']) pattern = re.compile(return_string) torrentinfo.main(alt_args=ns, out=self.out, err=self.err) assert self.err.getvalue() == '' self.assertTrue(re.match(pattern, self.out.getvalue()) != None)
def test_basic_files_single(self): tname = 'regular.torrent' tp = self.torrent_path(tname) ns = self.arg_namespace('-n -f %s' % tp) return_string = '\n'.join([tname, ' name torrentinfo.py', ' comment ', ' tracker url fake.com/announce', ' created by mktorrent 1.0', r' created on \d{4}/\d\d/\d\d \d\d:\d\d:\d\d \w+?', ' files ', ' 0', ' torrentinfo.py', ' 22.1KB\n\n']) pattern = re.compile(return_string) torrentinfo.main(alt_args=ns, out=self.out, err=self.err) assert self.err.getvalue() == '' self.assertTrue(re.match(pattern, self.out.getvalue()) != None)