MCPcopy Index your code
hub / github.com/python/cpython / test_custom_invalid_serializer

Method test_custom_invalid_serializer

Lib/test/test_shelve.py:228–246  ·  view source on GitHub ↗
(self, serialized)

Source from the content-addressed store, hash-verified

226
227 @subTests("serialized", [None, ["invalid type"]])
228 def test_custom_invalid_serializer(self, serialized):
229 test_dir = f"{self.dirname}_{id(serialized)}"
230 os.mkdir(test_dir)
231 self.addCleanup(os_helper.rmtree, test_dir)
232 test_fn = os.path.join(test_dir, "shelftemp.db")
233
234 def serializer(obj, protocol=None):
235 return serialized
236
237 def deserializer(data):
238 return data.decode("utf-8")
239
240 # Since the serializer returns an invalid type or None,
241 # dbm.error is raised by dbm.sqlite3 and TypeError is raised
242 # by other backends.
243 with self.assertRaises((TypeError, dbm.error)):
244 with shelve.open(test_fn, serializer=serializer,
245 deserializer=deserializer) as s:
246 s["foo"] = "bar"
247
248 def test_custom_incomplete_deserializer(self):
249 os.mkdir(self.dirname)

Callers

nothing calls this directly

Calls 6

addCleanupMethod · 0.95
assertRaisesMethod · 0.95
idFunction · 0.85
mkdirMethod · 0.45
joinMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected