11# -*- coding: utf-8 -*-
22
33from bencoder import bdecode
4+ import os
5+
6+ TORRENT_PATH = os .path .join (
7+ os .path .abspath (os .path .dirname (__file__ )),
8+ "debian-8.3.0-amd64-netinst.iso.torrent"
9+ )
410
511
612def test_decode_str ():
@@ -22,6 +28,15 @@ def test_decode_dict():
2228 assert bdecode (b'd2:ka2:va2:kbi2ee' ) == od
2329
2430
31+ def test_ordered_dict ():
32+ from bencoder import OrderedDict
33+ rv = bdecode (b'd2:ka2:va2:kbi2ee' )
34+ assert isinstance (rv , OrderedDict )
35+ assert list (rv .keys ()) == [b'ka' , b'kb' ]
36+ assert list (bdecode (b'd2:kc2:va2:kei2ee' ).keys ()) == [b'kc' , b'ke' ]
37+ assert list (bdecode (b'd2:ke2:va2:kci2ee' ).keys ()) == [b'ke' , b'kc' ]
38+
39+
2540def test_encode_complex ():
2641 od = dict ()
2742 od [b'KeyA' ] = [b'listitemA' , {b'k' : b'v' }, 3 ]
@@ -33,12 +48,7 @@ def test_encode_complex():
3348
3449
3550def test_decode_debian_torrent ():
36- import os
37- torrent_path = os .path .join (
38- os .path .abspath (os .path .dirname (__file__ )),
39- "debian-8.3.0-amd64-netinst.iso.torrent"
40- )
41- with open (torrent_path , "rb" ) as f :
51+ with open (TORRENT_PATH , "rb" ) as f :
4252 torrent = bdecode (f .read ())
4353 assert torrent [b'announce' ] == b'http://bttracker.debian.org:6969/announce'
4454 assert torrent [b'comment' ] == b'"Debian CD from cdimage.debian.org"'
0 commit comments