Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update whichmodule tests in cloudpickle to work with numpy 2.2. #546

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Changes from 1 commit
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: 9 additions & 9 deletions tests/cloudpickle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,7 @@ def __getattr__(self, name):
try:
sys.modules["NonModuleObject"] = non_module_object

func_module_name = _whichmodule(func, None)
func_module_name = _whichmodule(func, "func")
assert func_module_name != "NonModuleObject"
assert func_module_name is None

Expand All @@ -1506,13 +1506,16 @@ def __getattr__(self, name):

def test_importing_multiprocessing_does_not_impact_whichmodule(self):
# non-regression test for #528
pytest.importorskip("numpy")
script = textwrap.dedent("""
import multiprocessing
import cloudpickle
from numpy import exp
from cloudpickle.cloudpickle import dumps

print(cloudpickle.cloudpickle._whichmodule(exp, exp.__name__))
# Trigger a loop during the execution of whichmodule() by
# explicitly setting the function's module to None
dumps.__module__ = None

print(cloudpickle.cloudpickle._whichmodule(dumps, dumps.__name__))
""")
script_path = Path(self.tmpdir) / "whichmodule_and_multiprocessing.py"
with open(script_path, mode="w") as f:
Expand All @@ -1524,11 +1527,8 @@ def test_importing_multiprocessing_does_not_impact_whichmodule(self):
stderr=subprocess.STDOUT,
)
out, _ = proc.communicate()
self.assertEqual(proc.wait(), 0)
assert out.strip() in (
b"numpy.core._multiarray_umath", # numpy 1
b"numpy._core._multiarray_umath", # numpy 2
)
self.assertEqual(proc.wait(), 0, msg="Stdout: " + str(out))
self.assertEqual(out.strip(), b"cloudpickle.cloudpickle")

def test_unrelated_faulty_module(self):
# Check that pickling a dynamically defined function or class does not
Expand Down