MCPcopy Create free account
hub / github.com/python/cpython / test_str_subclass_error

Method test_str_subclass_error

Lib/test/test_functools.py:568–580  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

566 self.assertEqual(repr(g_partial),"functools.partial(Function(old_function), EvilObject, None, None, None, None, arg=None)")
567
568 def test_str_subclass_error(self):
569 class BadStr(str):
570 def __eq__(self, other):
571 raise RuntimeError
572 def __hash__(self):
573 return str.__hash__(self)
574
575 def f(**kwargs):
576 return kwargs
577
578 p = functools.partial(f, poison="")
579 with self.assertRaises(RuntimeError):
580 result = p(**{BadStr("poison"): "new_value"})
581
582@unittest.skipUnless(c_functools, 'requires the C _functools module')
583class TestPartialC(TestPartial, unittest.TestCase):

Callers

nothing calls this directly

Calls 4

partialMethod · 0.80
BadStrClass · 0.70
pFunction · 0.50
assertRaisesMethod · 0.45

Tested by

no test coverage detected