Current File : //usr/local/apps/python3/lib/python3.11/test/__pycache__/bisect_cmd.cpython-311.opt-1.pyc
�

�Ke����dZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
d�Zd�Zd�Z
d�Zd�Zdd�Zd	�Zd
�Zedkre��dSdS)
a�
Command line tool to bisect failing CPython tests.

Find the test_os test method which alters the environment:

    ./python -m test.bisect_cmd --fail-env-changed test_os

Find a reference leak in "test_os", write the list of failing tests into the
"bisect" file:

    ./python -m test.bisect_cmd -o bisect -R 3:3 test_os

Load an existing list of tests from a file using -i option:

    ./python -m test --list-cases -m FileTests test_os > tests
    ./python -m test.bisect_cmd -i tests test_os
�Nc��t|d��5}|D]}t||����|���ddd��dS#1swxYwYdS)N�w)�file)�open�print�flush)�filename�tests�fp�names    �9/usr/local/apps/python3/lib/python3.11/test/bisect_cmd.py�write_testsrs���	
�h��	�	����	!�	!�D��$�R� � � � � �
���
�
�
���������������������s�+A	�	A
�A
c�r�|sdStdt|���d|����t||��|S)NzWriting z tests into )r�lenr)r	r
s  r
�write_outputr&sE������	�E��E�
�
�
�
�H�H�
=�>�>�>���%� � � ��O�c�,�d�|��S)N� )�join)�argss r
�format_shell_argsr.s���8�8�D�>�>�rc��tjg}|�tj����|�tj����|S�N)�sys�
executable�extend�
subprocess�_args_from_interpreter_flags�"_optim_args_from_interpreter_flags)�cmds r
�
python_cmdr!2sG���>�
�C��J�J�z�6�8�8�9�9�9��J�J�z�<�>�>�?�?�?��Jrc�z�t��}|�gd���|�|j��tj|tjd���}|j}|r8t|��}td|�d|����tj
|��|j���}|S)N)�-m�testz--list-casesT)�stdout�universal_newlineszFailed to list tests: z failed with exit code )
r!r�	test_argsr�run�PIPE�
returncoderrr�exitr%�
splitlines)rr �proc�exitcoder
s     r
�
list_casesr/9s���
�,�,�C��J�J�-�-�-�.�.�.��J�J�t�~�����>�#�!+��-1�3�3�3�D���H�����$�$��
�����h�h� �	!�	!�	!��������K�"�"�$�$�E��Lrc��tj��}	t||��t��}|�ddd|g��|�|j��t
dt|��z��tj	|��}|j
tj�
|��rtj|��SS#tj�
|��rtj|��wwxYw)Nr#r$z--matchfilez+ %s)�tempfile�mktemprr!rr'rrrr(r*�os�path�exists�unlink)rr
�
huntrleaks�tmpr r-s      r
�	run_testsr9Js���
�/�
�
�C���C������l�l���
�
�D�&�-��5�6�6�6��
�
�4�>�"�"�"�
�f�(��-�-�-�.�.�.��~�c�"�"����
�7�>�>�#���	��I�c�N�N�N�N�	��2�7�>�>�#���	��I�c�N�N�N�N�	���s�B
C�6D
c�D�tj��}|�ddd���|�ddd���|�dd	td
d���|�d
dtdd���|���\}}||_|S)Nz-iz--inputzUTest names produced by --list-tests written into a file. If not set, run --list-tests)�helpz-oz--outputzResult of the bisectionz-nz--max-tests�z:Maximum number of tests to stop the bisection (default: 1))�type�defaultr;z-Nz
--max-iter�dz5Maximum number of bisection iterations (default: 100))�argparse�ArgumentParser�add_argument�int�parse_known_argsr')�parserrr's   r
�
parse_argsrFZs���
�
$�
&�
&�F�
����i�I��J�J�J�����j�6��8�8�8�
����m�#�q�,��-�-�-�����l��c�.��/�/�/�
�-�-�/�/�O�D�)��D�N��Krc
�d�t��}d|jvs	d|jvrtd��t��|jr9t	|j��5}d�|D��}ddd��n#1swxYwYnt|��}tdt
|��z��tdt|j��z��td|j�d|j	�d	���t|j|��}t��tj
��}d
}	t
|��|jk�r4||j	k�r(t
|��}t|dzd
��}tj||��}td|�d
t
|���dt
|������t��t#||��}td|�dt
|������td|��|r'td��|}t|j|��}ntd��t��|d
z
}t
|��|jkr||j	k��(n;#t$$r.t��td��t��YnwxYwtdt
|��z��|D]}	td|	z���t��|rtd|z��t'jtj
��|z
��}
t
|��|jkr>td|�dt+j|
�������t/jd
��dStd|�dt+j|
�������dS)Nz-wz
--verbose2z;WARNING: -w/--verbose2 option should not be used to bisect!c�6�g|]}|�����S�)�strip)�.0�lines  r
�
<listcomp>zmain.<locals>.<listcomp>vs ��1�1�1�d�T�Z�Z�\�\�1�1�1rzStart bisection with %s testszTest arguments: %sz!Bisection will stop when getting z1 or less tests (-n/--max-tests option), or after z" iterations (-N/--max-iter option)r<�z[+] Iteration z: run z tests/zran r+z*Tests failed: continuing with this subtestz;Tests succeeded: skipping this subtest, trying a new subsetzBisection interrupted!zTests (%s):z* %szOutput written into %szBisection completed in z iterations and )�secondszBisection failed after )rFr'r�inputrr/rr�	max_tests�max_iterr�output�time�	monotonic�max�random�sampler9�KeyboardInterrupt�math�ceil�datetime�	timedeltarr+)rrr
rS�
start_time�	iteration�ntest�subtestsr.r$�dts           r
�mainrcns����<�<�D��t�~������!?�!?�
�K�L�L�L�
�����z�!�
�$�*�
�
�	2��1�1�b�1�1�1�E�	2�	2�	2�	2�	2�	2�	2�	2�	2�	2�	2����	2�	2�	2�	2���4� � ��	�
)�C��J�J�
6�7�7�7�	�
�!2�4�>�!B�!B�
B�C�C�C�	�E��^�^�^�T�]�]�]�,�-�-�-��$�+�u�
-�
-�F�	�G�G�G���!�!�J��I���%�j�j�4�>�)�)�i�4�=�.H�.H���J�J�E����
�A�&�&�E��}�U�E�2�2�H��E��Y�Y��H�
�
�
�
�s�5�z�z�z�;�
<�
<�
<��G�G�G� ��x�0�0�H��E�u�u�u�c�%�j�j�j�9�:�:�:��&�(�#�#�#��
U��B�C�C�C� ��%�d�k�5�9�9����S�T�T�T��G�G�G���N�I�)�%�j�j�4�>�)�)�i�4�=�.H�.H���*����
����
�&�'�'�'�
����������

�-�#�e�*�*�
$�%�%�%�����
�f�t�m�����	�G�G�G�
�1�
�&��/�0�0�0�	
��4�>�#�#�j�0�	1�	1�B�
�5�z�z�T�^�#�#�
�����H�.�r�:�:�:�:�<�	=�	=�	=���������
�����H�.�r�:�:�:�:�<�	=�	=�	=�	=�	=s%�
A2�2A6�9A6�)E
I7�75J/�.J/�__main__r)�__doc__r@r\�os.pathr3rZrWrrr1rTrrrr!r/r9rFrc�__name__rIrr
�<module>rhs
����$����������������
�
�
�
�����
�
�
�
������������������������"
�
�
�
� ���(A=�A=�A=�H�z����D�F�F�F�F�F��r