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

Method test_str_of_str_subclass

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

Source from the content-addressed store, hash-verified

3727 pass
3728
3729 def test_str_of_str_subclass(self):
3730 # Testing __str__ defined in subclass of str ...
3731 import binascii
3732
3733 class octetstring(str):
3734 def __str__(self):
3735 return binascii.b2a_hex(self.encode('ascii')).decode("ascii")
3736 def __repr__(self):
3737 return self + " repr"
3738
3739 o = octetstring('A')
3740 self.assertEqual(type(o), octetstring)
3741 self.assertEqual(type(str(o)), str)
3742 self.assertEqual(type(repr(o)), str)
3743 self.assertEqual(ord(o), 0x41)
3744 self.assertEqual(str(o), '41')
3745 self.assertEqual(repr(o), 'A repr')
3746 self.assertEqual(o.__str__(), '41')
3747 self.assertEqual(o.__repr__(), 'A repr')
3748
3749 def test_repr_with_module_str_subclass(self):
3750 # gh-98783

Callers

nothing calls this directly

Calls 5

octetstringClass · 0.85
strFunction · 0.85
assertEqualMethod · 0.45
__str__Method · 0.45
__repr__Method · 0.45

Tested by

no test coverage detected