(self)
| 3922 | self.check_frame_opcodes(pickled) |
| 3923 | |
| 3924 | def test_framing_large_objects(self): |
| 3925 | if self.py_version < (3, 4): |
| 3926 | self.skipTest('not supported in Python < 3.4') |
| 3927 | N = 1024 * 1024 |
| 3928 | small_items = [[i] for i in range(10)] |
| 3929 | obj = [b'x' * N, *small_items, b'y' * N, 'z' * N] |
| 3930 | for proto in range(4, pickle.HIGHEST_PROTOCOL + 1): |
| 3931 | for fast in [False, True]: |
| 3932 | with self.subTest(proto=proto, fast=fast): |
| 3933 | if not fast: |
| 3934 | # fast=False by default. |
| 3935 | # This covers in-memory pickling with pickle.dumps(). |
| 3936 | pickled = self.dumps(obj, proto) |
| 3937 | else: |
| 3938 | # Pickler is required when fast=True. |
| 3939 | if not hasattr(self, 'pickler'): |
| 3940 | continue |
| 3941 | buf = io.BytesIO() |
| 3942 | pickler = self.pickler(buf, protocol=proto) |
| 3943 | pickler.fast = fast |
| 3944 | pickler.dump(obj) |
| 3945 | pickled = buf.getvalue() |
| 3946 | unpickled = self.loads(pickled) |
| 3947 | # More informative error message in case of failure. |
| 3948 | self.assertEqual([len(x) for x in obj], |
| 3949 | [len(x) for x in unpickled]) |
| 3950 | # Perform full equality check if the lengths match. |
| 3951 | self.assertEqual(obj, unpickled) |
| 3952 | if self.py_version >= (3, 7): |
| 3953 | n_frames = count_opcode(pickle.FRAME, pickled) |
| 3954 | # A single frame for small objects between |
| 3955 | # first two large objects. |
| 3956 | self.assertEqual(n_frames, 1) |
| 3957 | self.check_frame_opcodes(pickled) |
| 3958 | |
| 3959 | def test_optional_frames(self): |
| 3960 | if self.py_version < (3, 4): |
nothing calls this directly
no test coverage detected