Beispiel #1
0
def test_serializability():
    state = da.random.RandomState(5)
    x = state.normal(10, 1, size=10, chunks=5)

    y = _loads(_dumps(x))

    assert (x.compute() == y.compute()).all()
Beispiel #2
0
def test_serializability():
    state = da.random.RandomState(5)
    x = state.normal(10, 1, size=10, chunks=5)

    y = _loads(_dumps(x))

    assert_eq(x, y)
Beispiel #3
0
def test_serializability():
    state = da.random.RandomState(5)
    x = state.normal(10, 1, size=10, chunks=5)

    y = _loads(_dumps(x))

    assert (x.compute() == y.compute()).all()
Beispiel #4
0
def test_serializability():
    state = da.random.RandomState(5)
    x = state.normal(10, 1, size=10, chunks=5)

    y = _loads(_dumps(x))

    assert_eq(x, y)
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)

    assert set(["np", "__builtins__"]) == set(_loads(_dumps(f)).__globals__.keys())
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)

    assert set(['np',
                '__builtins__']) == set(_loads(_dumps(f)).__globals__.keys())
def test_pickle_globals():
    """ Unrelated globals should not be included in serialized bytes """
    def unrelated_function(a):
        return np.array([a])

    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 test_pickle_globals():
    """ Unrelated globals should not be included in serialized bytes """
    def unrelated_function(a):
        return np.array([a])

    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 test_pickle_kwargs():
    """Test that out-of-band pickling works

    Note cloudpickle does not support this argument:

    https://github.com/cloudpipe/cloudpickle/issues/213
    """
    b = _dumps(my_small_function_global, fix_imports=True)
    assert b"my_small_function_global" in b
    assert b"unrelated_function_global" not in b
    assert b"numpy" not in b
    my_small_function_global_2 = _loads(b, fix_imports=True)
    assert my_small_function_global_2(2, 3) == 5
Beispiel #10
0
def test_out_of_band_pickling():
    """Test that out-of-band pickling works"""
    np = pytest.importorskip("numpy")

    a = np.arange(5)

    l = []
    b = _dumps(a, buffer_callback=l.append)
    assert len(l) == 1
    assert isinstance(l[0], pickle.PickleBuffer)
    assert memoryview(l[0]) == memoryview(a)

    a2 = _loads(b, buffers=l)
    assert np.all(a == a2)
Beispiel #11
0
def test_pickle_locals():
    """Unrelated locals should not be included in serialized bytes"""
    np = pytest.importorskip("numpy")

    def unrelated_function_local(a):
        return np.array([a])

    def my_small_function_local(a, b):
        return a + b

    b = _dumps(my_small_function_local)
    assert b"my_small_function_global" not in b
    assert b"my_small_function_local" in b
    assert b"unrelated_function_local" not in b
Beispiel #12
0
def test_out_of_band_pickling():
    """Test that out-of-band pickling works"""
    if has_cloudpickle:
        if cloudpickle.__version__ < LooseVersion("1.3.0"):
            pytest.skip("when using cloudpickle, it must be version 1.3.0+")

    a = np.arange(5)

    l = []
    b = _dumps(a, buffer_callback=l.append)
    assert len(l) == 1
    assert isinstance(l[0], pickle.PickleBuffer)
    assert memoryview(l[0]) == memoryview(a)

    a2 = _loads(b, buffers=l)
    assert np.all(a == a2)
Beispiel #13
0
def test_pickle_globals():
    """ Unrelated globals should not be included in serialized bytes """
    b = _dumps(my_small_function_global)
    assert b"my_small_function_global" in b
    assert b"unrelated_function_global" not in b
    assert b"numpy" not in b