a #e @s>ddlZddlZddlmZedZGdddZeZdS)N)settingsz app.loggerc@seZdZddZddZddZd$dd Zd d Zd d ZddZ ddZ ddZ ddZ d%ddZ ddZddZddZd d!Zd"d#ZdS)& TestWatchcCs |dSN)clearselfr/webodm/app/testwatch.py__init__ szTestWatch.__init__cCsd|j|jS)Nz{}.{})format __module____name__)frrr func_to_name szTestWatch.func_to_namecCsi|_i|_dSr)_calls_intercept_listrrrr rszTestWatch.clearNcCs|dur |nd|j|<dS)NTr)rfnamerrrr interceptszTestWatch.interceptcCs ||jvSrrrrrrr intercept_list_hasszTestWatch.intercept_list_hascOs0||r,t|j|r,|j||i|dSr)rcallabler)rrargskwargsrrr &execute_intercept_function_replacementsz0TestWatch.execute_intercept_function_replacementcCs||jvr|j|SgSrrrrrr get_callsszTestWatch.get_callscCs||j|<dSrr)rrvaluerrr set_calls szTestWatch.set_callscCs|t|Sr)rrr)rfuncrrr should_prevent_execution#sz"TestWatch.should_prevent_executioncCst||Sr)lenrrrrr get_calls_count&szTestWatch.get_calls_countcCsZd}||}d}|||kr:||kr:t||d7}q||krPtd|||S)Ng?rr#z,wait_until_call has timed out waiting for {})r"timesleep TimeoutErrorr r)rrcounttimeoutZSLEEP_INTERVALZ TIMEOUT_LIMITcrrr wait_until_call)s  zTestWatch.wait_until_callcOs&t|}|j|g|Ri|dSr)rrmanual_log_callrrrrrrrr log_call6s zTestWatch.log_callcOs2tjr.||}||||d|||dS)N)rrr)rTESTINGrappendr)rrrrlistrrr r,:s zTestWatch.manual_log_callcOs`tjr\||r\t|}t|d|j|g|Ri||j|g|Ri|dSdS)Nz interceptedTF) rr/r rrloggerinforr.r-rrr hook_pre@s zTestWatch.hook_precOs"tjr|j|g|Ri|dSr)rr/r.)rrrrrrr hook_postIszTestWatch.hook_postc s|dtfdd}|S)z9 Decorator that adds pre/post hook calls testWatchcsfdd}|S)NcsFjg|Ri|rdS|i|}jg|Ri||Sr)r4r5)rrret)rtwrr wrapperSsz/TestWatch.watch..outer..wrapperr)rr9r8)rr outerRszTestWatch.watch..outer)getr6)rr;rr:r watchMs  zTestWatch.watch)N)r#r$)r r __qualname__r rrrrrrrr r"r+r.r,r4r5r=rrrr rs    r)r%loggingwebodmr getLoggerr2rr6rrrr s   S