File tree Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -10,5 +10,4 @@ python:
1010
1111before_install : pip install Cython
1212install : python setup.py install
13- script : coverage run --source=bencoder setup.py -q nosetests
14- after_success : coveralls
13+ script : nosetests
Original file line number Diff line number Diff line change 1+ # -*- coding: utf-8 -*-
2+
3+ from bencoder import bencode
4+
5+
6+ def test_encode_str ():
7+ assert bencode ("WWWWWW" ) == b'6:WWWWWW'
8+
9+
10+ def test_encode_int ():
11+ assert bencode (233 ) == b'i233e'
12+
13+
14+ def test_encode_bytes ():
15+ b = b"TheseAreSomeBytes"
16+ coded = bencode (b )
17+ l = bytes (str (len (b )))
18+ assert coded == l + b':' + b
19+
20+
21+ def test_encode_list ():
22+ assert bencode (['a' , 'b' , 3 ]) == b'l1:a1:bi3ee'
23+
24+
25+ def test_encode_tuple ():
26+ assert bencode (('a' , 'b' , 3 )) == b'l1:a1:bi3ee'
27+
28+
29+ def test_encode_dict ():
30+ od = dict ()
31+ od ['ka' ] = 'va'
32+ od ['kb' ] = 2
33+ assert bencode (od ) == b'd2:ka2:va2:kbi2ee'
34+
35+
36+ def test_encode_complex ():
37+ od = dict ()
38+ od ['KeyA' ] = ['listitemA' , {'k' : 'v' }, 3 ]
39+ od ['KeyB' ] = {'k' : 'v' }
40+ od ['KeyC' ] = 3
41+ od ['KeyD' ] = 'AString'
42+ expected_result = b'd4:KeyAl9:listitemAd1:k1:vei3ee4:KeyBd1:k1:ve4:KeyCi3e4:KeyD7:AStringe'
43+ assert bencode (od ) == expected_result
You can’t perform that action at this time.
0 commit comments