Skip to content

Commit

Permalink
Change test_pickle_globals to not check __globals__ directly
Browse files Browse the repository at this point in the history
Implementation taken from cloudpipe/cloudpickle#202 (comment)
  • Loading branch information
mrocklin committed Sep 14, 2018
1 parent 0910b41 commit 7f6c256
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions dask/tests/test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,23 @@

from dask import compute, delayed
from dask.context import set_options
from dask.multiprocessing import get, _dumps, _loads, remote_exception
from dask.multiprocessing import get, _dumps, remote_exception
from dask.utils_test import inc


def test_pickle_globals():
""" For the function f(x) defined below, the only globals added in pickling
should be 'np' and '__builtins__'"""
def f(x):
return np.sin(x) + np.cos(x)
def unrelated_function(a):
return np.array([a])

assert set(['np', '__builtins__']) == set(
_loads(_dumps(f)).__globals__.keys())
def my_small_function(a, b):
return a + b

b = _dumps(my_small_function)
assert b'my_small_function' in b
assert b'unrelated_function' not in b
assert b'numpy' not in b


def bad():
Expand Down

0 comments on commit 7f6c256

Please sign in to comment.