File: _debugger_case_wait_for_attach_impl.py

package info (click to toggle)
pydevd 3.3.0%2Bds-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 13,892 kB
  • sloc: python: 77,508; cpp: 1,869; sh: 368; makefile: 50; ansic: 4
file content (57 lines) | stat: -rw-r--r-- 1,681 bytes parent folder | download | duplicates (2)
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
import os
import sys
import time
from _pydevd_bundle.pydevd_constants import PYDEVD_USE_SYS_MONITORING

port = int(sys.argv[1])
root_dirname = os.path.dirname(os.path.dirname(__file__))

if root_dirname not in sys.path:
    sys.path.append(root_dirname)

import pydevd
try:
    pydevd._wait_for_attach()  # Cannot be called before _enable_attach.
except AssertionError:
    pass
else:
    raise AssertionError('Expected _wait_for_attach to raise exception.')

if '--use-dap-mode' in sys.argv:
    pydevd.config('http_json', 'debugpy-dap')

assert sys.gettrace() is None
print('enable attach to port: %s' % (port,))
pydevd._enable_attach(('127.0.0.1', port))
pydevd._enable_attach(('127.0.0.1', port))  # no-op in practice

try:
    pydevd._enable_attach(('127.0.0.1', port + 15))  # different port: raise error.
except AssertionError:
    pass
else:
    raise AssertionError('Expected _enable_attach to raise exception (because it is already hearing in another port).')

assert pydevd.get_global_debugger() is not None
if PYDEVD_USE_SYS_MONITORING:
    assert sys.monitoring.get_tool(sys.monitoring.DEBUGGER_ID) == 'pydevd'
else:
    assert sys.gettrace() is not None

a = 10  # Break 1
print('wait for attach')
pydevd._wait_for_attach()
print('finished wait for attach')
pydevd._wait_for_attach()  # Should promptly return (already connected).

a = 20  # Break 2

pydevd._wait_for_attach()  # As we disconnected on the 2nd break, this one should wait until a new configurationDone.

a = 20  # Break 3

while a == 20:  # Pause 1
    # The debugger should disconnect/reconnect, pause and then change 'a' to another value.
    time.sleep(1 / 20.)  # Pause 2

print('TEST SUCEEDED!')