
    h                     ^    S r SSKrSSKJr  SSKJr  SSKJr   " S S\R                  5      rg)	z
Test libpython.py. This is already partly tested by test_libcython_in_gdb and
Lib/test/test_gdb.py in the Python source. These tests are run in gdb and
called from test_libcython_in_gdb.main()
    N)	libcython)	libpython   )test_libcython_in_gdbc                   n   ^  \ rS rSrSrU 4S jrS rSS jrS rSS jr	SS jr
S	 rS
 rS rS rSrU =r$ )TestPrettyPrinters   a~  
Test whether types of Python objects are correctly inferred and that
the right libpython.PySomeTypeObjectPtr classes are instantiated.

Also test whether values are appropriately formatted (don't be too
laborious as Lib/test/test_gdb.py already covers this extensively).

Don't take care of decreffing newly allocated objects as a new
interpreter is started for every test anyway.
c                 D   > [         TU ]  5         U R                  S5        g )Nzb = c = d = 0)supersetUpbreak_and_run)self	__class__s    e/var/www/fran/franai/venv/lib/python3.13/site-packages/Cython/Debugger/Tests/test_libpython_in_gdb.pyr   TestPrettyPrinters.setUp   s    ?+    c                 j    [         R                  " U5      n[        R                  " U5      S:w  d   eU$ )Nr   )gdbparse_and_evalr   pointervalue)r   codevalues      r   get_pyobjectTestPrettyPrinters.get_pyobject   s0    ""4(%%e,111r   c                     Ub"  X!S.n[         R                  " SU-  5        SU-   n[        R                  R	                  U R                  U5      5      $ )N)varnamer   zset $%(varname)s = %(code)s$)r   executer   PyObjectPtrfrom_pyobject_ptrr   )r   r   gdbvards       r   pyobject_fromcode$TestPrettyPrinters.pyobject_fromcode$   sM    !/AKK59:<D$$66t7H7H7NOOr   c                 @    UR                  [        R                  5      $ N)get_truncated_reprr   MAX_OUTPUT_LEN)r   pyobjects     r   get_reprTestPrettyPrinters.get_repr,   s    **9+C+CDDr   c                 n    SU;  d   eSUR                  S5      [        U5      4-  nU R                  X2S9$ )N   "z0(PyObject *) PyBytes_FromStringAndSize("%s", %d)	iso8859-1r!   )decodelenr#   )r   stringr!   r   s       r   alloc_bytestring#TestPrettyPrinters.alloc_bytestring/   sG    6!!! BV]]S^E_adekalDmm%%d%::r   c                     [         R                  " 5       nSU< S3nUR                  S5      R                  S5      nU R	                  SXER                  SS5      R                  SS	5      [        U5      4-  US
9$ )N	PyUnicode_DecodeUnicodeEscapeunicode_escaper.   z#(PyObject *) %s("%s", %d, "strict")"z\"\z\\r/   )r   get_inferior_unicode_postfixencoder0   r#   replacer1   )r   r2   r!   postfixfuncnamedatas         r   alloc_unicodestring&TestPrettyPrinters.alloc_unicodestring6   s}    88:8?A}}-.55kB%%1,,sE2::4GT5T T &  	r   c                     U R                  S5      n[        R                  nSnU R                  [	        U5      U5        U R                  U R                  U5      U5        g )Ns   spamzb'spam')r3   r   PyBytesObjectPtrassertEqualtyper*   )r   
bytestringbytestring_classexpecteds       r   test_bytestring"TestPrettyPrinters.test_bytestring@   sR    **73
$55j)+;<z2H=r   c                     U R                  S5      nU R                  [        U5      [        R                  5        U R                  U R                  U5      S5        g )Nu   spam ἄλφαu   'spam ἄλφα')rA   rE   rF   r   PyUnicodeObjectPtrr*   )r   unicode_strings     r   test_unicodeTestPrettyPrinters.test_unicodeI   sH    112BCn-y/K/KL~68JKr   c                     U R                  SSS9n[        R                  " S5      (       d   eU R                  [	        U5      [
        R                  5        U R                  U R                  U5      S5        g )NzPyLong_FromLong(200)longvalr/   z!$longval->ob_type == &PyLong_Type200)r#   r   r   rE   rF   r   PyLongObjectPtrr*   )r   rR   s     r   	test_longTestPrettyPrinters.test_longO   sh    (()?09 ) ;!!"EFFFFg	(A(ABw/7r   c                 x    U R                  S5      nU R                  [        U5      [        R                  5        g )NzPyEval_GetFrame())r#   rE   rF   r   PyFrameObjectPtr)r   frames     r   test_frame_type"TestPrettyPrinters.test_frame_typeW   s-    &&':;ei&@&@Ar    r&   )__name__
__module____qualname____firstlineno____doc__r   r   r#   r*   r3   rA   rJ   rO   rU   rZ   __static_attributes____classcell__)r   s   @r   r   r      sD    	,
PE;>L8B Br   r   )	ra   r   Cython.Debuggerr   r    r   DebugTestCaser   r\   r   r   <module>rg      s/     % % #KB.<< KBr   