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
import zipfile
@@ -21,12 +22,17 @@ class itertools:
21
22
Counter = Counter
22
23
23
24
25
+ def _make_link (info : zipfile .ZipInfo ): # type: ignore[name-defined]
26
+ info .external_attr |= stat .S_IFLNK << 16
27
+
28
+
24
29
def build_alpharep_fixture ():
25
30
"""
26
31
Create a zip file with this structure:
27
32
28
33
.
29
34
├── a.txt
35
+ ├── n.txt (-> a.txt)
30
36
├── b
31
37
│ ├── c.txt
32
38
│ ├── d
@@ -47,6 +53,7 @@ def build_alpharep_fixture():
47
53
- multiple files in a directory (b/c, b/f)
48
54
- a directory containing only a directory (g/h)
49
55
- a directory with files of different extensions (j/klm)
56
+ - a symlink (n) pointing to (a)
50
57
51
58
"alpha" because it uses alphabet
52
59
"rep" because it's a representative example
@@ -61,6 +68,9 @@ def build_alpharep_fixture():
61
68
zf .writestr ("j/k.bin" , b"content of k" )
62
69
zf .writestr ("j/l.baz" , b"content of l" )
63
70
zf .writestr ("j/m.bar" , b"content of m" )
71
+ zf .writestr ("n.txt" , b"a.txt" )
72
+ _make_link (zf .infolist ()[- 1 ])
73
+
64
74
zf .filename = "alpharep.zip"
65
75
return zf
66
76
@@ -91,7 +101,7 @@ def zipfile_ondisk(self, alpharep):
91
101
def test_iterdir_and_types (self , alpharep ):
92
102
root = zipfile .Path (alpharep )
93
103
assert root .is_dir ()
94
- a , b , g , j = root .iterdir ()
104
+ a , k , b , g , j = root .iterdir ()
95
105
assert a .is_file ()
96
106
assert b .is_dir ()
97
107
assert g .is_dir ()
@@ -111,7 +121,7 @@ def test_is_file_missing(self, alpharep):
111
121
@pass_alpharep
112
122
def test_iterdir_on_file (self , alpharep ):
113
123
root = zipfile .Path (alpharep )
114
- a , b , g , j = root .iterdir ()
124
+ a , k , b , g , j = root .iterdir ()
115
125
with self .assertRaises (ValueError ):
116
126
a .iterdir ()
117
127
@@ -126,7 +136,7 @@ def test_subdir_is_dir(self, alpharep):
126
136
@pass_alpharep
127
137
def test_open (self , alpharep ):
128
138
root = zipfile .Path (alpharep )
129
- a , b , g , j = root .iterdir ()
139
+ a , k , b , g , j = root .iterdir ()
130
140
with a .open (encoding = "utf-8" ) as strm :
131
141
data = strm .read ()
132
142
self .assertEqual (data , "content of a" )
@@ -230,7 +240,7 @@ def test_open_missing_directory(self, alpharep):
230
240
@pass_alpharep
231
241
def test_read (self , alpharep ):
232
242
root = zipfile .Path (alpharep )
233
- a , b , g , j = root .iterdir ()
243
+ a , k , b , g , j = root .iterdir ()
234
244
assert a .read_text (encoding = "utf-8" ) == "content of a"
235
245
# Also check positional encoding arg (gh-101144).
236
246
assert a .read_text ("utf-8" ) == "content of a"
@@ -296,7 +306,7 @@ def test_mutability(self, alpharep):
296
306
reflect that change.
297
307
"""
298
308
root = zipfile .Path (alpharep )
299
- a , b , g , j = root .iterdir ()
309
+ a , k , b , g , j = root .iterdir ()
300
310
alpharep .writestr ('foo.txt' , 'foo' )
301
311
alpharep .writestr ('bar/baz.txt' , 'baz' )
302
312
assert any (child .name == 'foo.txt' for child in root .iterdir ())
@@ -513,12 +523,9 @@ def test_eq_hash(self, alpharep):
513
523
514
524
@pass_alpharep
515
525
def test_is_symlink (self , alpharep ):
516
- """
517
- See python/cpython#82102 for symlink support beyond this object.
518
- """
519
-
520
526
root = zipfile .Path (alpharep )
521
- assert not root .is_symlink ()
527
+ assert not root .joinpath ('a.txt' ).is_symlink ()
528
+ assert root .joinpath ('n.txt' ).is_symlink ()
522
529
523
530
@pass_alpharep
524
531
def test_relative_to (self , alpharep ):
0 commit comments