1 """Read all test files.
10 from nose
.tools
import *
14 def run_reading_normal(fn
, comment
):
16 rf
= rarfile
.RarFile(fn
)
17 except rarfile
.NeedFirstVolume
:
19 if rf
.needs_password():
20 rf
.setpassword('password')
21 eq_(rf
.strerror(), None)
22 eq_(rf
.comment
, comment
)
23 for ifn
in rf
.namelist():
29 item
= rf
.getinfo(ifn
)
38 eq_(total
, item
.file_size
)
40 # read from stream with readinto
41 bbuf
= bytearray(1024)
42 with rf
.open(ifn
) as f
:
43 res
= f
.readinto(memoryview(bbuf
))
47 def run_reading_inmem(fn
, comment
):
49 rf
= rarfile
.RarFile(fn
)
50 except rarfile
.NeedFirstVolume
:
52 if len(rf
.volumelist()) > 1:
55 buf
= io
.open(fn
, 'rb').read()
56 run_reading_normal(io
.BytesIO(buf
), comment
)
58 def run_reading(fn
, comment
=None):
60 run_reading_normal(fn
, comment
)
61 run_reading_inmem(fn
, comment
)
63 def test_reading_rar3_ctime():
64 run_reading('test/files/ctime0.rar')
65 run_reading('test/files/ctime1.rar')
66 run_reading('test/files/ctime2.rar')
67 run_reading('test/files/ctime3.rar')
68 run_reading('test/files/ctime4.rar')
70 def test_reading_rar2():
71 run_reading('test/files/rar15-comment-lock.rar', u
'RARcomment -----')
72 run_reading('test/files/rar15-comment.rar', u
'RARcomment -----')
73 run_reading('test/files/rar202-comment-nopsw.rar', u
'RARcomment')
75 def test_reading_rar3():
76 run_reading('test/files/rar3-comment-plain.rar', u
'RARcomment\n')
77 run_reading('test/files/seektest.rar')
78 run_reading('test/files/unicode.rar')
79 run_reading('test/files/unicode2.rar')
81 def test_reading_rar2_psw():
82 run_reading('test/files/rar202-comment-psw.rar', u
'RARcomment')
84 def test_reading_rar3_psw():
85 run_reading('test/files/rar3-comment-psw.rar', u
'RARcomment\n')
87 if rarfile
._have
_crypto
:
88 def test_reading_rar3_hpsw():
89 run_reading('test/files/rar3-comment-hpsw.rar', u
'RARcomment\n')
91 @raises(rarfile
.NoCrypto
)
92 def test_reading_rar3_hpsw_nocrypto():
93 run_reading('test/files/rar3-comment-hpsw.rar', u
'RARcomment\n')
95 def test_reading_rar3_vols():
96 run_reading('test/files/rar3-old.rar')
97 run_reading('test/files/rar3-vols.part1.rar')
98 run_reading('test/files/rar3-vols.part2.rar')
99 run_reading('test/files/rar3-vols.part3.rar')
101 def test_reading_rar5_blake():
102 run_reading('test/files/rar5-blake.rar', u
'RAR5 archive - blake\n')
104 def test_reading_rar5_crc():
105 run_reading('test/files/rar5-crc.rar', u
'RAR5 archive - crc\n')
107 def test_reading_rar5_links():
108 run_reading('test/files/rar5-dups.rar')
109 run_reading('test/files/rar5-hlink.rar')
111 def test_reading_rar5_quick_open():
112 run_reading('test/files/rar5-quick-open.rar')
114 def test_reading_rar5_solid_qo():
115 run_reading('test/files/rar5-solid-qo.rar')
117 def test_reading_rar5_solid():
118 run_reading('test/files/rar5-solid.rar')
120 def test_reading_rar5_times():
121 run_reading('test/files/rar5-times.rar')
122 run_reading('test/files/rar5-times2.rar')
124 def test_reading_rar5_vols():
125 run_reading('test/files/rar5-vols.part1.rar')
126 run_reading('test/files/rar5-vols.part2.rar')
127 run_reading('test/files/rar5-vols.part3.rar')
129 if rarfile
._have
_crypto
:
130 def test_reading_rar5_hpsw():
131 run_reading('test/files/rar5-hpsw.rar', u
'RAR5 archive - hdr-password\n')
133 @raises(rarfile
.NoCrypto
)
134 def test_reading_rar5_hpsw():
135 run_reading('test/files/rar5-hpsw.rar', u
'RAR5 archive - hdr-password\n')
137 def test_reading_rar5_psw_blake():
138 run_reading('test/files/rar5-psw-blake.rar', u
'RAR5 archive - nohdr-password-blake\n')
140 def test_reading_rar5_psw():
141 run_reading('test/files/rar5-psw.rar', u
'RAR5 archive - nohdr-password\n')
143 def test_reading_missed():
146 for fn
in glob('test/files/*.rar'):
147 fn
= fn
.replace('\\', '/')
148 if fn
not in _done_reading
:
150 eq_(missed
, problems
)