File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 1+ # -*- coding: utf-8 -*-
2+
3+ from bencoder import bdecode
4+
5+
6+ def test_decode_str ():
7+ assert bdecode (b'6:WWWWWW' ) == "WWWWWW"
8+
9+
10+ def test_decode_int ():
11+ assert bdecode (b'i233e' ) == 233
12+
13+
14+ def test_decode_list ():
15+ assert bdecode (b'l1:a1:bi3ee' ) == ['a' , 'b' , 3 ]
16+
17+
18+ def test_decode_dict ():
19+ od = dict ()
20+ od ['ka' ] = 'va'
21+ od ['kb' ] = 2
22+ assert bdecode (b'd2:ka2:va2:kbi2ee' ) == od
23+
24+
25+ def test_encode_complex ():
26+ od = dict ()
27+ od ['KeyA' ] = ['listitemA' , {'k' : 'v' }, 3 ]
28+ od ['KeyB' ] = {'k' : 'v' }
29+ od ['KeyC' ] = 3
30+ od ['KeyD' ] = 'AString'
31+ expected_result = b'd4:KeyAl9:listitemAd1:k1:vei3ee4:KeyBd1:k1:ve4:KeyCi3e4:KeyD7:AStringe'
32+ assert bdecode (expected_result ) == od
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ def test_encode_int():
1414def test_encode_bytes ():
1515 b = b"TheseAreSomeBytes"
1616 coded = bencode (b )
17- l = bytes ( str (len (b )))
17+ l = str (len (b )). encode ( )
1818 assert coded == l + b':' + b
1919
2020
You can’t perform that action at this time.
0 commit comments