Skip to content

Commit

Permalink
Add test cases to make sure
Browse files Browse the repository at this point in the history
  • Loading branch information
HyukjinKwon committed Aug 5, 2017
1 parent 77b7ddc commit 4062d3a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/cloudpickle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,34 @@ def __init__(self, x):

self.assertEqual(set(weakset), set([depickled1, depickled2]))

def test_ignoring_whichmodule_exception(self):
class FakeModule(object):
def __getattr__(self, name):
# This throws an exception while looking up within
# pickle.whichimodule.
raise Exception()

class Foo(object):
__module__ = None

def foo(self):
return "it works!"

def foo():
return "it works!"

foo.__module__ = None

sys.modules["_fake_module"] = FakeModule()
try:
# Test whichmodule in save_global.
self.assertEqual(pickle_depickle(Foo()).foo(), "it works!")

# Test whichmodule in save_function.
self.assertEqual(pickle_depickle(foo)(), "it works!")
finally:
sys.modules.pop("_fake_module", None)


if __name__ == '__main__':
unittest.main()

0 comments on commit 4062d3a

Please sign in to comment.