From c0f6a2f8c320d77adf67ff8572655ba578dbd576 Mon Sep 17 00:00:00 2001 From: NakanoMiku Date: Fri, 22 Dec 2023 03:18:10 +0800 Subject: [PATCH] Update test_abc.py from CPython v3.12.0 --- Lib/test/test_abc.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Lib/test/test_abc.py b/Lib/test/test_abc.py index f65b1f629..5ce57cc20 100644 --- a/Lib/test/test_abc.py +++ b/Lib/test/test_abc.py @@ -154,7 +154,7 @@ def test_factory(abc_ABCMeta, abc_get_cache_token): @abc.abstractmethod def method_one(self): pass - msg = r"class C with abstract method method_one" + msg = r"class C without an implementation for abstract method 'method_one'" self.assertRaisesRegex(TypeError, msg, C) def test_object_new_with_many_abstractmethods(self): @@ -165,7 +165,7 @@ def test_factory(abc_ABCMeta, abc_get_cache_token): @abc.abstractmethod def method_two(self): pass - msg = r"class C with abstract methods method_one, method_two" + msg = r"class C without an implementation for abstract methods 'method_one', 'method_two'" self.assertRaisesRegex(TypeError, msg, C) def test_abstractmethod_integration(self): @@ -448,15 +448,16 @@ def test_factory(abc_ABCMeta, abc_get_cache_token): # Also check that issubclass() propagates exceptions raised by # __subclasses__. + class CustomError(Exception): ... exc_msg = "exception from __subclasses__" def raise_exc(): - raise Exception(exc_msg) + raise CustomError(exc_msg) class S(metaclass=abc_ABCMeta): __subclasses__ = raise_exc - with self.assertRaisesRegex(Exception, exc_msg): + with self.assertRaisesRegex(CustomError, exc_msg): issubclass(int, S) def test_subclasshook(self): @@ -521,6 +522,7 @@ def test_factory(abc_ABCMeta, abc_get_cache_token): self.assertEqual(A.__abstractmethods__, set()) A() + def test_update_new_abstractmethods(self): class A(metaclass=abc_ABCMeta): @abc.abstractmethod @@ -534,7 +536,7 @@ def test_factory(abc_ABCMeta, abc_get_cache_token): A.foo = updated_foo abc.update_abstractmethods(A) self.assertEqual(A.__abstractmethods__, {'foo', 'bar'}) - msg = "class A with abstract methods bar, foo" + msg = "class A without an implementation for abstract methods 'bar', 'foo'" self.assertRaisesRegex(TypeError, msg, A) def test_update_implementation(self): @@ -546,7 +548,7 @@ def test_factory(abc_ABCMeta, abc_get_cache_token): class B(A): pass - msg = "class B with abstract method foo" + msg = "class B without an implementation for abstract method 'foo'" self.assertRaisesRegex(TypeError, msg, B) self.assertEqual(B.__abstractmethods__, {'foo'}) @@ -604,7 +606,7 @@ def test_factory(abc_ABCMeta, abc_get_cache_token): abc.update_abstractmethods(B) - msg = "class B with abstract method foo" + msg = "class B without an implementation for abstract method 'foo'" self.assertRaisesRegex(TypeError, msg, B) def test_update_layered_implementation(self): @@ -626,7 +628,7 @@ def test_factory(abc_ABCMeta, abc_get_cache_token): abc.update_abstractmethods(C) - msg = "class C with abstract method foo" + msg = "class C without an implementation for abstract method 'foo'" self.assertRaisesRegex(TypeError, msg, C) def test_update_multi_inheritance(self):