31
31
str = type ('' )
32
32
33
33
34
+ import sys
34
35
import io
35
36
import mmap
36
37
import compoundfiles .mmap as fake_mmap
@@ -69,11 +70,23 @@ def test_read_only(test_map):
69
70
def test_len (test_map ):
70
71
assert len (test_map )== 26
71
72
72
- def test_indexing (test_map ):
73
+ @pytest .mark .skipif (sys .version_info [0 ]== 3 ,
74
+ reason = "py2 mmap is an array of chars" )
75
+ def test_indexing_v2 (test_map ):
73
76
assert test_map [0 ]== b'a'
74
77
assert test_map [4 ]== b'e'
75
78
assert test_map [- 1 ]== b'z'
76
79
assert test_map [- 3 ]== b'x'
80
+
81
+ @pytest .mark .skipif (sys .version_info [0 ]== 2 ,
82
+ reason = "py3 mmap is an array of ints" )
83
+ def test_indexing_v3 (test_map ):
84
+ assert test_map [0 ]== ord (b'a' )
85
+ assert test_map [4 ]== ord (b'e' )
86
+ assert test_map [- 1 ]== ord (b'z' )
87
+ assert test_map [- 3 ]== ord (b'x' )
88
+
89
+ def test_indexing (test_map ):
77
90
with pytest .raises (IndexError ):
78
91
test_map [30 ]
79
92
with pytest .raises (IndexError ):
@@ -94,7 +107,7 @@ def test_slicing(test_map):
94
107
assert test_map [- 5 :- 1 :2 ]== b'vx'
95
108
96
109
def test_negative_slicing (test_map ):
97
- assert test_map [::- 1 ]== b'' . join ( reversed ( test_map [:]))
110
+ assert test_map [::- 1 ]== b'zyxwvutsrqponmlkjihgfedcba'
98
111
assert test_map [::- 2 ]== b'zxvtrpnljhfdb'
99
112
assert test_map [- 2 ::- 2 ]== b'ywusqomkigeca'
100
113
assert test_map [5 :10 :- 1 ]== b''
@@ -127,6 +140,22 @@ def test_rfind(test_map):
127
140
assert test_map .rfind (b'xyz' ,0 ,- 1 )== - 1
128
141
assert test_map .rfind (b'foobar' )== - 1
129
142
143
+ @pytest .mark .skipif (sys .version_info [0 ]== 3 ,
144
+ reason = "py2 read_byte returns bytes" )
145
+ def test_seek_n_read_v2 (test_map ):
146
+ test_map .seek (- 3 ,io .SEEK_END )
147
+ assert test_map .read_byte ()== b'x'
148
+ assert test_map .read_byte ()== b'y'
149
+ assert test_map .read_byte ()== b'z'
150
+
151
+ @pytest .mark .skipif (sys .version_info [0 ]== 2 ,
152
+ reason = "py3 read_byte returns an int" )
153
+ def test_seek_n_read_v3 (test_map ):
154
+ test_map .seek (- 3 ,io .SEEK_END )
155
+ assert test_map .read_byte ()== ord (b'x' )
156
+ assert test_map .read_byte ()== ord (b'y' )
157
+ assert test_map .read_byte ()== ord (b'z' )
158
+
130
159
def test_seek_n_read (test_map ):
131
160
test_map .seek (0 )
132
161
assert test_map .read (26 )== b'abcdefghijklmnopqrstuvwxyz'
@@ -136,10 +165,6 @@ def test_seek_n_read(test_map):
136
165
test_map .seek (- 3 ,io .SEEK_END )
137
166
assert test_map .read (- 1 )== b'xyz'
138
167
assert test_map .read (- 1 )== b''
139
- test_map .seek (- 3 ,io .SEEK_CUR )
140
- assert test_map .read_byte ()== b'x'
141
- assert test_map .read_byte ()== b'y'
142
- assert test_map .read_byte ()== b'z'
143
168
test_map .seek (0 ,io .SEEK_SET )
144
169
assert test_map .readline ()== b'abcdefghijklmnopqrstuvwxyz'
145
170