write tests for streamer

This commit is contained in:
bkfox
2023-06-12 14:09:06 +02:00
parent b586bc5309
commit 3d76b656d2
11 changed files with 254 additions and 41 deletions

View File

@ -0,0 +1,39 @@
import atexit as o_atexit
import subprocess as o_subprocess
import psutil as o_psutil
from . import atexit, subprocess, psutil
modules = [
(o_atexit, atexit, {}),
(o_subprocess, subprocess, {}),
(o_psutil, psutil, {}),
]
def init_mappings():
for original, spoof, mapping in modules:
if mapping:
continue
mapping.update(
{
attr: (getattr(original, attr, None), spoofed)
for attr, spoofed in vars(spoof).items()
if not attr.startswith("_") and hasattr(original, attr)
}
)
def setup():
for original, spoof, mappings in modules:
for attr, (orig, spoofed) in mappings.items():
setattr(original, attr, spoofed)
def setdown():
for original, spoof, mappings in modules:
for attr, (orig, spoofed) in mappings.items():
setattr(original, attr, orig)
init_mappings()