Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/cloudpickle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3180,5 +3180,23 @@ def test_module_level_pickler():
assert cloudpickle.Pickler is cloudpickle.CloudPickler


def test_is_tornado_coroutine_without_tornado_gen(monkeypatch):
# is_tornado_coroutine returns False when tornado.gen was never
# imported. See https://github.com/cloudpipe/cloudpickle/issues/346
monkeypatch.delitem(sys.modules, "tornado.gen", raising=False)
with pytest.warns(DeprecationWarning, match="deprecated"):
assert cloudpickle.is_tornado_coroutine(lambda: None) is False


def test_is_tornado_coroutine_with_old_tornado(monkeypatch):
# Simulate a Tornado version too old to provide
# tornado.gen.is_coroutine_function.
# See https://github.com/cloudpipe/cloudpickle/issues/346
stub_gen = types.ModuleType("tornado.gen")
monkeypatch.setitem(sys.modules, "tornado.gen", stub_gen)
with pytest.warns(DeprecationWarning, match="deprecated"):
assert cloudpickle.is_tornado_coroutine(lambda: None) is False


if __name__ == "__main__":
unittest.main()
23 changes: 23 additions & 0 deletions tests/test_backward_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import pickle

import pytest
import cloudpickle

from .generate_old_pickles import PICKLE_DIRECTORY

Expand Down Expand Up @@ -93,3 +94,25 @@ def test_complex_function():
def test_nested_function():
f = load_obj("nested_function.pkl")
assert f(41) == 42


def test_cloudpickle_fast_forwards_public_names():
# cloudpickle_fast is a compatibility shim for pickles generated by
# previous cloudpickle versions: attribute access is forwarded to
# cloudpickle.cloudpickle through __getattr__ (PEP 562).
# See https://github.com/cloudpipe/cloudpickle/issues/346
from cloudpickle import cloudpickle_fast

assert cloudpickle_fast.CloudPickler is cloudpickle.CloudPickler
assert cloudpickle_fast.Pickler is cloudpickle.Pickler
assert cloudpickle_fast.dumps is cloudpickle.dumps
assert cloudpickle_fast.loads is cloudpickle.loads


def test_cloudpickle_fast_unknown_attribute_raises_attribute_error():
from cloudpickle import cloudpickle_fast

with pytest.raises(AttributeError):
# Accessing a missing attribute is the point: it exercises
# cloudpickle_fast.__getattr__.
cloudpickle_fast.this_attribute_does_not_exist # noqa: B018