Skip to content

Commit

Permalink
pythongh-113212: Test supercheck error message
Browse files Browse the repository at this point in the history
  • Loading branch information
WolframAlph committed Dec 20, 2023
1 parent 3b7e6fd commit f33fc36
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Lib/test/test_super.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,25 @@ def method(self):
with self.assertRaisesRegex(TypeError, "argument 1 must be a type"):
C().method()

def test_supercheck_fail(self):
class C:
def method(self, type_, obj):
return super(type_, obj).method()

c = C()
err_msg = r"super\(type, obj\): obj must be an instance or subtype of type. "
cases = (
(int, c, int.__name__, C.__name__),
(C, list(), C.__name__, list.__name__), # obj is instance of type
(C, list, C.__name__, list.__name__), # obj is type itself
)

for type_, obj, type_str, obj_type_str in cases:
regex = err_msg + f"Got obj: '{obj_type_str}', type: '{type_str}'."

with self.assertRaisesRegex(TypeError, regex):
c.method(type_, obj)

def test_super___class__(self):
class C:
def method(self):
Expand Down

0 comments on commit f33fc36

Please sign in to comment.