1 """Test seeking on files.
7 from nose
.tools
import *
9 ARC
= 'test/files/seektest.rar'
11 def do_seek(f
, pos
, lim
):
28 if got
== fsize
and ln
:
29 raise Exception('unexpected read')
30 if not ln
and got
< fsize
:
31 raise Exception('unexpected read failure')
38 cnt
= int(inf
.file_size
/ 4)
41 do_seek(f
, int(cnt
/2), cnt
)
44 for i
in range(int(cnt
/2)):
48 do_seek(f
, i
*2 - int(cnt
/ 2), cnt
)
50 for i
in range(cnt
+ 10):
51 do_seek(f
, cnt
- i
- 5, cnt
)
55 def run_arc(arc
, desc
):
56 files
= ['stest1.txt', 'stest2.txt']
57 rf
= rarfile
.RarFile(arc
)
61 def test_seek_filename():
64 def test_seek_stringio():
65 data
= open(ARC
, 'rb').read()
70 run_arc(cStringIO
.StringIO(data
), "cStringIO")
77 run_arc(StringIO
.StringIO(data
), "StringIO")
81 def test_seek_bytesio():
82 # filelike: io.BytesIO, io.open()
83 data
= open(ARC
, 'rb').read()
84 run_arc(io
.BytesIO(data
), "io.BytesIO")
88 run_arc(open(ARC
, 'rb'), "open")
90 def test_seek_ioopen():
92 run_arc(io
.open(ARC
, 'rb'), "io.open")