forked from rc/aircox
		
	- Writes tests for aircox streamer application; - Add test utilities in aircox Co-authored-by: bkfox <thomas bkfox net> Reviewed-on: rc/aircox#110
		
			
				
	
	
		
			40 lines
		
	
	
		
			937 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			937 B
		
	
	
	
		
			Python
		
	
	
	
	
	
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()
 |