1 """Test seeking on files.
10 ARC
= "test/files/seektest.rar"
15 def do_seek(f
, pos
, lim
, size
=None):
32 f
.seek(ofs
- cur
, _WHENCE
)
35 f
.seek(ofs
- size
, _WHENCE
)
36 _WHENCE
= (_WHENCE
+ 1) % 3
44 if got
== fsize
and ln
:
45 raise ValueError("unexpected read")
46 if not ln
and got
< fsize
:
47 raise ValueError("unexpected read failure")
50 assert spos
* 4 == got
55 cnt
= int(inf
.file_size
/ 4)
58 with pytest
.raises(ValueError):
60 with pytest
.raises(ValueError):
63 do_seek(f
, int(cnt
/ 2), cnt
)
66 for i
in range(int(cnt
/ 2)):
67 do_seek(f
, i
* 2, cnt
, inf
.file_size
)
70 do_seek(f
, i
* 2 - int(cnt
/ 2), cnt
, inf
.file_size
)
72 for i
in range(cnt
+ 10):
73 do_seek(f
, cnt
- i
- 5, cnt
, inf
.file_size
)
78 def run_arc(arc
, desc
):
79 files
= ["stest1.txt", "stest2.txt"]
80 rf
= rarfile
.RarFile(arc
)
85 def test_seek_filename():
89 def test_seek_bytesio():
90 # filelike: io.BytesIO, io.open()
91 with
open(ARC
, "rb") as f
:
93 run_arc(io
.BytesIO(data
), "io.BytesIO")
98 with
open(ARC
, "rb") as f
:
102 def test_seek_ioopen():
103 # filelike: io.open()
104 with io
.open(ARC
, "rb") as f
:
105 run_arc(f
, "io.open")