Format: application/x-python-code
1 o
2
3 ��h�; � @ sn d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl m
4 Z
5 ddlmZ ddl
6 mZ ddlmZ ddlZG d d
7 � d
8 e�ZG dd� de�Zd
9 d� Zdd� Zdd� Zdd� Zdd� Zedd� �ZdZdd� Zejjdd�edd� ��Zejjdd�ejj e�!� d kd!d�ed"d#� ���Z"ejj#ej$j%d$vd%d&d'�ejj e�!� d kd!d�ed(d)� ���Z&ed*d+� �Z'dS ),zTests for debugging machinery.
10 � N)�NamedTemporaryFile��dedent)�patch)�debugger)�IPYTHON_TESTING_TIMEOUT_SCALE)�
11 skip_win32c @ s e Zd ZdZdd� Zdd� ZdS )�
12 _FakeInputa
13 A fake input stream for pdb's interactive debugger. Whenever a
14 line is read, print it (to simulate the user typing it), and then
15 return it. The set of lines to return is specified in the
16 constructor; they should not have trailing newlines.
17 c C s t |�| _d S �N)�iter�lines)�selfr � r �Vc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/tests/test_debugger.py�__init__ s z_FakeInput.__init__c C s t | j�}t|� |d S )N�
18 )�nextr �print)r
19 �liner r r �readline# s
20 z_FakeInput.readlineN)�__name__�
21 __module__�__qualname__�__doc__r r r r r r r s r c @ s( e Zd ZdZdd� Zdd� Zdd� ZdS ) �PdbTestInputz:Context manager that makes testing Pdb in doctests easier.c C s
22 || _ d S r
23 )�input)r
24 r r r r r + s
25 zPdbTestInput.__init__c C s t j| _t| j�t _d S r
26 )�sys�stdin�
27 real_stdinr r )r
28 r r r � __enter__. s zPdbTestInput.__enter__c G s | j t_d S r
29 )r r r )r
30 �excr r r �__exit__2 s zPdbTestInput.__exit__N)r r r r r r r! r r r r r ( s
31 r c C � dS )a}
32 Test calling some IPython magics from ipdb.
33
34 First, set up some test functions and classes which we can inspect.
35
36 In [1]: class ExampleClass(object):
37 ...: """Docstring for ExampleClass."""
38 ...: def __init__(self):
39 ...: """Docstring for ExampleClass.__init__"""
40 ...: pass
41 ...: def __str__(self):
42 ...: return "ExampleClass()"
43
44 In [2]: def example_function(x, y, z="hello"):
45 ...: """Docstring for example_function."""
46 ...: pass
47
48 In [3]: old_trace = sys.gettrace()
49
50 Create a function which triggers ipdb.
51
52 In [4]: def trigger_ipdb():
53 ...: a = ExampleClass()
54 ...: debugger.Pdb().set_trace()
55
56 Run ipdb with faked input & check output. Because of a difference between
57 Python 3.13 & older versions, the first bit of the output is inconsistent.
58 We need to use ... to accommodate that, so the examples have to use IPython
59 prompts so that ... is distinct from the Python PS2 prompt.
60
61 In [5]: with PdbTestInput([
62 ...: 'pdef example_function',
63 ...: 'pdoc ExampleClass',
64 ...: 'up',
65 ...: 'down',
66 ...: 'list',
67 ...: 'pinfo a',
68 ...: 'll',
69 ...: 'continue',
70 ...: ]):
71 ...: trigger_ipdb()
72 ...> <doctest ...>(3)trigger_ipdb()
73 1 def trigger_ipdb():
74 2 a = ExampleClass()
75 ----> 3 debugger.Pdb().set_trace()
76 <BLANKLINE>
77 ipdb> pdef example_function
78 example_function(x, y, z='hello')
79 ipdb> pdoc ExampleClass
80 Class docstring:
81 Docstring for ExampleClass.
82 Init docstring:
83 Docstring for ExampleClass.__init__
84 ipdb> up
85 > <doctest ...>(11)<module>()
86 7 'pinfo a',
87 8 'll',
88 9 'continue',
89 10 ]):
90 ---> 11 trigger_ipdb()
91 <BLANKLINE>
92 ipdb> down...
93 > <doctest ...>(3)trigger_ipdb()
94 1 def trigger_ipdb():
95 2 a = ExampleClass()
96 ----> 3 debugger.Pdb().set_trace()
97 <BLANKLINE>
98 ipdb> list
99 1 def trigger_ipdb():
100 2 a = ExampleClass()
101 ----> 3 debugger.Pdb().set_trace()
102 <BLANKLINE>
103 ipdb> pinfo a
104 Type: ExampleClass
105 String form: ExampleClass()
106 Namespace: Local...
107 Docstring: Docstring for ExampleClass.
108 Init docstring: Docstring for ExampleClass.__init__
109 ipdb> ll
110 1 def trigger_ipdb():
111 2 a = ExampleClass()
112 ----> 3 debugger.Pdb().set_trace()
113 <BLANKLINE>
114 ipdb> continue
115
116 Restore previous trace function, e.g. for coverage.py
117
118 In [6]: sys.settrace(old_trace)
119 Nr r r r r �test_ipdb_magics9 � r# c C r"