MCPcopy Index your code
hub / github.com/python/cpython / test_classmethods_in_c

Method test_classmethods_in_c

Lib/test/test_descr.py:1757–1804  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1755 @support.impl_detail("the module 'xxsubtype' is internal")
1756 @unittest.skipIf(xxsubtype is None, "requires xxsubtype module")
1757 def test_classmethods_in_c(self):
1758 # Testing C-based class methods...
1759 import xxsubtype as spam
1760 a = (1, 2, 3)
1761 d = {'abc': 123}
1762 x, a1, d1 = spam.spamlist.classmeth(*a, **d)
1763 self.assertEqual(x, spam.spamlist)
1764 self.assertEqual(a, a1)
1765 self.assertEqual(d, d1)
1766 x, a1, d1 = spam.spamlist().classmeth(*a, **d)
1767 self.assertEqual(x, spam.spamlist)
1768 self.assertEqual(a, a1)
1769 self.assertEqual(d, d1)
1770 spam_cm = spam.spamlist.__dict__['classmeth']
1771 x2, a2, d2 = spam_cm(spam.spamlist, *a, **d)
1772 self.assertEqual(x2, spam.spamlist)
1773 self.assertEqual(a2, a1)
1774 self.assertEqual(d2, d1)
1775 class SubSpam(spam.spamlist): pass
1776 x2, a2, d2 = spam_cm(SubSpam, *a, **d)
1777 self.assertEqual(x2, SubSpam)
1778 self.assertEqual(a2, a1)
1779 self.assertEqual(d2, d1)
1780
1781 with self.assertRaises(TypeError) as cm:
1782 spam_cm()
1783 self.assertEqual(
1784 str(cm.exception),
1785 "descriptor 'classmeth' of 'xxsubtype.spamlist' "
1786 "object needs an argument")
1787
1788 with self.assertRaises(TypeError) as cm:
1789 spam_cm(spam.spamlist())
1790 self.assertEqual(
1791 str(cm.exception),
1792 "descriptor 'classmeth' for type 'xxsubtype.spamlist' "
1793 "needs a type, not a 'xxsubtype.spamlist' as arg 2")
1794
1795 with self.assertRaises(TypeError) as cm:
1796 spam_cm(list)
1797 expected_errmsg = (
1798 "descriptor 'classmeth' requires a subtype of 'xxsubtype.spamlist' "
1799 "but received 'list'")
1800 self.assertEqual(str(cm.exception), expected_errmsg)
1801
1802 with self.assertRaises(TypeError) as cm:
1803 spam_cm.__get__(None, list)
1804 self.assertEqual(str(cm.exception), expected_errmsg)
1805
1806 @support.cpython_only
1807 def test_method_get_meth_method_invalid_type(self):

Callers

nothing calls this directly

Calls 6

strFunction · 0.85
classmethMethod · 0.80
spamlistMethod · 0.80
assertEqualMethod · 0.45
assertRaisesMethod · 0.45
__get__Method · 0.45

Tested by

no test coverage detected