Skip to content

Commit c463dec

Browse files
Implement some suggestions by iritkatriel
1 parent 2dc67fe commit c463dec

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Lib/test/test_xpickle.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ class AbstractCompatTests(PyPicklerTests):
8787
_OLD_HIGHEST_PROTOCOL = pickle.HIGHEST_PROTOCOL
8888

8989
def setUp(self):
90-
self.assertTrue(self.py_version)
90+
self.assertIsNotNone(self.py_version,
91+
msg='Needs a python version tuple')
9192
if not have_python_version(self.py_version):
9293
py_version_str = ".".join(map(str, self.py_version))
9394
self.skipTest(f'Python {py_version_str} not available')
@@ -100,23 +101,21 @@ def setUp(self):
100101

101102
def tearDown(self):
102103
# Set the highest protocol back to the default.
103-
pickletester.protocols = range(pickle.HIGHEST_PROTOCOL + 1)
104104
pickle.HIGHEST_PROTOCOL = self._OLD_HIGHEST_PROTOCOL
105+
pickletester.protocols = range(pickle.HIGHEST_PROTOCOL + 1)
105106

106-
def send_to_worker(self, python, obj, proto, **kwargs):
107+
@staticmethod
108+
def send_to_worker(python, data):
107109
"""Bounce a pickled object through another version of Python.
108-
This will pickle the object, send it to a child process where it will
110+
This will send data to a child process where it will
109111
be unpickled, then repickled and sent back to the parent process.
110112
Args:
111113
python: list containing the python binary to start and its arguments
112-
obj: object to pickle.
113-
proto: pickle protocol number to use.
114-
kwargs: other keyword arguments to pass into pickle.dumps()
114+
data: bytes object to send to the child process
115115
Returns:
116116
The pickled data received from the child process.
117117
"""
118118
target = pathlib.Path(__file__).parent / 'xpickle_worker.py'
119-
data = super().dumps((proto, obj), proto, **kwargs)
120119
worker = subprocess.Popen([*python, target],
121120
stdin=subprocess.PIPE,
122121
stdout=subprocess.PIPE,
@@ -145,8 +144,9 @@ def dumps(self, arg, proto=0, **kwargs):
145144
# it works in a different Python version.
146145
if 'buffer_callback' in kwargs:
147146
self.skipTest('Test does not support "buffer_callback" argument.')
147+
data = super().dumps((proto, arg), proto, **kwargs)
148148
python = py_executable_map[self.py_version]
149-
return self.send_to_worker(python, arg, proto, **kwargs)
149+
return self.send_to_worker(python, data)
150150

151151
def loads(self, *args, **kwargs):
152152
return super().loads(*args, **kwargs)

0 commit comments

Comments
 (0)