mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
bpo-41180: Replace marshal code.__new__ audit event with marshal.load[s] and marshal.dumps (GH-26970)
This commit is contained in:
parent
2df13e1211
commit
a5764d3d96
5 changed files with 75 additions and 10 deletions
|
@ -6,6 +6,7 @@ module with arguments identifying each test.
|
|||
"""
|
||||
|
||||
import contextlib
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
|
@ -106,6 +107,32 @@ def test_block_add_hook_baseexception():
|
|||
pass
|
||||
|
||||
|
||||
def test_marshal():
|
||||
import marshal
|
||||
o = ("a", "b", "c", 1, 2, 3)
|
||||
payload = marshal.dumps(o)
|
||||
|
||||
with TestHook() as hook:
|
||||
assertEqual(o, marshal.loads(marshal.dumps(o)))
|
||||
|
||||
try:
|
||||
with open("test-marshal.bin", "wb") as f:
|
||||
marshal.dump(o, f)
|
||||
with open("test-marshal.bin", "rb") as f:
|
||||
assertEqual(o, marshal.load(f))
|
||||
finally:
|
||||
os.unlink("test-marshal.bin")
|
||||
|
||||
actual = [(a[0], a[1]) for e, a in hook.seen if e == "marshal.dumps"]
|
||||
assertSequenceEqual(actual, [(o, marshal.version)] * 2)
|
||||
|
||||
actual = [a[0] for e, a in hook.seen if e == "marshal.loads"]
|
||||
assertSequenceEqual(actual, [payload])
|
||||
|
||||
actual = [e for e, a in hook.seen if e == "marshal.load"]
|
||||
assertSequenceEqual(actual, ["marshal.load"])
|
||||
|
||||
|
||||
def test_pickle():
|
||||
import pickle
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue