mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
bpo-45975: Simplify some while-loops with walrus operator (GH-29347)
This commit is contained in:
parent
25bc115df9
commit
024ac542d7
28 changed files with 41 additions and 153 deletions
|
@ -825,10 +825,7 @@ class FileTestCase(unittest.TestCase):
|
|||
def test_read_10(self):
|
||||
with LZMAFile(BytesIO(COMPRESSED_XZ)) as f:
|
||||
chunks = []
|
||||
while True:
|
||||
result = f.read(10)
|
||||
if not result:
|
||||
break
|
||||
while result := f.read(10):
|
||||
self.assertLessEqual(len(result), 10)
|
||||
chunks.append(result)
|
||||
self.assertEqual(b"".join(chunks), INPUT)
|
||||
|
@ -911,10 +908,7 @@ class FileTestCase(unittest.TestCase):
|
|||
def test_read1(self):
|
||||
with LZMAFile(BytesIO(COMPRESSED_XZ)) as f:
|
||||
blocks = []
|
||||
while True:
|
||||
result = f.read1()
|
||||
if not result:
|
||||
break
|
||||
while result := f.read1():
|
||||
blocks.append(result)
|
||||
self.assertEqual(b"".join(blocks), INPUT)
|
||||
self.assertEqual(f.read1(), b"")
|
||||
|
@ -926,10 +920,7 @@ class FileTestCase(unittest.TestCase):
|
|||
def test_read1_10(self):
|
||||
with LZMAFile(BytesIO(COMPRESSED_XZ)) as f:
|
||||
blocks = []
|
||||
while True:
|
||||
result = f.read1(10)
|
||||
if not result:
|
||||
break
|
||||
while result := f.read1(10):
|
||||
blocks.append(result)
|
||||
self.assertEqual(b"".join(blocks), INPUT)
|
||||
self.assertEqual(f.read1(), b"")
|
||||
|
@ -937,10 +928,7 @@ class FileTestCase(unittest.TestCase):
|
|||
def test_read1_multistream(self):
|
||||
with LZMAFile(BytesIO(COMPRESSED_XZ * 5)) as f:
|
||||
blocks = []
|
||||
while True:
|
||||
result = f.read1()
|
||||
if not result:
|
||||
break
|
||||
while result := f.read1():
|
||||
blocks.append(result)
|
||||
self.assertEqual(b"".join(blocks), INPUT * 5)
|
||||
self.assertEqual(f.read1(), b"")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue