[3.10] bpo-43988: Add test.support.check_disallow_instantiation() (GH-25757) (GH-26885)
(cherry picked from commit 4f725261c6cf23d259e8fdc205e12b76ef4d2d31, fbff5387c3e1f3904420fa5a27738c6c5881305b, and 8cec740820fc875117bfa7b6bdb10202ebeb8fd5)
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
Automerge-Triggered-By: GH:vstinner
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
index 76754b6..1623bf3 100644
--- a/Lib/test/test_hashlib.py
+++ b/Lib/test/test_hashlib.py
@@ -915,20 +915,13 @@ def test_disallow_instantiation(self):
except ValueError:
continue
with self.subTest(constructor=constructor):
- hash_type = type(h)
- self.assertRaises(TypeError, hash_type)
+ support.check_disallow_instantiation(self, type(h))
@unittest.skipUnless(HASH is not None, 'need _hashlib')
- def test_hash_disallow_instanciation(self):
+ def test_hash_disallow_instantiation(self):
# internal types like _hashlib.HASH are not constructable
- with self.assertRaisesRegex(
- TypeError, "cannot create '_hashlib.HASH' instance"
- ):
- HASH()
- with self.assertRaisesRegex(
- TypeError, "cannot create '_hashlib.HASHXOF' instance"
- ):
- HASHXOF()
+ support.check_disallow_instantiation(self, HASH)
+ support.check_disallow_instantiation(self, HASHXOF)
def test_readonly_types(self):
for algorithm, constructors in self.constructors_to_test.items():