(self)
| 895 | self.assertEqual(my_struct.pack(12345), b'\x30\x39') |
| 896 | |
| 897 | def test_custom_struct_new(self): |
| 898 | # New way, no warnings: |
| 899 | class MyStruct(struct.Struct): |
| 900 | def __new__(cls, *args, **kwargs): |
| 901 | return super().__new__(cls, '>h') |
| 902 | |
| 903 | for format in '>h', '<h', 42, '$', '\u20ac', '\udc00', b'\xa4': |
| 904 | with self.subTest(format=format): |
| 905 | my_struct = MyStruct(format) |
| 906 | self.assertEqual(my_struct.format, '>h') |
| 907 | self.assertEqual(my_struct.pack(12345), b'\x30\x39') |
| 908 | my_struct = MyStruct(format='<h') |
| 909 | self.assertEqual(my_struct.format, '>h') |
| 910 | self.assertEqual(my_struct.pack(12345), b'\x30\x39') |
| 911 | my_struct = MyStruct() |
| 912 | self.assertEqual(my_struct.format, '>h') |
| 913 | self.assertEqual(my_struct.pack(12345), b'\x30\x39') |
| 914 | my_struct = MyStruct('<h', 42) |
| 915 | self.assertEqual(my_struct.format, '>h') |
| 916 | self.assertEqual(my_struct.pack(12345), b'\x30\x39') |
| 917 | |
| 918 | def test_custom_struct_new_and_init(self): |
| 919 | # New way, no warnings: |
nothing calls this directly
no test coverage detected