2022-07-31 10:00:45 +00:00
|
|
|
from pytest_pyodide import run_in_pyodide
|
2021-01-13 11:07:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
@run_in_pyodide(packages=["cloudpickle"])
|
2022-05-26 02:47:43 +00:00
|
|
|
def test_cloudpickle(selenium):
|
2021-01-13 11:07:50 +00:00
|
|
|
import cloudpickle
|
|
|
|
|
2022-02-10 08:36:18 +00:00
|
|
|
squared = lambda x: x**2
|
2021-01-13 11:07:50 +00:00
|
|
|
pickled_lambda = cloudpickle.dumps(squared)
|
|
|
|
|
|
|
|
import pickle
|
|
|
|
|
|
|
|
new_squared = pickle.loads(pickled_lambda)
|
|
|
|
assert new_squared(2) == 4
|
|
|
|
|
|
|
|
CONSTANT = 42
|
|
|
|
|
|
|
|
def my_function(data: int) -> int:
|
|
|
|
return data + CONSTANT
|
|
|
|
|
|
|
|
pickled_function = cloudpickle.dumps(my_function)
|
|
|
|
depickled_function = pickle.loads(pickled_function)
|
|
|
|
assert depickled_function(43) == 85
|