mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Issue #14099: Backout changeset e5bb3044402b (except adapted tests).
This commit is contained in:
parent
b6c0c5ba5f
commit
b76bcc4ffc
4 changed files with 105 additions and 135 deletions
|
@ -1653,52 +1653,22 @@ class TestsWithMultipleOpens(unittest.TestCase):
|
|||
def test_same_file(self):
|
||||
# Verify that (when the ZipFile is in control of creating file objects)
|
||||
# multiple open() calls can be made without interfering with each other.
|
||||
for f in get_files(self):
|
||||
self.make_test_archive(f)
|
||||
with zipfile.ZipFile(f, mode="r") as zipf:
|
||||
with zipf.open('ones') as zopen1, zipf.open('ones') as zopen2:
|
||||
data1 = zopen1.read(500)
|
||||
data2 = zopen2.read(500)
|
||||
data1 += zopen1.read()
|
||||
data2 += zopen2.read()
|
||||
self.assertEqual(data1, data2)
|
||||
self.assertEqual(data1, self.data1)
|
||||
self.make_test_archive(TESTFN2)
|
||||
with zipfile.ZipFile(TESTFN2, mode="r") as zipf:
|
||||
with zipf.open('ones') as zopen1, zipf.open('ones') as zopen2:
|
||||
data1 = zopen1.read(500)
|
||||
data2 = zopen2.read(500)
|
||||
data1 += zopen1.read()
|
||||
data2 += zopen2.read()
|
||||
self.assertEqual(data1, data2)
|
||||
self.assertEqual(data1, self.data1)
|
||||
|
||||
def test_different_file(self):
|
||||
# Verify that (when the ZipFile is in control of creating file objects)
|
||||
# multiple open() calls can be made without interfering with each other.
|
||||
for f in get_files(self):
|
||||
self.make_test_archive(f)
|
||||
with zipfile.ZipFile(f, mode="r") as zipf:
|
||||
with zipf.open('ones') as zopen1, zipf.open('twos') as zopen2:
|
||||
data1 = zopen1.read(500)
|
||||
data2 = zopen2.read(500)
|
||||
data1 += zopen1.read()
|
||||
data2 += zopen2.read()
|
||||
self.assertEqual(data1, self.data1)
|
||||
self.assertEqual(data2, self.data2)
|
||||
|
||||
def test_interleaved(self):
|
||||
# Verify that (when the ZipFile is in control of creating file objects)
|
||||
# multiple open() calls can be made without interfering with each other.
|
||||
for f in get_files(self):
|
||||
self.make_test_archive(f)
|
||||
with zipfile.ZipFile(f, mode="r") as zipf:
|
||||
with zipf.open('ones') as zopen1, zipf.open('twos') as zopen2:
|
||||
data1 = zopen1.read(500)
|
||||
data2 = zopen2.read(500)
|
||||
data1 += zopen1.read()
|
||||
data2 += zopen2.read()
|
||||
self.assertEqual(data1, self.data1)
|
||||
self.assertEqual(data2, self.data2)
|
||||
|
||||
def test_read_after_close(self):
|
||||
for f in get_files(self):
|
||||
self.make_test_archive(f)
|
||||
with contextlib.ExitStack() as stack:
|
||||
with zipfile.ZipFile(f, 'r') as zipf:
|
||||
zopen1 = stack.enter_context(zipf.open('ones'))
|
||||
zopen2 = stack.enter_context(zipf.open('twos'))
|
||||
self.make_test_archive(TESTFN2)
|
||||
with zipfile.ZipFile(TESTFN2, mode="r") as zipf:
|
||||
with zipf.open('ones') as zopen1, zipf.open('twos') as zopen2:
|
||||
data1 = zopen1.read(500)
|
||||
data2 = zopen2.read(500)
|
||||
data1 += zopen1.read()
|
||||
|
@ -1706,32 +1676,56 @@ class TestsWithMultipleOpens(unittest.TestCase):
|
|||
self.assertEqual(data1, self.data1)
|
||||
self.assertEqual(data2, self.data2)
|
||||
|
||||
def test_read_after_write(self):
|
||||
for f in get_files(self):
|
||||
with zipfile.ZipFile(f, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
||||
zipf.writestr('ones', self.data1)
|
||||
zipf.writestr('twos', self.data2)
|
||||
with zipf.open('ones') as zopen1:
|
||||
data1 = zopen1.read(500)
|
||||
self.assertEqual(data1, self.data1[:500])
|
||||
with zipfile.ZipFile(f, 'r') as zipf:
|
||||
data1 = zipf.read('ones')
|
||||
data2 = zipf.read('twos')
|
||||
def test_interleaved(self):
|
||||
# Verify that (when the ZipFile is in control of creating file objects)
|
||||
# multiple open() calls can be made without interfering with each other.
|
||||
self.make_test_archive(TESTFN2)
|
||||
with zipfile.ZipFile(TESTFN2, mode="r") as zipf:
|
||||
with zipf.open('ones') as zopen1, zipf.open('twos') as zopen2:
|
||||
data1 = zopen1.read(500)
|
||||
data2 = zopen2.read(500)
|
||||
data1 += zopen1.read()
|
||||
data2 += zopen2.read()
|
||||
self.assertEqual(data1, self.data1)
|
||||
self.assertEqual(data2, self.data2)
|
||||
|
||||
def test_read_after_close(self):
|
||||
self.make_test_archive(TESTFN2)
|
||||
with contextlib.ExitStack() as stack:
|
||||
with zipfile.ZipFile(TESTFN2, 'r') as zipf:
|
||||
zopen1 = stack.enter_context(zipf.open('ones'))
|
||||
zopen2 = stack.enter_context(zipf.open('twos'))
|
||||
data1 = zopen1.read(500)
|
||||
data2 = zopen2.read(500)
|
||||
data1 += zopen1.read()
|
||||
data2 += zopen2.read()
|
||||
self.assertEqual(data1, self.data1)
|
||||
self.assertEqual(data2, self.data2)
|
||||
|
||||
def test_read_after_write(self):
|
||||
with zipfile.ZipFile(TESTFN2, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
||||
zipf.writestr('ones', self.data1)
|
||||
zipf.writestr('twos', self.data2)
|
||||
with zipf.open('ones') as zopen1:
|
||||
data1 = zopen1.read(500)
|
||||
self.assertEqual(data1, self.data1[:500])
|
||||
with zipfile.ZipFile(TESTFN2, 'r') as zipf:
|
||||
data1 = zipf.read('ones')
|
||||
data2 = zipf.read('twos')
|
||||
self.assertEqual(data1, self.data1)
|
||||
self.assertEqual(data2, self.data2)
|
||||
|
||||
def test_write_after_read(self):
|
||||
for f in get_files(self):
|
||||
with zipfile.ZipFile(f, "w", zipfile.ZIP_DEFLATED) as zipf:
|
||||
zipf.writestr('ones', self.data1)
|
||||
with zipf.open('ones') as zopen1:
|
||||
zopen1.read(500)
|
||||
zipf.writestr('twos', self.data2)
|
||||
with zipfile.ZipFile(f, 'r') as zipf:
|
||||
data1 = zipf.read('ones')
|
||||
data2 = zipf.read('twos')
|
||||
self.assertEqual(data1, self.data1)
|
||||
self.assertEqual(data2, self.data2)
|
||||
with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_DEFLATED) as zipf:
|
||||
zipf.writestr('ones', self.data1)
|
||||
with zipf.open('ones') as zopen1:
|
||||
zopen1.read(500)
|
||||
zipf.writestr('twos', self.data2)
|
||||
with zipfile.ZipFile(TESTFN2, 'r') as zipf:
|
||||
data1 = zipf.read('ones')
|
||||
data2 = zipf.read('twos')
|
||||
self.assertEqual(data1, self.data1)
|
||||
self.assertEqual(data2, self.data2)
|
||||
|
||||
def test_many_opens(self):
|
||||
# Verify that read() and open() promptly close the file descriptor,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue