PageRenderTime 32ms CodeModel.GetById 24ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/pygdb2/test/test_pygdb2.py

https://bitbucket.org/antocuni/pygdb2/
Python | 47 lines | 45 code | 2 blank | 0 comment | 3 complexity | 91a53a23cd598b598a41b6e25d3ce0d7 MD5 | raw file
 1import py
 2import os
 3import sys
 4import re
 5import pexpect
 6
 7def expect_lines(child, *lines):
 8    for line in lines:
 9        child.expect(line)
10
11def test_set_watchpoint(monkeypatch):
12    root = py.path.local(__file__).join('..', '..', '..')
13    PYTHONPATH = os.getenv('PYTHONPATH') or ''
14    if PYTHONPATH:
15        PYTHONPATH += ':'
16    PYTHONPATH += str(root)
17    monkeypatch.setenv('PYTHONPATH', PYTHONPATH)
18    #
19    watch_expr = re.escape('*(int*)') + '[0-9]*'
20    #
21    cmd = 'gdb --eval "python import pygdb2" --args %s set_watchpoint.py' % sys.executable
22    child = pexpect.spawn(cmd, timeout=2)
23    child.logfile = sys.stdout
24    child.expect_exact ('(gdb) ')
25    child.sendline('pyrun')
26    expect_lines(child,
27                 'program starting',
28                 'pygdb2: watch %s' % watch_expr,
29                 'Hardware watchpoint 1: %s' % watch_expr,
30                 '0',
31                 '1',
32                 'Hardware watchpoint 1: %s' % watch_expr,
33                 'Old value = 42',
34                 'New value = 43',
35                 )
36    child.expect_exact ('(gdb) ')
37    child.sendline('c')
38    expect_lines(child,
39                 '2',
40                 '3',
41                 '4',
42                 'program stopping',
43                 )
44    child.expect_exact('Program exited normally.')
45    child.expect_exact ('(gdb) ')
46    child.sendline('quit')
47    child.expect(pexpect.EOF)