Your IP : 216.73.216.213


Current Path : /opt/alt/python311/lib64/python3.11/test/test_gdb/__pycache__/
Upload File :
Current File : //opt/alt/python311/lib64/python3.11/test/test_gdb/__pycache__/test_pretty_print.cpython-311.pyc

�

�0�ipE��`�ddlZddlZddlmZddlmZmZmZmZm	Z	d�Z
Gd�de	��ZdS)�N)�support�)�
BREAKPOINT_FN�GDB_VERSION�run_gdb�setup_module�
DebuggerTestsc�"�t��dS�N)r���F/opt/alt/python311/lib64/python3.11/test/test_gdb/test_pretty_print.py�setUpModuler
s���N�N�N�N�Nr
c��eZdZ		d"d�Zd�Zd#d�Zejd��d���Zd�Z	d	�Z
d
�Zejd��d���Zejd��d���Z
d
�Zejd��d���Zejd��d���Zd�Zd�Zd�Zd�Zd#d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d �Z!d!�Z"dS)$�PrettyPrintTestsNFc���|pdg}|�|t||���}tjd|tj��}|s|�d|�d|����|�d��|fS)Nzbacktrace 1)�
breakpoint�cmds_after_breakpoint�import_sitezS#0\s+builtin_id\s+\(self\=.*,\s+v=\s*(.*?)?\)\s+at\s+\S*[A-Za-z]+/[A-Za-z0-9_-]+\.czUnexpected gdb output: �
r)�get_stack_tracer�re�search�DOTALL�fail�group)�self�sourcerr�
gdb_output�ms      r�get_gdb_reprzPrettyPrintTests.get_gdb_reprs��� !6� H�-����)�)�&�]�@U�6A�*�C�C�
�
�I�
6�
��	�
#�
#���	R��I�I�I����Z�Z�P�Q�Q�Q��w�w�q�z�z�:�%�%r
c�h�|�d��}|�t|v��dS)N�id(42))r�
assertTruer�rrs  r�test_getting_backtracez'PrettyPrintTests.test_getting_backtrace3s2���)�)�(�3�3�
����
��3�4�4�4�4�4r
c	��|�dt|��zdz��\}}|st|��}|�|||�d|�d|����dS)Nzid(�)z did not equal expected z; full output was:
)r!�ascii�repr�assertEqual)r�val�exp_repr�gdb_reprrs     r�
assertGdbReprzPrettyPrintTests.assertGdbRepr7s{�� $�0�0���s���1C�c�1I�J�J���*��	!��C�y�y�H�����8�%�X�X�x�x�x���=�	?�	?�	?�	?�	?r
�cpuc���|�d��|�d��|�d��|�d��|�d��dS)z0Verify the pretty-printing of various int values�*ri����lJ)�l�����I�5N�r/�rs r�test_intzPrettyPrintTests.test_intAso��	
���2�������1�������2�������=�)�)�)����,�-�-�-�-�-r
c��|�d��|�d��|�d��dS)z2Verify the pretty-printing of True, False and NoneTFNr3r4s r�test_singletonsz PrettyPrintTests.test_singletonsJsD�����4� � � ����5�!�!�!����4� � � � � r
c��|�i��|�ddid��|�ddd�d��dS)z*Verify the pretty-printing of dictionaries�foo�barz{'foo': 'bar'}r2)r9�douglasz{'foo': 'bar', 'douglas': 42}Nr3r4s r�
test_dictszPrettyPrintTests.test_dictsPsV�����2�������E�5�>�+;�<�<�<����5�R�8�8�:Y�Z�Z�Z�Z�Zr
c��|�g��|�ttd������dS)z#Verify the pretty-printing of lists�N)r/�list�ranger4s r�
test_listszPrettyPrintTests.test_listsWs<�����2�������4��a���>�>�*�*�*�*�*r
c�J�|�d��|�d��|�d��|�d��|�d��|�td�td��D������dS)	z#Verify the pretty-printing of bytesr
s(And now for something hopefully the sames7string with embedded NUL here  and then some more texts7this is a tab:	 this is a slash-N:
 this is a slash-R:
s!this is byte 255:� and byte 128:�c��g|]}|��Srr)�.0�bs  r�
<listcomp>z/PrettyPrintTests.test_bytes.<locals>.<listcomp>is��!8�!8�!8��!�!8�!8�!8r
�N)r/�bytesr@r4s r�
test_byteszPrettyPrintTests.test_bytes\s���	
���3�������F�G�G�G����V�W�W�W����4�	�	�	�
	
���E�F�F�F����5�!8�!8�U�3�Z�Z�!8�!8�!8�9�9�:�:�:�:�:r
c�L���tdd��\}}|�|s�std|�d|�������fd�}��d����d����d��|d	��|d
��|td����dS)
z-Verify the pretty-printing of unicode stringsz--eval-commandz:python import locale; print(locale.getpreferredencoding())zZunable to determine the Python locale preferred encoding of embedded Python in GDB
stdout=z
stderr=c����	|������|��dS#t$r'��|t|����YdSwxYwr)�encoder/�UnicodeEncodeErrorr))�text�encodingrs ��r�
check_reprz1PrettyPrintTests.test_strings.<locals>.check_repr~sx���
)����H�%�%�%��"�"�4�(�(�(�(�(��&�
6�
6�
6��"�"�4��t���5�5�5�5�5�5�
6���s�/�-A �A �z(And now for something hopefully the samez7string with embedded NUL here  and then some more textu☠u文字化けi!�N)r�RuntimeErrorr/�chr)r�stdout�stderrrPrOs`   @r�test_stringszPrettyPrintTests.test_stringsks����!��H�J�J�������	&��	&��%� �%�%�!�%�%�&�&�
&�	)�	)�	)�	)�	)�	)�	
���2�������E�F�F�F����U�V�V�V�	�
�8����
	�
�-�.�.�.�	�
�3�w�<�<� � � � � r
c��|�t��d��|�dd��|�d��dS)z$Verify the pretty-printing of tuplesz())rz(1,))r9r:�bazN)r/�tupler4s r�test_tupleszPrettyPrintTests.test_tuples�sM�����5�7�7�D�)�)�)����4��(�(�(����0�1�1�1�1�1r
c���tdkr|�d��|�t��d��|�tdg��d��tjjsJ|�tddg��d��|�tgd���d	��|�d
��\}}|�|d��dS)
z"Verify the pretty-printing of sets���z.pretty-printing of sets needs gdb 7.3 or laterzset()�az{'a'}rEz
{'a', 'b'}��r>�z	{4, 5, 6}z&s = set(['a','b'])
s.remove('a')
id(s)z{'b'}N)	r�skipTestr/�set�sys�flags�ignore_environmentr!r+�rr.rs   r�	test_setszPrettyPrintTests.test_sets�s��������M�M�J�K�K�K����3�5�5�'�*�*�*����3��u�:�:�w�/�/�/��y�+�	<����s�C��:����=�=�=����s�9�9�9�~�~�{�;�;�;� $�0�0�2	� 
� 
���*�	
����7�+�+�+�+�+r
c��tdkr|�d��|�t��d��|�tdg��d��tjjsL|�tddg��d��|�tgd���d	��d
Sd
S)z(Verify the pretty-printing of frozensetsr\z4pretty-printing of frozensets needs gdb 7.3 or laterzfrozenset()r_zfrozenset({'a'})rEzfrozenset({'a', 'b'})r`zfrozenset({4, 5, 6})N)rrcr/�	frozensetrerfrgr4s r�test_frozensetsz PrettyPrintTests.test_frozensets�s��������M�M�P�Q�Q�Q����9�;�;�
�6�6�6����9�c�U�+�+�-?�@�@�@��y�+�	M����y�#�s��4�4�6M�N�N�N����y����3�3�5K�L�L�L�L�L�	M�	Mr
c��|�d��\}}|�|d��|�d��\}}|�|d��dS)NzR
try:
    raise RuntimeError("I am an error")
except RuntimeError as e:
    id(e)
zRuntimeError('I am an error',)z=
try:
    a = 1 / 0
except ZeroDivisionError as e:
    id(e)
z&ZeroDivisionError('division by zero',)�r!r+rhs   r�test_exceptionsz PrettyPrintTests.test_exceptions�s���#�0�0�2� � ���*�	
����9�	;�	;�	;�
 $�0�0�2� � ���*�	
����A�	C�	C�	C�	C�	Cr
c��|�d��\}}tjd|��}|�|d|z���dS)z7Verify the pretty-printing of new-style class instancesz8
class Foo:
    pass
foo = Foo()
foo.an_int = 42
id(foo)�*<Foo\(an_int=42\) at remote 0x-?[0-9a-f]+>�'Unexpected new-style class rendering %r��msgN�r!r�matchr$�rr.rr s    r�test_modern_classz"PrettyPrintTests.test_modern_class�si��#�0�0�2� � ���*�
�H�B�H�M�M������E��P�	�	R�	R�	R�	R�	Rr
c��|�d��\}}tjd|��}|�|d|z���dS)z<Verify the pretty-printing of an instance of a list subclasszO
class Foo(list):
    pass
foo = Foo()
foo += [1, 2, 3]
foo.an_int = 42
id(foo)rqrrrsNrurws    r�test_subclassing_listz&PrettyPrintTests.test_subclassing_list�si��#�0�0�2� � ���*�
�H�B�H�M�M������E��P�	�	R�	R�	R�	R�	Rr
c��|�d��\}}tjd|��}|�|d|z���dS)z=Verify the pretty-printing of an instance of a tuple subclasszH
class Foo(tuple):
    pass
foo = Foo((1, 2, 3))
foo.an_int = 42
id(foo)rqrrrsNrurws    r�test_subclassing_tuplez'PrettyPrintTests.test_subclassing_tuple�sk�� $�0�0�2� � ���*�
�H�B�H�M�M������E��P�	�	R�	R�	R�	R�	Rr
c���|r|dg}ndg}|�||���\}}|r||krdSd}tj||��}|s|�d|�d|����dSdS)z�Run Python under gdb, corrupting variables in the inferior process
        immediately before taking a backtrace.

        Verify that the variable's representation is the expected failsafe
        representation�	backtrace�rNz<.* at remote 0x-?[0-9a-f]+>�Unexpected gdb representation: r)r!rrvr)	rr�
corruption�expreprrr.r�patternr s	         r�
assertSanezPrettyPrintTests.assertSane�s����	0�#-�{�";�!�!�#.�-�!�
���f�4I�
�
K�
K�	��*��	��7�"�"���1���H�W�h�'�'���	2��I�I�I�#�8�8�Z�Z�1�
2�
2�
2�
2�
2�	2�	2r
c�j�|�dddg���\}}|�|d��dS)z2Ensure that a NULL PyObject* is handled gracefullyr#zset variable v=0r~r�0x0Nrnrhs   r�
test_NULL_ptrzPrettyPrintTests.test_NULL_ptrsS��
���h�5G�5@�5B�
�
C�
C�	��*�	
����5�)�)�)�)�)r
c�2�|�dd��dS)z?Ensure that a PyObject* with NULL ob_type is handled gracefullyr#zset v->ob_type=0N�r�r4s r�test_NULL_ob_typez"PrettyPrintTests.test_NULL_ob_type%s'������*�	,�	,�	,�	,�	,r
c�6�|�ddd���dS)zDEnsure that a PyObject* with a corrupt ob_type is handled gracefullyr#zset v->ob_type=0xDEADBEEF�42�r�Nr�r4s r�test_corrupt_ob_typez%PrettyPrintTests.test_corrupt_ob_type*s/������3� $�	�	&�	&�	&�	&�	&r
c�6�|�ddd���dS)zDEnsure that a PyObject* with a type with corrupt tp_flags is handledr#zset v->ob_type->tp_flags=0x0r�r�Nr�r4s r�test_corrupt_tp_flagsz&PrettyPrintTests.test_corrupt_tp_flags0s/������6� $�	�	&�	&�	&�	&�	&r
c�6�|�ddd���dS)zCEnsure that a PyObject* with a type with corrupt tp_name is handledr#z"set v->ob_type->tp_name=0xDEADBEEFr�r�Nr�r4s r�test_corrupt_tp_namez%PrettyPrintTests.test_corrupt_tp_name6s/������<� $�	�	&�	&�	&�	&�	&r
c���tjjr|�d��|�dd���\}}tjd|��}|�|d|z���dS)	zAEnsure that the new-style class _Helper in site.py can be handledz(need site module, but -S option was usedzid(__builtins__.help)T)rz%<_Helper\(\) at remote 0x-?[0-9a-f]+>zUnexpected rendering %rrsN)rerf�no_sitercr!rrvr$rws    r�test_builtins_helpz#PrettyPrintTests.test_builtins_help<s����9��	F��M�M�D�E�E�E� $�0�0�1H�VZ�0�[�[���*��H�=�x�H�H������5��@�	�	B�	B�	B�	B�	Br
c��|�d��\}}|�|d��|�d��\}}|�|d��dS)zbEnsure that a reference loop involving a list doesn't lead proxyval
        into an infinite loop:z#a = [3, 4, 5] ; a.append(a) ; id(a)z[3, 4, 5, [...]]z-a = [3, 4, 5] ; b = [a] ; a.append(b) ; id(a)z[3, 4, 5, [[...]]]Nrnrhs   r�test_selfreferential_listz*PrettyPrintTests.test_selfreferential_listJsp��
���C�D�D�	��*�����#5�6�6�6�
���M�N�N�	��*�����#7�8�8�8�8�8r
c�b�|�d��\}}|�|d��dS)zbEnsure that a reference loop involving a dict doesn't lead proxyval
        into an infinite loop:z-a = {} ; b = {'bar':a} ; a['foo'] = b ; id(a)z{'foo': {'bar': {...}}}Nrnrhs   r�test_selfreferential_dictz*PrettyPrintTests.test_selfreferential_dictUs>��
���M�N�N�	��*�	
����#<�=�=�=�=�=r
c��|�d��\}}|�tjd|��d|�d|����dS)Nz:
class Foo:
    pass
foo = Foo()
foo.an_attr = foo
id(foo)�1<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>r�r�r!r$rrvrhs   r�'test_selfreferential_old_style_instancez8PrettyPrintTests.test_selfreferential_old_style_instance]sp������
�
�	��*�	
�����!U�!)�+�+�+�&�X�X�z�z�3�	4�	4�	4�	4�	4r
c�"�|�d��\}}|�tjd|��d|�d|����|�d��\}}|�tjd|��d|�d|����dS)NzB
class Foo(object):
    pass
foo = Foo()
foo.an_attr = foo
id(foo)r�r�rzR
class Foo(object):
    pass
a = Foo()
b = Foo()
a.an_attr = b
b.an_attr = a
id(a)zZ<Foo\(an_attr=<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>\) at remote 0x-?[0-9a-f]+>r�rhs   r�'test_selfreferential_new_style_instancez8PrettyPrintTests.test_selfreferential_new_style_instancejs�������
�
�	��*�	
�����!U�!)�+�+�+�&�X�X�z�z�3�	4�	4�	4�
���	�
�
�	��*�	
�����!~�!)�+�+�+�&�X�X�z�z�3�	4�	4�	4�	4�	4r
c���|�d��\}}|�|d��|�t|��dtd��z��dS)z)Verify that very long output is truncatedzid(list(range(1000)))a[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226...(truncated)iz...(truncated)N)r!r+�lenrhs   r�test_truncationz PrettyPrintTests.test_truncation�sw��#�0�0�1H�I�I���*�����7�	8�	8�	8�,	
����X�����$4� 5� 5�5�	7�	7�	7�	7�	7r
c��|�d��\}}|�tjd|��d|�d|����dS)Nz$import sys; id(sys.stdout.readlines)zO<built-in method readlines of _io.TextIOWrapper object at remote 0x-?[0-9a-f]+>r�rr�rhs   r�test_builtin_methodz$PrettyPrintTests.test_builtin_method�sf��#�0�0�1W�X�X���*������!s�!)�+�+�+�&�X�X�z�z�3�	4�	4�	4�	4�	4r
c��|�dddg���}|�tjd|tj��d|�d|����dS)NzQ
import sys
def foo(a, b, c):
    return sys._getframe(0)

f = foo(3, 4, 5)
id(f)�
builtin_idzprint (PyFrameObject*)v)rrzK.*\s+\$1 =\s+Frame 0x-?[0-9a-f]+, for file <string>, line 4, in foo \(a=3.*r�r)rr$rrvrr%s  r�test_frameszPrettyPrintTests.test_frames�s����)�)�+	�6B�AZ�@[�*�	,�	,�
�	
�����!o�!+�!#��,�,�,�DN�:�:�z�z�Z�	\�	\�	\�	\�	\r
)NFr)#�__name__�
__module__�__qualname__r!r&r/r�requires_resourcer5r7r<rArIrVrZrirlrorxrzr|r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr
rrrs�������+/�!&�"&�"&�"&�"&�H5�5�5�?�?�?�?��W��u�%�%�.�.�&�%�.�!�!�!�[�[�[�+�+�+�
�W��u�%�%�;�;�&�%�;��W��u�%�%�,!�,!�&�%�,!�\2�2�2��W��u�%�%�,�,�&�%�,�$�W��u�%�%�	M�	M�&�%�	M�C�C�C�,
R�
R�
R�R�R�R�
R�
R�
R�2�2�2�2�:*�*�*�,�,�,�
&�&�&�&�&�&�&�&�&�B�B�B�	9�	9�	9�>�>�>�4�4�4�4�4�4�67�7�7�84�4�4�\�\�\�\�\r
r)rre�testr�utilrrrrr	rrrr
r�<module>r�s���	�	�	�	�
�
�
�
�������*�*�*�*�*�*�*�*�*�*�*�*�*�*�
���h\�h\�h\�h\�h\�}�h\�h\�h\�h\�h\r