From 8bbd858249f9ca1d8791e7e7c6ff0d88dcae1db6 Mon Sep 17 00:00:00 2001 From: simple-is-great Date: Sat, 2 Nov 2024 15:39:45 +0900 Subject: [PATCH 1/4] gh-125522: Fix bare except in test_zlib.test_flushes --- Lib/test/test_zlib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py index 8b4bb8750f8f5c..b9256baad29e4f 100644 --- a/Lib/test/test_zlib.py +++ b/Lib/test/test_zlib.py @@ -511,7 +511,7 @@ def test_flushes(self): b = obj.flush( sync ) c = obj.compress( data[3000:] ) d = obj.flush() - except: + except zlib.error: print("Error for flush mode={}, level={}" .format(sync, level)) raise From 34c797c7263ffa6d25035fd2c34defb74a1e13e2 Mon Sep 17 00:00:00 2001 From: simple-is-great Date: Sat, 2 Nov 2024 16:50:38 +0900 Subject: [PATCH 2/4] Address code review --- Lib/test/test_zlib.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py index b9256baad29e4f..2ff8c61becffe7 100644 --- a/Lib/test/test_zlib.py +++ b/Lib/test/test_zlib.py @@ -505,20 +505,17 @@ def test_flushes(self): for sync in sync_opt: for level in range(10): - try: + with self.subTest(sync=sync, level=level): obj = zlib.compressobj( level ) a = obj.compress( data[:3000] ) b = obj.flush( sync ) c = obj.compress( data[3000:] ) d = obj.flush() - except zlib.error: - print("Error for flush mode={}, level={}" - .format(sync, level)) - raise - self.assertEqual(zlib.decompress(b''.join([a,b,c,d])), - data, ("Decompress failed: flush " - "mode=%i, level=%i") % (sync, level)) - del obj + + self.assertEqual(zlib.decompress(b''.join([a,b,c,d])), + data, ("Decompress failed: flush " + "mode=%i, level=%i") % (sync, level)) + del obj @unittest.skipUnless(hasattr(zlib, 'Z_SYNC_FLUSH'), 'requires zlib.Z_SYNC_FLUSH') From e016be4d98d878f9a409a623498a06a1bc521f3a Mon Sep 17 00:00:00 2001 From: simple-is-great Date: Sat, 2 Nov 2024 16:56:22 +0900 Subject: [PATCH 3/4] address code review: fixed whitespaces and format --- Lib/test/test_zlib.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py index 2ff8c61becffe7..950c964f0e4520 100644 --- a/Lib/test/test_zlib.py +++ b/Lib/test/test_zlib.py @@ -511,10 +511,9 @@ def test_flushes(self): b = obj.flush( sync ) c = obj.compress( data[3000:] ) d = obj.flush() - self.assertEqual(zlib.decompress(b''.join([a,b,c,d])), - data, ("Decompress failed: flush " - "mode=%i, level=%i") % (sync, level)) + data, ("Decompress failed: flush " + "mode=%i, level=%i") % (sync, level)) del obj @unittest.skipUnless(hasattr(zlib, 'Z_SYNC_FLUSH'), From d0a8af5d0d58c8d69d59764ecf4cbb6b4a8b86e4 Mon Sep 17 00:00:00 2001 From: simple-is-great <103080930+simple-is-great@users.noreply.github.com> Date: Sat, 2 Nov 2024 17:02:03 +0900 Subject: [PATCH 4/4] Update Lib/test/test_zlib.py Co-authored-by: Sergey B Kirpichev --- Lib/test/test_zlib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py index 950c964f0e4520..4d97fe56f3a094 100644 --- a/Lib/test/test_zlib.py +++ b/Lib/test/test_zlib.py @@ -513,7 +513,7 @@ def test_flushes(self): d = obj.flush() self.assertEqual(zlib.decompress(b''.join([a,b,c,d])), data, ("Decompress failed: flush " - "mode=%i, level=%i") % (sync, level)) + "mode=%i, level=%i") % (sync, level)) del obj @unittest.skipUnless(hasattr(zlib, 'Z_SYNC_FLUSH'),