mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
gh-106531: Refresh zipfile._path with zipp 3.18. (#116835)
* gh-106531: Refresh zipfile._path with zipp 3.18. * Add blurb
This commit is contained in:
parent
ab9e322ae1
commit
be59aaf3ab
5 changed files with 159 additions and 54 deletions
|
@ -6,6 +6,7 @@ import pickle
|
|||
import sys
|
||||
import unittest
|
||||
import zipfile
|
||||
import zipfile._path
|
||||
|
||||
from ._functools import compose
|
||||
from ._itertools import Counter
|
||||
|
@ -20,16 +21,6 @@ class jaraco:
|
|||
Counter = Counter
|
||||
|
||||
|
||||
def add_dirs(zf):
|
||||
"""
|
||||
Given a writable zip file zf, inject directory entries for
|
||||
any directories implied by the presence of children.
|
||||
"""
|
||||
for name in zipfile.CompleteDirs._implied_dirs(zf.namelist()):
|
||||
zf.writestr(name, b"")
|
||||
return zf
|
||||
|
||||
|
||||
def build_alpharep_fixture():
|
||||
"""
|
||||
Create a zip file with this structure:
|
||||
|
@ -76,7 +67,7 @@ def build_alpharep_fixture():
|
|||
|
||||
alpharep_generators = [
|
||||
Invoked.wrap(build_alpharep_fixture),
|
||||
Invoked.wrap(compose(add_dirs, build_alpharep_fixture)),
|
||||
Invoked.wrap(compose(zipfile._path.CompleteDirs.inject, build_alpharep_fixture)),
|
||||
]
|
||||
|
||||
pass_alpharep = parameterize(['alpharep'], alpharep_generators)
|
||||
|
@ -210,11 +201,12 @@ class TestPath(unittest.TestCase):
|
|||
with zf.joinpath('file.txt').open('w', encoding="utf-8") as strm:
|
||||
strm.write('text file')
|
||||
|
||||
def test_open_extant_directory(self):
|
||||
@pass_alpharep
|
||||
def test_open_extant_directory(self, alpharep):
|
||||
"""
|
||||
Attempting to open a directory raises IsADirectoryError.
|
||||
"""
|
||||
zf = zipfile.Path(add_dirs(build_alpharep_fixture()))
|
||||
zf = zipfile.Path(alpharep)
|
||||
with self.assertRaises(IsADirectoryError):
|
||||
zf.joinpath('b').open()
|
||||
|
||||
|
@ -226,11 +218,12 @@ class TestPath(unittest.TestCase):
|
|||
with self.assertRaises(ValueError):
|
||||
root.joinpath('a.txt').open('rb', 'utf-8')
|
||||
|
||||
def test_open_missing_directory(self):
|
||||
@pass_alpharep
|
||||
def test_open_missing_directory(self, alpharep):
|
||||
"""
|
||||
Attempting to open a missing directory raises FileNotFoundError.
|
||||
"""
|
||||
zf = zipfile.Path(add_dirs(build_alpharep_fixture()))
|
||||
zf = zipfile.Path(alpharep)
|
||||
with self.assertRaises(FileNotFoundError):
|
||||
zf.joinpath('z').open()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue