mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-137589: Zipfile tests: close file objects (GH-138080)
Zipfile tests: close file objects
This commit is contained in:
parent
c4e7d245d6
commit
5cea843594
2 changed files with 26 additions and 19 deletions
|
|
@ -274,7 +274,8 @@ def test_pathlike_construction(self, alpharep):
|
|||
"""
|
||||
zipfile_ondisk = self.zipfile_ondisk(alpharep)
|
||||
pathlike = FakePath(str(zipfile_ondisk))
|
||||
zipfile.Path(pathlike)
|
||||
root = zipfile.Path(pathlike)
|
||||
root.root.close()
|
||||
|
||||
@pass_alpharep
|
||||
def test_traverse_pathlike(self, alpharep):
|
||||
|
|
@ -373,6 +374,7 @@ def test_root_on_disk(self, alpharep):
|
|||
root = zipfile.Path(self.zipfile_ondisk(alpharep))
|
||||
assert root.name == 'alpharep.zip' == root.filename.name
|
||||
assert root.stem == 'alpharep' == root.filename.stem
|
||||
root.root.close()
|
||||
|
||||
@pass_alpharep
|
||||
def test_suffix(self, alpharep):
|
||||
|
|
@ -574,11 +576,13 @@ def test_inheritance(self, alpharep):
|
|||
)
|
||||
def test_pickle(self, alpharep, path_type, subpath):
|
||||
zipfile_ondisk = path_type(str(self.zipfile_ondisk(alpharep)))
|
||||
|
||||
saved_1 = pickle.dumps(zipfile.Path(zipfile_ondisk, at=subpath))
|
||||
root = zipfile.Path(zipfile_ondisk, at=subpath)
|
||||
saved_1 = pickle.dumps(root)
|
||||
root.root.close()
|
||||
restored_1 = pickle.loads(saved_1)
|
||||
first, *rest = restored_1.iterdir()
|
||||
assert first.read_text(encoding='utf-8').startswith('content of ')
|
||||
restored_1.root.close()
|
||||
|
||||
@pass_alpharep
|
||||
def test_extract_orig_with_implied_dirs(self, alpharep):
|
||||
|
|
@ -590,6 +594,7 @@ def test_extract_orig_with_implied_dirs(self, alpharep):
|
|||
# wrap the zipfile for its side effect
|
||||
zipfile.Path(zf)
|
||||
zf.extractall(source_path.parent)
|
||||
zf.close()
|
||||
|
||||
@pass_alpharep
|
||||
def test_getinfo_missing(self, alpharep):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue