Skip to content

Commit

Permalink
Import pickle from compat in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jakirkham committed May 21, 2020
1 parent ebaf7f6 commit 1d6abbd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion tests/cloudpickle_file_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import unicode_literals

import os
import pickle
import shutil
import sys
import tempfile
Expand All @@ -10,6 +9,7 @@
import pytest

import cloudpickle
from cloudpickle.compat import pickle


class CloudPickleFileTests(unittest.TestCase):
Expand Down
16 changes: 9 additions & 7 deletions tests/cloudpickle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import logging
import math
from operator import itemgetter, attrgetter
import pickle
import platform
import random
import shutil
Expand Down Expand Up @@ -43,6 +42,7 @@
tornado = None

import cloudpickle
from cloudpickle.compat import pickle
from cloudpickle.cloudpickle import _is_dynamic
from cloudpickle.cloudpickle import _make_empty_cell, cell_set
from cloudpickle.cloudpickle import _extract_class_dict, _whichmodule
Expand Down Expand Up @@ -519,7 +519,7 @@ def test_module_locals_behavior(self):
pickled_func_path = os.path.join(self.tmpdir, 'local_func_g.pkl')

child_process_script = '''
import pickle
from cloudpickle.compat import pickle
import gc
with open("{pickled_func_path}", 'rb') as f:
func = pickle.load(f)
Expand Down Expand Up @@ -604,7 +604,7 @@ def test_load_dynamic_module_in_grandchild_process(self):
child_process_module_file = os.path.join(
self.tmpdir, 'dynamic_module_from_child_process.pkl')
child_process_script = '''
import pickle
from cloudpickle.compat import pickle
import textwrap
import cloudpickle
Expand All @@ -624,7 +624,7 @@ def test_load_dynamic_module_in_grandchild_process(self):

# The script ran by the process created by the child process
child_of_child_process_script = """ '''
import pickle
from cloudpickle.compat import pickle
with open('{child_process_module_file}','rb') as fid:
mod = pickle.load(fid)
''' """
Expand Down Expand Up @@ -679,7 +679,7 @@ def my_small_function(x, y):
assert b'math' not in b

def test_is_dynamic_module(self):
import pickle # decouple this test from global imports
from cloudpickle.compat import pickle
import os.path
import distutils
import distutils.ccompiler
Expand Down Expand Up @@ -969,7 +969,8 @@ def example():

# choose "subprocess" rather than "multiprocessing" because the latter
# library uses fork to preserve the parent environment.
command = ("import pickle, base64; "
command = ("import base64; "
"from cloudpickle.compat import pickle; "
"pickle.loads(base64.b32decode('" +
base64.b32encode(s).decode('ascii') +
"'))()")
Expand All @@ -990,7 +991,8 @@ def example():

s = cloudpickle.dumps(example, protocol=self.protocol)

command = ("import pickle, base64; "
command = ("import base64; "
"from cloudpickle.compat import pickle; "
"pickle.loads(base64.b32decode('" +
base64.b32encode(s).decode('ascii') +
"'))()")
Expand Down
3 changes: 2 additions & 1 deletion tests/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import tempfile
import base64
from subprocess import Popen, check_output, PIPE, STDOUT, CalledProcessError
from pickle import loads
from cloudpickle.compat import pickle
from contextlib import contextmanager
from concurrent.futures import ProcessPoolExecutor

import psutil
from cloudpickle import dumps
from subprocess import TimeoutExpired

loads = pickle.loads
TIMEOUT = 60
TEST_GLOBALS = "a test value"

Expand Down

0 comments on commit 1d6abbd

Please sign in to comment.