MCPcopy
hub / github.com/cloudpipe/cloudpickle / test_submodule

Method test_submodule

tests/cloudpickle_test.py:1080–1104  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1078 self.assertEqual(f2(), res)
1079
1080 def test_submodule(self):
1081 # Function that refers (by attribute) to a sub-module of a package.
1082
1083 # Choose any module NOT imported by __init__ of its parent package
1084 # examples in standard library include:
1085 # http.cookies, unittest.mock, curses.textpad, xml.etree.ElementTree
1086 import xml
1087 import xml.etree.ElementTree
1088
1089 def example():
1090 _ = xml.etree.ElementTree.Comment # noqa: F821
1091
1092 example() # smoke test
1093
1094 s = cloudpickle.dumps(example, protocol=self.protocol)
1095
1096 # refresh the environment, i.e., unimport the dependency
1097 del xml
1098 for item in list(sys.modules):
1099 if item.split(".")[0] == "xml":
1100 del sys.modules[item]
1101
1102 # deserialise
1103 f = pickle.loads(s)
1104 f() # smoke test
1105
1106 def test_submodule_closure(self):
1107 # Same as test_submodule except the xml package has not been imported

Callers

nothing calls this directly

Calls 1

fFunction · 0.85

Tested by

no test coverage detected