File: test_info.py

package info (click to toggle)
py7zr 0.22.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,300 kB
  • sloc: python: 8,740; makefile: 197; ansic: 35
file content (137 lines) | stat: -rw-r--r-- 4,268 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import os
import sys

import pytest

import py7zr
from py7zr.exceptions import UnsupportedCompressionMethodError

try:
    import inflate64  # type: ignore
except ImportError:
    inflate64 = None

testdata_path = os.path.join(os.path.dirname(__file__), "data")
os.umask(0o022)


@pytest.mark.files
def test_archiveinfo_deflate():
    with py7zr.SevenZipFile(os.path.join(testdata_path, "deflate.7z"), "r") as ar:
        ai = ar.archiveinfo()
        assert ai.method_names[0] == "DEFLATE"


@pytest.mark.files
def test_archiveinfo_deflate64():
    with py7zr.SevenZipFile(os.path.join(testdata_path, "deflate64.7z"), "r") as ar:
        ai = ar.archiveinfo()
        assert ai.method_names[0] == "DEFLATE64"


@pytest.mark.files
def test_archiveinfo_lzma_bcj2():
    with py7zr.SevenZipFile(os.path.join(testdata_path, "lzma_bcj2_1.7z"), "r") as ar:
        ai = ar.archiveinfo()
        assert ai.method_names == ["LZMA", "BCJ2*"]


@pytest.mark.files
def test_archiveinfo_lzma_bcj():
    with py7zr.SevenZipFile(os.path.join(testdata_path, "lzma_bcj_x86.7z"), "r") as ar:
        ai = ar.archiveinfo()
        assert ai.method_names == ["LZMA", "BCJ"]


@pytest.mark.files
def test_archiveinfo_lzma2_bcj():
    with py7zr.SevenZipFile(os.path.join(testdata_path, "lzma2bcj.7z"), "r") as ar:
        ai = ar.archiveinfo()
        assert ai.method_names == ["LZMA2", "BCJ"]


@pytest.mark.files
def test_archiveinfo_lzma2_bcj_arm():
    with py7zr.SevenZipFile(os.path.join(testdata_path, "lzma2_bcj_arm.7z"), "r") as ar:
        ai = ar.archiveinfo()
        assert ai.method_names == ["LZMA2", "ARM"]


@pytest.mark.files
def test_archiveinfo_lzma2_bcj_armt():
    with py7zr.SevenZipFile(os.path.join(testdata_path, "lzma2_bcj_armt.7z"), "r") as ar:
        ai = ar.archiveinfo()
        assert ai.method_names == ["LZMA2", "ARMT"]


@pytest.mark.files
def test_archiveinfo_lzma2_bcj_ia64():
    with py7zr.SevenZipFile(os.path.join(testdata_path, "lzma2_bcj_ia64.7z"), "r") as ar:
        ai = ar.archiveinfo()
        assert ai.method_names == ["LZMA2", "IA64"]


@pytest.mark.files
def test_archiveinfo_lzma2_bcj_ppc():
    with py7zr.SevenZipFile(os.path.join(testdata_path, "lzma2_bcj_ppc.7z"), "r") as ar:
        ai = ar.archiveinfo()
        assert ai.method_names == ["LZMA2", "PPC"]


@pytest.mark.files
def test_archiveinfo_lzma2_bcj_sparc():
    with py7zr.SevenZipFile(os.path.join(testdata_path, "lzma2_bcj_sparc.7z"), "r") as ar:
        ai = ar.archiveinfo()
        assert ai.method_names == ["LZMA2", "SPARC"]


@pytest.mark.files
def test_archiveinfo_7zaes_lzma():
    with py7zr.SevenZipFile(os.path.join(testdata_path, "encrypted_1.7z"), "r") as ar:
        ai = ar.archiveinfo()
        assert ai.method_names == ["LZMA", "7zAES"]


@pytest.mark.files
def test_archivetest_deflate():
    with py7zr.SevenZipFile(os.path.join(testdata_path, "deflate.7z"), "r") as ar:
        assert ar.testzip() is None


@pytest.mark.files
@pytest.mark.skipif(hasattr(sys, "pypy_version_info"), reason="No support for deflate64 on pypy")
def test_archivetest_deflate64():
    with py7zr.SevenZipFile(os.path.join(testdata_path, "deflate64.7z"), "r") as ar:
        assert ar.testzip() is None


@pytest.mark.files
def test_archivetest_lzma_bcj2():
    with pytest.raises(UnsupportedCompressionMethodError):
        with py7zr.SevenZipFile(os.path.join(testdata_path, "lzma_bcj2_1.7z"), "r") as ar:
            assert ar.testzip() is None


@pytest.mark.files
def test_archivetest_lzma_bcj():
    with py7zr.SevenZipFile(os.path.join(testdata_path, "lzma_bcj_x86.7z"), "r") as ar:
        assert ar.testzip() is None


@pytest.mark.files
def test_archivetest_lzma2_bcj():
    with py7zr.SevenZipFile(os.path.join(testdata_path, "lzma2bcj.7z"), "r") as ar:
        assert ar.testzip() is None


@pytest.mark.files
def test_archivetest_7zaes():
    with py7zr.SevenZipFile(os.path.join(testdata_path, "encrypted_1.7z"), "r", password="secret") as ar:
        assert ar.testzip() is None


@pytest.mark.files
def test_list_filename_encryption(tmp_path):
    with py7zr.SevenZipFile(os.path.join(testdata_path, "filename_encryption.7z"), "r", password="hello") as ar:
        file_list = ar.list()
        assert file_list[0].filename == "New Text Document.TXT"