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 21, 2023
1 parent 0f7d134 commit 13c3597
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 \({} {}\) is not an instance or subtype of type \({}\)."
cases = (
(int, c, int.__name__, C.__name__, "instance of"),
(C, list(), C.__name__, list.__name__, "instance of"), # obj is instance of type
(C, list, C.__name__, list.__name__, "type"), # obj is type itself
)

for type_, obj, type_str, obj_str, instance_or_type in cases:
regex = err_msg.format(instance_or_type, obj_str, 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 13c3597

Please sign in to comment.