-
Notifications
You must be signed in to change notification settings - Fork 25
/
test_pystack.py
72 lines (55 loc) · 2.04 KB
/
test_pystack.py
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
from __future__ import absolute_import
import sys
import subprocess
import platform
import time
import shutil
from pytest import fixture, mark, param, raises
from click.testing import CliRunner
from pystack import (
cli_main, tolerate_missing_locale, find_debugger, DebuggerNotFound)
skipif_non_gdb = mark.skipif(
shutil.which('gdb') is None, reason='gdb not found')
skipif_non_lldb = mark.skipif(
shutil.which('lldb') is None, reason='lldb not found')
skipif_darwin = mark.skipif(
platform.system().lower() == 'darwin', reason='gdb on darwin is unstable')
STATEMENTS = {
'sleep': '__import__("time").sleep(360)',
}
@fixture
def process(request):
args = [sys.executable, '-c', request.param]
process = subprocess.Popen(args)
try:
time.sleep(1)
yield process
finally:
process.terminate()
process.wait()
@fixture
def cli():
tolerate_missing_locale()
return CliRunner()
def test_find_debugger():
assert find_debugger('true') == '/usr/bin/true'
with raises(DebuggerNotFound) as error:
find_debugger('shhhhhhhhhhhhhhhhhhhhhhhhh')
assert error.value.args[0] == (
'Could not find "shhhhhhhhhhhhhhhhhhhhhhhhh" in your'
' PATH environment variable')
@mark.parametrize(('process', 'debugger'), [
param(STATEMENTS['sleep'], 'gdb', marks=[skipif_non_gdb, skipif_darwin]),
param(STATEMENTS['sleep'], 'lldb', marks=skipif_non_lldb),
], indirect=['process'])
def test_smoke(cli, process, debugger):
result = cli.invoke(cli_main, [str(process.pid), '--debugger', debugger])
assert not result.exception
assert result.exit_code == 0
assert ' File "<string>", line 1, in <module>\n' in result.output
@mark.parametrize('process', [STATEMENTS['sleep']], indirect=['process'])
def test_smoke_debugger_not_found(cli, mocker, process):
mocker.patch('pystack.find_debugger', side_effect=DebuggerNotFound('oops'))
result = cli.invoke(cli_main, [str(process.pid)])
assert result.exit_code == 1
assert 'DebuggerNotFound: oops' in result.output