3
3
import contextlib
4
4
import pathlib
5
5
import pickle
6
+ import stat
6
7
import sys
7
8
import unittest
8
9
from .compat .overlay import zipfile
15
16
from ._test_params import parameterize , Invoked
16
17
17
18
19
+ def _make_link (info : zipfile .ZipInfo ): # type: ignore[name-defined]
20
+ info .external_attr |= stat .S_IFLNK << 16
21
+
22
+
18
23
def build_alpharep_fixture ():
19
24
"""
20
25
Create a zip file with this structure:
21
26
22
27
.
23
28
├── a.txt
29
+ ├── n.txt (-> a.txt)
24
30
├── b
25
31
│ ├── c.txt
26
32
│ ├── d
@@ -41,6 +47,7 @@ def build_alpharep_fixture():
41
47
- multiple files in a directory (b/c, b/f)
42
48
- a directory containing only a directory (g/h)
43
49
- a directory with files of different extensions (j/klm)
50
+ - a symlink (n) pointing to (a)
44
51
45
52
"alpha" because it uses alphabet
46
53
"rep" because it's a representative example
@@ -55,6 +62,9 @@ def build_alpharep_fixture():
55
62
zf .writestr ("j/k.bin" , b"content of k" )
56
63
zf .writestr ("j/l.baz" , b"content of l" )
57
64
zf .writestr ("j/m.bar" , b"content of m" )
65
+ zf .writestr ("n.txt" , b"a.txt" )
66
+ _make_link (zf .infolist ()[- 1 ])
67
+
58
68
zf .filename = "alpharep.zip"
59
69
return zf
60
70
@@ -85,7 +95,7 @@ def zipfile_ondisk(self, alpharep):
85
95
def test_iterdir_and_types (self , alpharep ):
86
96
root = zipfile .Path (alpharep )
87
97
assert root .is_dir ()
88
- a , b , g , j = root .iterdir ()
98
+ a , k , b , g , j = root .iterdir ()
89
99
assert a .is_file ()
90
100
assert b .is_dir ()
91
101
assert g .is_dir ()
@@ -105,7 +115,7 @@ def test_is_file_missing(self, alpharep):
105
115
@pass_alpharep
106
116
def test_iterdir_on_file (self , alpharep ):
107
117
root = zipfile .Path (alpharep )
108
- a , b , g , j = root .iterdir ()
118
+ a , k , b , g , j = root .iterdir ()
109
119
with self .assertRaises (ValueError ):
110
120
a .iterdir ()
111
121
@@ -120,7 +130,7 @@ def test_subdir_is_dir(self, alpharep):
120
130
@pass_alpharep
121
131
def test_open (self , alpharep ):
122
132
root = zipfile .Path (alpharep )
123
- a , b , g , j = root .iterdir ()
133
+ a , k , b , g , j = root .iterdir ()
124
134
with a .open (encoding = "utf-8" ) as strm :
125
135
data = strm .read ()
126
136
self .assertEqual (data , "content of a" )
@@ -224,7 +234,7 @@ def test_open_missing_directory(self, alpharep):
224
234
@pass_alpharep
225
235
def test_read (self , alpharep ):
226
236
root = zipfile .Path (alpharep )
227
- a , b , g , j = root .iterdir ()
237
+ a , k , b , g , j = root .iterdir ()
228
238
assert a .read_text (encoding = "utf-8" ) == "content of a"
229
239
# Also check positional encoding arg (gh-101144).
230
240
assert a .read_text ("utf-8" ) == "content of a"
@@ -290,7 +300,7 @@ def test_mutability(self, alpharep):
290
300
reflect that change.
291
301
"""
292
302
root = zipfile .Path (alpharep )
293
- a , b , g , j = root .iterdir ()
303
+ a , k , b , g , j = root .iterdir ()
294
304
alpharep .writestr ('foo.txt' , 'foo' )
295
305
alpharep .writestr ('bar/baz.txt' , 'baz' )
296
306
assert any (child .name == 'foo.txt' for child in root .iterdir ())
@@ -507,12 +517,9 @@ def test_eq_hash(self, alpharep):
507
517
508
518
@pass_alpharep
509
519
def test_is_symlink (self , alpharep ):
510
- """
511
- See python/cpython#82102 for symlink support beyond this object.
512
- """
513
-
514
520
root = zipfile .Path (alpharep )
515
- assert not root .is_symlink ()
521
+ assert not root .joinpath ('a.txt' ).is_symlink ()
522
+ assert root .joinpath ('n.txt' ).is_symlink ()
516
523
517
524
@pass_alpharep
518
525
def test_relative_to (self , alpharep ):
0 commit comments