3 import rarfile
, os
, os
.path
, time
, sys
6 fdir
= "/proc/%d/fd" % os
.getpid()
7 if os
.path
.isdir(fdir
):
8 os
.system('printf "fds = "; ls -l %s | wc -l' % fdir
)
10 def do_seek(f
, pos
, lim
):
26 raise Exception('seek failed (got=%d, exp=%d)' % (got
, exp
))
28 if got
== fsize
and ln
:
29 raise Exception('unexpected read')
30 if not ln
and got
< fsize
:
31 raise Exception('unexpected read failure')
35 raise Exception('unexpected pos: spos=%d pos=%d' % (spos
, pos
))
37 def test_seek(rf
, fn
):
39 cnt
= int(inf
.file_size
/ 4)
42 do_seek(f
, int(cnt
/2), cnt
)
45 for i
in range(int(cnt
/2)):
49 do_seek(f
, i
*2 - int(cnt
/ 2), cnt
)
51 for i
in range(cnt
+ 10):
52 do_seek(f
, cnt
- i
- 5, cnt
)
58 def test_arc(arc
, desc
):
59 files
= ['stest1.txt', 'stest2.txt']
60 rf
= rarfile
.RarFile(arc
, crc_check
=0)
62 sys
.stdout
.write('%s | test/seek %s .. ' % (desc
, fn
))
67 arc
= 'files/seektest.rar'
68 data
= open(arc
, 'rb').read()
76 test_arc(cStringIO
.StringIO(data
), "cStringIO")
80 # filelike: io.BytesIO, io.open()
83 test_arc(io
.BytesIO(data
), "io.BytesIO")
84 test_arc(io
.open(arc
, 'rb'), "io.open")
91 test_arc(StringIO
.StringIO(data
), "StringIO")
96 test_arc(open(arc
, 'rb'), "file")
101 if __name__
== '__main__':