diff options
author | Steve Dower <steve.dower@python.org> | 2021-06-30 17:21:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-30 17:21:37 +0100 |
commit | 139de04518bd98a975b7c98ab8a38e570dc585e4 (patch) | |
tree | bd1b6f601221f24623dc618faf173bc7165f1cf0 /Lib/test/audit-tests.py | |
parent | 86eeeb425936ba67d79f32bfbd5c5f8002819438 (diff) | |
download | cpython-git-139de04518bd98a975b7c98ab8a38e570dc585e4.tar.gz |
bpo-41180: Replace marshal code.__new__ audit event with marshal.load[s] and marshal.dumps (GH-26961)
Diffstat (limited to 'Lib/test/audit-tests.py')
-rw-r--r-- | Lib/test/audit-tests.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/audit-tests.py b/Lib/test/audit-tests.py index 7a7de637c3..ccec9fedc4 100644 --- a/Lib/test/audit-tests.py +++ b/Lib/test/audit-tests.py @@ -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 |