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

Method test_no_custom_struct_new_or_init

Lib/test/test_struct.py:961–988  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

959 self.assertEqual(my_struct.pack(12345), b'\x39\x30')
960
961 def test_no_custom_struct_new_or_init(self):
962 class MyStruct(struct.Struct):
963 pass
964
965 my_struct = MyStruct('>h')
966 self.assertEqual(my_struct.format, '>h')
967 self.assertEqual(my_struct.pack(12345), b'\x30\x39')
968 my_struct = MyStruct(format='>h')
969 self.assertEqual(my_struct.format, '>h')
970 self.assertEqual(my_struct.pack(12345), b'\x30\x39')
971 with self.assertRaises(TypeError):
972 MyStruct()
973 with self.assertRaises(TypeError):
974 MyStruct(42)
975 with self.assertRaises(struct.error):
976 MyStruct('$')
977 with self.assertRaises(ValueError):
978 MyStruct('\udc00')
979 with self.assertRaises(ValueError):
980 MyStruct(b'\xa4')
981 with self.assertRaises(TypeError):
982 MyStruct('>h', 42)
983 with self.assertRaises(TypeError):
984 MyStruct('>h', arg=42)
985 with self.assertRaises(TypeError):
986 MyStruct(arg=42)
987 with self.assertRaises(TypeError):
988 MyStruct('>h', format='>h')
989
990 def test_repr(self):
991 s = struct.Struct('=i2H')

Callers

nothing calls this directly

Calls 4

MyStructClass · 0.85
assertEqualMethod · 0.45
packMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected