1 """Read all test files.
12 "rar15-comment-lock.rar": "RARcomment -----",
13 "rar15-comment.rar": "RARcomment -----",
14 "rar202-comment-nopsw.rar": "RARcomment",
15 "rar202-comment-psw.rar": "RARcomment",
16 "rar3-comment-hpsw.rar": "RARcomment\n",
17 "rar3-comment-plain.rar": "RARcomment\n",
18 "rar3-comment-psw.rar": "RARcomment\n",
19 "rar5-blake.rar": "RAR5 archive - blake\n",
20 "rar5-crc.rar": "RAR5 archive - crc\n",
21 "rar5-crc.sfx": "RAR5 archive - crc\n",
22 "rar5-hpsw.rar": "RAR5 archive - hdr-password\n",
23 "rar5-psw-blake.rar": "RAR5 archive - nohdr-password-blake\n",
24 "rar5-psw.rar": "RAR5 archive - nohdr-password\n",
29 for f
in sorted(glob("test/files/*.rar"))
34 def run_reading_normal(fn
, comment
):
36 rf
= rarfile
.RarFile(fn
)
37 except rarfile
.NeedFirstVolume
:
39 if rf
.needs_password():
40 rf
.setpassword("password")
41 assert rf
.strerror() is None
42 assert rf
.comment
== comment
43 for ifn
in rf
.namelist():
47 info
= rf
.getinfo(ifn
)
57 item
= rf
.getinfo(ifn
)
66 assert total
== item
.file_size
, ifn
68 # read from stream with readinto
69 bbuf
= bytearray(1024)
70 with rf
.open(ifn
) as f
:
71 res
= f
.readinto(memoryview(bbuf
))
76 def run_reading_inmem(fn
, comment
):
78 rf
= rarfile
.RarFile(fn
)
79 except rarfile
.NeedFirstVolume
:
81 if len(rf
.volumelist()) > 1:
84 with io
.open(fn
, "rb") as f
:
86 run_reading_normal(io
.BytesIO(buf
), comment
)
90 basename
= fn
.split("/")[-1]
91 comment
= ARCHIVE_COMMENTS
.get(basename
)
92 run_reading_normal(fn
, comment
)
93 run_reading_inmem(fn
, comment
)
96 @pytest.mark
.parametrize("fn", ARCHIVE_FILES
)
101 @pytest.mark
.skipif(not rarfile
._have
_crypto
, reason
="No crypto")
102 def test_reading_rar3_hpsw():
103 run_reading("test/files/rar3-comment-hpsw.rar")
106 @pytest.mark
.skipif(rarfile
._have
_crypto
, reason
="Has crypto")
107 def test_reading_rar3_hpsw_nocrypto():
108 with pytest
.raises(rarfile
.NoCrypto
):
109 run_reading("test/files/rar3-comment-hpsw.rar")
112 @pytest.mark
.skipif(not rarfile
._have
_crypto
, reason
="No crypto")
113 def test_reading_rar5_hpsw():
114 run_reading("test/files/rar5-hpsw.rar")
117 @pytest.mark
.skipif(rarfile
._have
_crypto
, reason
="Has crypto")
118 def test_reading_rar5_hpsw_nocrypto():
119 with pytest
.raises(rarfile
.NoCrypto
):
120 run_reading("test/files/rar5-hpsw.rar")
123 def test_reading_rar3_sfx():
124 assert rarfile
.is_rarfile("test/files/rar3-seektest.sfx") is False
125 assert rarfile
.is_rarfile_sfx("test/files/rar3-seektest.sfx") is True
126 run_reading("test/files/rar3-seektest.sfx")
127 run_reading("test/files/rar3-seektest.sfx")
130 def test_reading_rar5_crc_sfx():
131 assert rarfile
.is_rarfile("test/files/rar5-crc.sfx") is False
132 assert rarfile
.is_rarfile_sfx("test/files/rar5-crc.sfx") is True
133 run_reading("test/files/rar5-crc.sfx")