15
15
16
16
17
17
VALUES = [
18
- (0 , 'i0e' ),
19
- (1 , 'i1e' ),
20
- (10 , 'i10e' ),
21
- (42 , 'i42e' ),
22
- (- 42 , 'i-42e' ),
23
- (True , 'i1e' ),
24
- (False , 'i0e' ),
25
- ('spam' , '4:spam' ),
26
- ('parrot sketch' , '13:parrot sketch' ),
27
- (['parrot sketch' , 42 ], 'l13:parrot sketchi42ee' ),
28
- ({'foo' : 42 , 'bar' : 'spam' }, 'd3:bar4:spam3:fooi42ee' )
18
+ (0 , b 'i0e' ),
19
+ (1 , b 'i1e' ),
20
+ (10 , b 'i10e' ),
21
+ (42 , b 'i42e' ),
22
+ (- 42 , b 'i-42e' ),
23
+ (True , b 'i1e' ),
24
+ (False , b 'i0e' ),
25
+ (b 'spam' , b '4:spam' ),
26
+ (b 'parrot sketch' , b '13:parrot sketch' ),
27
+ ([b 'parrot sketch' , 42 ], b 'l13:parrot sketchi42ee' ),
28
+ ({b 'foo' : 42 , b 'bar' : b 'spam' }, b 'd3:bar4:spam3:fooi42ee' )
29
29
]
30
30
31
31
if OrderedDict is not None :
32
32
VALUES .append ((OrderedDict ((
33
- ('bar' , 'spam' ),
34
- ('foo' , 42 )
35
- )), 'd3:bar4:spam3:fooi42ee' ))
33
+ (b 'bar' , b 'spam' ),
34
+ (b 'foo' , 42 )
35
+ )), b 'd3:bar4:spam3:fooi42ee' ))
36
36
37
37
38
- @pytest .mark .skipif (sys .version_info [0 ] < 3 , reason = "Requires: Python 3+" )
39
38
def test_encode ():
40
- """Encode should give known result with known input."""
41
- for plain , encoded in VALUES :
42
- assert encoded .encode ('utf-8' ) == bencode (plain )
43
-
44
-
45
- @pytest .mark .skipif (sys .version_info [0 ] != 2 , reason = "Requires: Python 2" )
46
- def test_encode_py2 ():
47
39
"""Encode should give known result with known input."""
48
40
for plain , encoded in VALUES :
49
41
assert encoded == bencode (plain )
50
42
51
43
52
- @pytest .mark .skipif (sys .version_info [0 ] < 3 , reason = "Requires: Python 3+" )
53
44
def test_encode_bencached ():
54
45
"""Ensure Bencached objects can be encoded."""
55
46
assert bencode ([Bencached (bencode ('test' ))]) == b'l4:teste'
56
47
57
48
58
- @pytest .mark .skipif (sys .version_info [0 ] != 2 , reason = "Requires: Python 2" )
59
- def test_encode_bencached_py2 ():
60
- """Ensure Bencached objects can be encoded."""
61
- assert bencode ([Bencached (bencode ('test' ))]) == 'l4:teste'
62
-
63
-
64
49
def test_encode_bytes ():
65
50
"""Ensure bytes can be encoded."""
66
51
assert bencode (b'\x9c ' ) == b'1:\x9c '
67
52
68
53
69
- @pytest .mark .skipif (sys .version_info [0 ] < 3 , reason = "Requires: Python 3+" )
70
54
def test_decode ():
71
- """Decode should give known result with known input."""
72
- for plain , encoded in VALUES :
73
- assert plain == bdecode (encoded .encode ('utf-8' ))
74
-
75
-
76
- @pytest .mark .skipif (sys .version_info [0 ] != 2 , reason = "Requires: Python 2" )
77
- def test_decode_py2 ():
78
55
"""Decode should give known result with known input."""
79
56
for plain , encoded in VALUES :
80
57
assert plain == bdecode (encoded )
@@ -85,15 +62,7 @@ def test_decode_bytes():
85
62
assert bdecode (b'1:\x9c ' ) == b'\x9c '
86
63
87
64
88
- @pytest .mark .skipif (sys .version_info [0 ] < 3 , reason = "Requires: Python 3+" )
89
65
def test_encode_roundtrip ():
90
- """Consecutive calls to decode and encode should deliver the original data again."""
91
- for plain , encoded in VALUES :
92
- assert encoded .encode ('utf-8' ) == bencode (bdecode (encoded .encode ('utf-8' )))
93
-
94
-
95
- @pytest .mark .skipif (sys .version_info [0 ] != 2 , reason = "Requires: Python 2" )
96
- def test_encode_roundtrip_py2 ():
97
66
"""Consecutive calls to decode and encode should deliver the original data again."""
98
67
for plain , encoded in VALUES :
99
68
assert encoded == bencode (bdecode (encoded ))
@@ -142,33 +111,15 @@ def test_dictionary_sorted():
142
111
assert encoded .index (b'zoo' ) > encoded .index (b'bar' )
143
112
144
113
145
- @pytest .mark .skipif (sys .version_info [0 ] < 3 , reason = "Requires: Python 3+" )
146
114
def test_dictionary_unicode ():
147
115
"""Test the handling of unicode in dictionaries."""
148
116
encoded = bencode ({u'foo' : 42 , 'bar' : {u'sketch' : u'parrot' , 'foobar' : 23 }})
149
117
150
118
assert encoded == 'd3:bard6:foobari23e6:sketch6:parrote3:fooi42ee' .encode ('utf-8' )
151
119
152
120
153
- @pytest .mark .skipif (sys .version_info [0 ] != 2 , reason = "Requires: Python 2" )
154
- def test_dictionary_unicode_py2 ():
155
- """Test the handling of unicode in dictionaries."""
156
- encoded = bencode ({u'foo' : 42 , 'bar' : {u'sketch' : u'parrot' , 'foobar' : 23 }})
157
-
158
- assert encoded == 'd3:bard6:foobari23e6:sketch6:parrote3:fooi42ee'
159
-
160
-
161
- @pytest .mark .skipif (sys .version_info [0 ] < 3 , reason = "Requires: Python 3+" )
162
121
def test_dictionary_nested ():
163
122
"""Test the handling of nested dictionaries."""
164
123
encoded = bencode ({'foo' : 42 , 'bar' : {'sketch' : 'parrot' , 'foobar' : 23 }})
165
124
166
125
assert encoded == 'd3:bard6:foobari23e6:sketch6:parrote3:fooi42ee' .encode ('utf-8' )
167
-
168
-
169
- @pytest .mark .skipif (sys .version_info [0 ] != 2 , reason = "Requires: Python 2" )
170
- def test_dictionary_nested_py2 ():
171
- """Test the handling of nested dictionaries."""
172
- encoded = bencode ({'foo' : 42 , 'bar' : {'sketch' : 'parrot' , 'foobar' : 23 }})
173
-
174
- assert encoded == 'd3:bard6:foobari23e6:sketch6:parrote3:fooi42ee'
0 commit comments