
    BTho                     ^   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Z G d de j6                        Z G d de j:                        Zd Zd Z  G d d      Z!d Z" G d d      Z#y)    N)partial)pathlib)TerminalWriter)locate_config)
CSVResults   )plugin)Logger)add_csv_options)add_display_options)add_global_options)add_histogram_options)TableResults)NAME_FORMATTERS)first_or_value)load_storage)report_noprogressa  examples:

    pytest-benchmark {0} 'Linux-CPython-3.5-64bit/*'

        Loads all benchmarks ran with that interpreter. Note the special quoting that disables your shell's glob
        expansion.

    pytest-benchmark {0} 0001

        Loads first run from all the interpreters.

    pytest-benchmark {0} /foo/bar/0001_abc.json /lorem/ipsum/0001_sir_dolor.json

        Loads runs from exactly those files.c                       e Zd ZddZy)
HelpActionNc                     |rt               j                  |dg       n|j                          |j                          y )N--help)make_parser
parse_args
print_helpexit)selfparser	namespacevaluesoption_strings        f/var/www/catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/pytest_benchmark/cli.py__call__zHelpAction.__call__'   s/    M$$fh%78    N)__name__
__module____qualname__r"    r#   r!   r   r   &   s    r#   r   c                   ,     e Zd ZdZdZ fdZd Z xZS )CommandArgumentParserNc                     d|d<   t        |   |dt        j                  i| | j	                  ddddt
        d	       | j                  d
d      }|j	                  ddt
               y )NFadd_helpformatter_classz-hr   COMMAND?zDisplay help and exit.)metavarnargsactionhelpr3   descriptioncommand)r1   r2   )super__init__argparseRawDescriptionHelpFormatteradd_argumentr   add_command)r   argskwargshelp_command	__class__s       r!   r8   zCommandArgumentParser.__init__3   sr    "z$_0T0T_X^_$)3z`xy''<T'U!!)3z!Jr#   c                    | j                   .| j                  ddt        j                        | _         i | _        d|v rd|vr|d   |d<    | j                   j
                  |fdt        j                  i|}|| j                  |<   |S )Ncommandsr6   )titledestparser_classr5   r3   r-   )rB   add_subparsersr9   ArgumentParsercommands_dispatch
add_parserr:   )r   nameoptsr6   s       r!   r<   z!CommandArgumentParser.add_command;   s    ==  // %44 0 DM
 &(D"D V4%7.DL*$--**4nAeAenimn'.t$r#   )r%   r&   r'   rB   rH   r8   r<   __classcell__)r@   s   @r!   r*   r*   /   s    HKr#   r*   c                      | ddd       y )Nglob_or_file*zHGlob or exact path for json files. If not specified all runs are loaded.)r1   r3   r(   )	addoptions    r!   add_glob_or_filerQ   K   s    nC.xyr#   c                  P   t        dd      } t        | j                  d       | j                  dd       | j                  dd	d
      }t	        |j                  d       t        |j                  d       t        |j                         t        |j                  d       | S )Nzpy.test-benchmarkz'pytest_benchmark's management commands.r4    )prefixlistzList saved runs.comparezCompare saved runs.a  examples:

    pytest-benchmark compare 'Linux-CPython-3.5-64bit/*'

        Loads all benchmarks ran with that interpreter. Note the special quoting that disables your shell's glob
        expansion.

    pytest-benchmark compare 0001

        Loads first run from all the interpreters.

    pytest-benchmark compare /foo/bar/0001_abc.json /lorem/ipsum/0001_sir_dolor.json

        Loads runs from exactly those files.)r5   epilog)r*   r   r;   r<   r   r   rQ   r   )r   compare_commands     r!   r   r   O   s    "#6DmnFv**26
v+=>(()0 ) O$ 44R@/66rB_112O00<Mr#   c                       e Zd Zd Zd Zy)HookDispatchc          
          t        |d      \  }}}t        j                  d      }|j                         r9t        j                  |fi ||t        |j                  d            d| _        y d | _        y )Nr(   )invocation_dirr=   zconftest.pyconsider_namespace_packages)rootr]   )r   r   Pathexistsimport_pathboolgetconftest)r   r^   r>   _configconftest_files         r!   r8   zHookDispatch.__init__p   sp    $DrB1f]3!#// ,0<Y1Z,[	DM !DMr#   c                 P    t        t        |      }t        | j                  ||      S r$   )getattrr	   rd   )r   itemdefaults      r!   __getattr__zHookDispatch.__getattr__}   s!    &$'t}}dG44r#   N)r%   r&   r'   r8   rl   r(   r#   r!   rZ   rZ   o   s    !5r#   rZ   c                     t               } | j                         }|j                  rt        j                  nt        j
                  }|j                  rt        j                  }t        |      }t        |j                  ||j                        }t        |j                  t        j                  d            }|j                  dk(  r!|j!                         D ]  }t#        |        y |j                  dk(  rt%        |j&                  |j(                  t+        |j,                  d      t.        |j0                     |t3        |j4                  d             }|j7                   |j8                  |j:                   |j<                  d 	      }|j?                  tA               |tB        
       |jD                  rBtG        |j&                  |j(                  |      }	|jD                  \  }
|	jI                  |
|       y y |j                  R| jK                  djM                  djO                  tQ        tR        | jT                  jV                                           y | jK                  d|j                         y )N)loggernetrc.)moder^   rU   rV   F)rf   )columnssort	histogramname_formatrn   
scale_unit)
benchmarksgroup_byrf   )progress_reporterz(missing command (available commands: {})z, zunexpected command ),r   r   quietr
   QUIETNORMALverboseVERBOSEr   storagero   rZ   
importmoder   r_   r6   queryprintr   rr   rs   r   rt   r   rJ   r   pytest_benchmark_scale_unitpytest_benchmark_group_statsload_benchmarksrN   rx   displayTerminalReporterr   csvr   rendererrorformatjoinmapreprrB   choices)r   r=   levelrn   r   hookfileresults_tablegroupsresults_csvoutput_files              r!   mainr      s   ]FD JJFLLFMME||E]F4<<djjIGT__7<<3DED||vMMO 	D$K			"$LL$T^^U;'		2t??M
 22.w..0A0AB]] 3 

 	.0&L]^88$T\\499fEK!XXN[{F3	 
 
	?FFtyyQTUY[a[j[j[r[rQsGtuv*4<<*:;<r#   c                   @    e Zd Zd Zd Zd Zd Zd Zd
dZddZ	d	 Z
y)r   c                 "    t               | _        y r$   )r   _twr   s    r!   r8   zTerminalReporter.__init__   s    !#r#   c                      y r$   r(   r   s    r!   ensure_newlinezTerminalReporter.ensure_newline   s    r#   c                 >     | j                   j                  |fi | y r$   )r   write)r   contentmarkups      r!   r   zTerminalReporter.write   s    w)&)r#   c                     t        |t              s|j                  d      } | j                  j                  |fi | y )Nreplace)errors)
isinstancestrdecoder   liner   r   r   s      r!   
write_linezTerminalReporter.write_line   s3    $$;;i;0Dd%f%r#   c                 Z    t        |      } | j                  j                  d|z   fi | y )N)r   r   r   r   s      r!   rewritezTerminalReporter.rewrite   s&    4ytd{-f-r#   Nc                 @     | j                   j                  ||fi | y r$   r   sep)r   r   rC   r   s       r!   	write_sepzTerminalReporter.write_sep   s    S%*6*r#   c                 @     | j                   j                  ||fi | y r$   r   )r   rC   r   kws       r!   sectionzTerminalReporter.section   s    S%&2&r#   c                 >     | j                   j                  |fi | y r$   )r   r   )r   msgr   s      r!   r   zTerminalReporter.line   s    c R r#   r$   )=)r%   r&   r'   r8   r   r   r   r   r   r   r   r(   r#   r!   r   r      s*    $*&
.+'!r#   r   )$r9   	functoolsr   _pytestr   _pytest._ior   _pytest.config.findpathsr   pytest_benchmark.csvr   rS   r	   rn   r
   r   r   r   r   tabler   utilsr   r   r   r   COMPARE_HELPActionr   rG   r*   rQ   r   rZ   r   r   r(   r#   r!   <module>r      s       & 2 +   # ' & )  " !  $0  H33 8z@5 5&%=P! !r#   