
    BThK                        d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ d dlmZ d dl	Z	ddl
mZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddlm!Z! ddlm"Z" ddlm#Z# ddlm$Z$ d Z%d5dZ&d5dZ'd5dZ(d5d Z)d! Z*d" Z+d# Z,d$ Z-d% Z. e	j^                  d&'      d(        Z0d) Z1d* Z2d+ Z3d, Z4d- Z5d. Z6e	j                  d/        Z7e	j                  d0        Z8d1 Z9 e	j^                  d&'      d2        Z: e	j^                  d&3      d4        Z;y)6    N)defaultdict)datetime)timezone   )__version__)BenchmarkFixture)BenchmarkSession)PerformanceRegression)default_timer)NameWrapper)consistent_dumps)get_commit_infoget_current_time)get_tag)operations_unit)parse_columns)parse_compare_fail)parse_cprofile_loops)parse_name_format)parse_rounds)
parse_save)parse_seconds)
parse_sort)parse_timer)parse_warmup)	time_unitc                     | j                   }dj                  |j                  t        |j                  j	                  d            S )Nzbenchmark: {version} (defaults: timer={timer} disable_gc={0[disable_gc]} min_rounds={0[min_rounds]} min_time={0[min_time]} max_time={0[max_time]} calibration_precision={0[calibration_precision]} warmup={0[warmup]} warmup_iterations={0[warmup_iterations]})timer)versionr   )_benchmarksessionformatoptionsr   getconfigbss     i/var/www/catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/pytest_benchmark/plugin.pypytest_report_headerr)   $   sB    		!	!B		 f


jjnnW%      c                      | d| ddt         dd        | d| ddd	d
        | d| ddt        g dd        | d| ddt        dd       y )N--sortCOLminzjColumn to sort on. Can be one of: 'min', 'max', 'mean', 'stddev', 'name', 'fullname'. Default: %(default)rmetavartypedefaulthelpzgroup-byLABELgroupzHow to group tests. Can be one of: 'group', 'name', 'fullname', 'func', 'fullfunc', 'param' or 'param:NAME', where NAME is the name passed to @pytest.parametrize. Default: %(default)rr1   r3   r4   columnsLABELS)
r/   maxmeanstddevmedianiqroutliersopsrounds
iterationszComma-separated list of columns to show in the result table. Default: 'min, max, mean, stddev, median, iqr, outliers, ops, rounds, iterations'nameFORMATnormalziHow to format names in results. Can be one of 'short', 'normal', 'long', or 'trial'. Default: %(default)r)r   r   r   	addoptionprefixs     r(   add_display_optionsrI   9   s    
VHD| 
VHH 	 
VHGlS 
VHDxr*   c           
      J    dt                } | d| ddddg |d|       y )	N
benchmark_r,   	histogramappendFILENAME-PREFIX?zPlot graphs of min/max/avg/stddev over time in FILENAME-PREFIX-test_name.svg. If FILENAME-PREFIX contains slashes ('/') then directories will be created. Default: actionr1   nargsr3   constr4   r   rG   rH   filename_prefixs      r(   add_histogram_optionsrV   Z   sH    "#3#5"67O
VHI!EETDWY	r*   c           
      J    dt                } | d| ddddg |d|       y )	NrK   r,   csvrM   FILENAMErO   zaSave a csv report. If FILENAME contains slashes ('/') then directories will be created. Default: rP   r   rT   s      r(   add_csv_optionsrZ   h   sM    "#3#5"67O
VHCs  uD  tG  Hr*   c                      | d| dg|rg ndgdddd  | d| dd	d
dd        | d| dg|rg ndgdddd  | d| dg|rg ndgdddd |s | ddg ddd       y y )Nr,   storagez-sURIzfile://./.benchmarksa&  Specify a path to store the runs as uri in form file://path or elasticsearch+http[s]://host1,host2/[index/doctype?project_name=Project] (when --benchmark-save or --benchmark-autosave are used). For backwards compatibility unexpected values are converted to file://<value>. Default: %(default)r.r7   netrcrO    z~/.netrczGLoad elasticsearch credentials from a netrc file. Default: %(default)r.)rR   r3   rS   r4   verbosez-v
store_trueFz)Dump diagnostic and progress information.rQ   r3   r4   quietz-qz1Disable reporting. Verbose mode takes precedence.z--import-modeprepend)rd   rM   	importlib
importmodezaHow to attempt loading hooks from conftest. Akin to pytest's --import-mode. Default: %(default)r.)r3   choicesdestr4    rF   s     r(   add_global_optionsrj   u   s    
VHG	D6	 &A	 
VHEV 
VHGD6 8 
VHED6 @ 6t	
 r*   c           
         | j                  d      }|j                  ddt        dd       |j                  ddt        dd	       |j                  d
dt        dd       |j                  ddt        t        t        t                    d       |j                  ddt        dd       |j                  dddt        d      t        d       |j                  ddt        dd       |j                  dddd !       |j                  d"ddd#!       |j                  d$ddd%!       |j                  d&ddd'!       |j                  d(ddd)!       |j                  d*d+t        d,-       t               }|j                  d.d/|d0| d12       |j                  d3dd45       |j                  d6d7t        j                  d8      d9-       |j                  d:d;dg d<d=>       |j                  d?d@dAt        dBC       |j                  dDdEd g dFdGH       |j                  dIdJdKt        dLM       |j                  dNdOdPt        dQM       dRt!                }|j                  dSdTdUdg |dV|W       |j                  dXdEd g dYdZH       t#        |j                         t%        |j                         t'        |j                         y )[N	benchmarkz--benchmark-min-timeSECONDSz0.000005z7Minimum time per round in seconds. Default: %(default)rr0   z--benchmark-max-timez1.0zMaximum run time per test - it will be repeated until this total time is reached. It may be exceeded if test function is very slow or --benchmark-min-rounds is large (it takes precedence). Default: %(default)rz--benchmark-min-roundsNUM   zRMinimum rounds, even if total time would exceed `--max-time`. Default: %(default)rz--benchmark-timerFUNCz6Timer to use when measuring time. Default: %(default)rz!--benchmark-calibration-precision
   zPrecision to use when calibrating number of iterations. Precision of 10 will make the timer look 10 times more accurate, at a cost of less precise measure of deviations. Default: %(default)rz--benchmark-warmupKINDrO   autoa  Activates warmup. Will run the test function up to number of times in the calibration phase. See `--benchmark-warmup-iterations`. Note: Even the warmup phase obeys --benchmark-max-time. Available KIND: 'auto', 'off', 'on'. Default: 'auto' (automatically activate on PyPy).)r1   rR   r3   r2   r4   z--benchmark-warmup-iterationsi zIMax number of iterations to run in the warmup phase. Default: %(default)rz--benchmark-disable-gcra   FzDisable GC during benchmarks.rb   z--benchmark-skipz/Skip running any tests that contain benchmarks.z--benchmark-disablezDisable benchmarks. Benchmarked functions are only ran once and no stats are reported. Use this is you want to run the test but don't do any benchmarking.z--benchmark-enablezzForcibly enable benchmarks. Use this option to override --benchmark-disable (in case you have it in pytest configuration).z--benchmark-onlyz5Only run benchmarks. This overrides --benchmark-skip.z--benchmark-saveNAMEz;Save the current run into 'STORAGE-PATH/counter_NAME.json'.)r1   r2   r4   z--benchmark-autosavestore_constz4Autosave the current run into 'STORAGE-PATH/counter_z.json)rQ   rS   r4   z--benchmark-save-datazkUse this to make --benchmark-save and --benchmark-autosave include all the timing data, not just the stats.)rQ   r4   z--benchmark-jsonPATHwbzrDump a JSON report into PATH. Note that this will include the complete data (all the timings, not just the stats).z--benchmark-comparezNUM|_IDTzsCompare the current run against run NUM (or prefix of _id in elasticsearch) or the latest saved run if unspecified.)r1   rR   r3   rS   r4   z--benchmark-compare-failEXPR+zFail test if performance regresses according to given EXPR (eg: min:5%% or mean:0.001 for number of seconds). Can be used multiple times.)r1   rR   r2   r4   z--benchmark-cprofileCOLUMN)ncalls_recursionncallstottimetottime_percumtimecumtime_perfunction_namezIf specified cProfile will be enabled. Top functions will be stored for the given column. Available columns: 'ncalls_recursion', 'ncalls', 'tottime', 'tottime_per', 'cumtime', 'cumtime_per', 'function_name'.)r1   r3   rg   r4   z--benchmark-cprofile-loopsLOOPSr   zZHow many times to run the function in cprofile. Available options: 'auto', or an integer. )r1   r3   r2   r4   z--benchmark-cprofile-topCOUNT   zHow many rows to display.rK   z--benchmark-cprofile-dumprM   rN   zSave cprofile dumps as FILENAME-PREFIX-test_name.prof. If FILENAME-PREFIX contains slashes ('/') then directories will be created. Default: rP   z--benchmark-time-unit)nsusmssrs   zVUnit to scale the results to. Available units: 'ns', 'us', 'ms', 's'. Default: 'auto'.)getgrouprG   r   r   r   strr   r   intr   r   r   argparseFileTyper   r   r   rj   rI   rV   )parserr6   tagcprofile_dump_prefixs       r(   pytest_addoptionr      s   OOK(E	OOF   
OO   
OO a   
OOK./E   
OO+`   
OOV$a  	 
OO'X   
OO,\5WvOw	OO&|U  RCO  D	OO>	   
OO!	   
OO&|U  RIO  J	OO&Z  OLO  M
)C	OOCC5N	   
OO}  
 
OOt$ E	   
OO F   
OO"Z   
OOsm   
OO$!i   
OO"(   ((8(:';<	OO#!"EEYD\^  	 
OO/e   u'(%//*r*   c                 V    ddl m} t        | dd       }|| j                  } ||       y )Nr   )hookspecadd_hookspecs)r_   r   getattraddhooks)pluginmanagerr   methods      r(   pytest_addhooksr   9  s+    ]OT:F~''
8r*   c           	          t        |      }t        |d         }||k7  r:|j                  j                  d| d| d|j                  j                   d       y y )Nmachine_infoz.Benchmark machine_info is different. Current: z VS saved: z (location: z).)r   loggerwarningr\   location)r&   benchmarksessionr   compared_benchmarkcompared_machine_infos        r(   %pytest_benchmark_compare_machine_infor   B  s    #L1L,-?-OP,''<\N+VkUllx  zJ  zR  zR  z[  z[  y\  \^  _	
 -r*   c                 `   | j                   }t        j                  j                  d      }t        j                  j                  d      }|D ]]  }t	        |d      xr d|j
                  v }|r|j                  s.|j                  |       @|j                  sM|j                  |       _ y )Nz-Skipping benchmark (--benchmark-skip active).)reasonz1Skipping non-benchmark (--benchmark-only active).fixturenamesrl   )r!   pytestmarkskiphasattrr   
add_markeronly)r&   itemsr'   
skip_bench
skip_otheritemhas_benchmarks          r(   pytest_collection_modifyitemsr   L  s    		!	!B!!)X!YJ!!)\!]J ,n5Z+IZIZ:Zww
+ww
+,r*   c                    t        t              }|D ]  }d}|j                  d      D ]  }|dk(  r
||d   fz  }|dk(  r
||d   fz  }!|dk(  r||d   j                  d      d   fz  }B|dk(  r
||d   fz  }Q|d	k(  r||d   j                  d      d   fz  }r|d
k(  r
||d
   fz  }|j                  d      r+|t	        d      d  }|dj                  ||d   |         fz  }t        d|d       |dj                  d |D              xs d    j                  |        |j                         D ]-  }|j                  t        j                  d|v rdnd             / t        |j                         d       S )Nri   ,r6   rC   func[r   fullnamefullfuncparamzparam:z{}={}paramszUnsupported grouping . c              3   8   K   | ]  }|st        |        y wN)r   ).0ps     r(   	<genexpr>z/pytest_benchmark_group_stats.<locals>.<genexpr>p  s     11qA1s   full)keyc                     | d   xs dS )Nr   r_   ri   )pairs    r(   <lambda>z.pytest_benchmark_group_stats.<locals>.<lambda>t  s    47=b r*   )r   listsplit
startswithlenr"   NotImplementedErrorjoinrM   valuesr-   operator
itemgettersortedr   )	r&   
benchmarksgroup_bygroupsbenchr   grouping
param_namegrouped_benchmarkss	            r(   pytest_benchmark_group_statsr   Z  s   F I s+ 	QH7"g((V#f''V#f++C0355Z'j)++Z'j)//4Q799W$g(($$X.%c(mo6
z5?:3NOQQ),A(Q*OPP#	Q$ 	sxx1119T:AA%H)I, %mmo gH$7$7fPXFX
^d$efg&,,.&@AAr*   T)hookwrapperc              #   \   K   | j                   j                  j                          d  y wr   )r&   r!   finish)session
exitstatuss     r(   pytest_sessionfinishr   w  s     NN$$++-	s   *,c                    	 | j                   j                  j                  |        y # t        $ r  t        $ rF | j                   j                  j
                  j                  dt        j                                  w xY w)N
)	r&   r!   displayr
   	Exceptionr   error	traceback
format_exc)terminalreporters    r(   pytest_terminal_summaryr   }  sp    1199:JK   1188>>IDXDXDZC[?\]s
   %( AB c                  2    dd l } | j                         xs i S )Nr   )cpuinfoget_cpu_info)r   s    r(   r   r     s    !'R'r*   c                 .   | r| j                  dd       nd }|dk(  ry|dk(  ry|dk(  ry|dk(  ry	|d
v sJ |dk(  r)|}|dv rd}t        |j                  ||d   |               S |dk(  r!t        |j                  d|d   d               S t	        d|      )Nbenchmark_time_unitr   )ng    eAr   )ug    .Ar   )mg     @@r   )r_   g      ?)rs   Nseconds)rC   r   r/   r   
operationsr@   zUnexpected measurement unit )	getoptionr   r$   r   RuntimeError)r&   unitr   bestworstr-   config_time_unittime_unit_keys           r(   pytest_benchmark_scale_unitr     s    HNv''(=tDTX4	T	!	T	!	S	 ~---y''!M$
1m(DEFF		uyy
1e0DEFF9$BCCr*   c                  @   t        j                         } t        j                         }| dk(  rLdt        j                  d d z  }t        j                  j
                  dk7  r|dt        j                  dd  z  z  }t        j                         t        j                         t        j                         t        j                         | |t        j                         t        j                         t        j                         t        j                         t               dS )NPyPyz%d.%d.%d   finalz-%s%d)node	processormachinepython_compilerpython_implementationpython_implementation_versionpython_versionpython_buildreleasesystemcpu)platformr  r  syspypy_version_inforeleaselevelr   r   r   r   r  r  r  r   )r  r  s     r(   &pytest_benchmark_generate_machine_infor    s    $::<$,$;$;$=!&(2S5J5J2A5N(N%  --8)Ws7L7LQR7P-PP)'')##%#335!6)F"113 --/##%//#~ r*   c                 8    t        | j                  dd             S )Nbenchmark_project_name)r   r   )r&   s    r(   %pytest_benchmark_generate_commit_infor    s    6++,DdKLLr*   c                     g }|||t        j                  t        j                        j	                         t
        d}|D ]0  }|j                  r|j                  |j                  |             2 |S )N)r   commit_infor   r   r    )include_data)	r   nowr   utc	isoformatr   	has_errorrM   as_dict)r&   r   r  r   r  benchmarks_jsonoutput_jsonr   s           r(   pytest_benchmark_generate_jsonr    sn    O$"%LL.88:K  M""5==l=#KLM r*   c           	   #     K   | j                   j                  }|j                  rt        j                  d       y | j                  }|j                  d      }|rt        |j                        ni }d|v rt        |d         |d<   t        |f|j                  j                  |j                  | j                  j                  |j                  dt        |j                  fi |}| |j!                          y w)Nz3Benchmarks are skipped (--benchmark-skip was used).rl   r   )	add_statsr   warnerdisabled)r&   r!   r   r   r   get_closest_markerdictkwargsr   r   r   rM   r   warnr  r#   _cleanup)requestr'   r   markerr#   fixtures         r(   rl   rl     s     ">>;;B	wwIJ||((5<BT&--%8g*77+;<GG"
mm**99<<$$[[
 2::))
 s   C:C<c                     | j                   S r   )weave)rl   s    r(   benchmark_weaver)    s    ??r*   c                     | j                  d      }|r<|j                  rt        d      |j                  D ]  }|dvst        d|d       y y )Nrl   z/benchmark mark can't have positional arguments.)
max_time
min_roundsmin_timer   r6   
disable_gcwarmupwarmup_iterationscalibration_precisioncprofilezbenchmark mark can't have z keyword argument.)r  args
ValueErrorr!  )r   r%  rC   s      r(   pytest_runtest_setupr5    sg    $$[1F;;NOOMM 	ZD   !#=dXEW!XYY	Z r*   c              #      K   d }d }t        | d      r| j                  j                  d      }|t        |t              st        d|d      |r#|j                         j                  dk(  |_        y y w)Nfuncargsrl   z-unexpected type for `benchmark` in funcargs, z must be a BenchmarkFixture instance. You should not use other plugins that define a `benchmark` fixture, or return and unexpected value if you do redefine it.skipped)	r   r7  r$   
isinstancer   	TypeError
get_resultoutcomer8  )r   callr<  r&  s       r(   pytest_runtest_makereportr>    s     GGtZ --##K0:g7G#H;G; GH H
 	
 !,,.66)C s   A5A7)trylastc                     | j                  dd       t        |       x}| _        |j                          | j                  j                  |d       y )Nmarkersz6benchmark: mark a test with custom benchmark settings.zpytest-benchmark)addinivalue_liner	   r!   handle_loadingr   registerr%   s     r(   pytest_configurerE    sH    
I'_`$4V$<<B	!
!!"&89r*   )z
benchmark-)<r   r   r  r	  r   collectionsr   r   r   r   r_   r   r&  r   r   r	   r
   timersr   utilsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r)   rI   rV   rZ   rj   r   r   r   r   r   hookimplr   r   r   r   r  r  r  rl   r)  r5  r>  rE  ri   r*   r(   <module>rJ     sN      
  #     % % * !  # " #  "   % ' $        *B
'
TW+t
,B: T"
 #

(D,,M  .  Z* T"D #D : :r*   