path/local/testing/test_local.py - line 246
|
def test_sysexec_failing(self): |
x = py.path.local.sysfind('false') |
py.test.raises(py.process.cmdexec.Error, """ |
x.sysexec('aksjdkasjd') |
-> """) | |
test/raises.py - line 20
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 | |
def raises(ExpectedException, *args, **kwargs): |
""" raise AssertionError, if target code does not raise the expected |
exception. |
""" |
assert args |
__tracebackhide__ = True |
if isinstance(args[0], str): |
expr, = args |
assert isinstance(expr, str) |
frame = sys._getframe(1) |
loc = frame.f_locals.copy() |
loc.update(kwargs) |
|
source = py.code.Source(expr) |
try: |
-> exec source.compile() in frame.f_globals, loc |
|
|
|
except ExpectedException: |
return py.code.ExceptionInfo() |
else: |
func = args[0] |
assert callable |
try: |
func(*args[1:], **kwargs) |
|
except ExpectedException: |
return py.code.ExceptionInfo() |
k = ", ".join(["%s=%r" % x for x in kwargs.items()]) |
if k: |
k = ', ' + k |
expr = '%s(%r%s)' %(func.__name__, args, k) |
raise ExceptionFailure(msg="DID NOT RAISE", |
expr=args, expected=ExpectedException) | |
None</home/user/NEW/py-0.9.1/py/test/raises.py:20> - line 2
|
-> x.sysexec('aksjdkasjd') | |
path/local/local.py - line 499
490 |
491 |
492 |
493 |
494 |
495 |
496 |
497 |
498 |
499 |
500 |
501 |
502 |
503 |
504 | |
def sysexec(self, *argv): |
""" return stdout-put from executing a system child process, |
where the self path points to the binary (XXX or script) |
to be executed. Note that this process is directly |
invoked and not through a system shell. |
""" |
from py.compat.subprocess import Popen, PIPE |
argv = map(str, argv) |
proc = Popen([str(self)] + list(argv), stdout=PIPE, stderr=PIPE) |
-> stdout, stderr = proc.communicate() |
ret = proc.wait() |
if ret != 0: |
raise py.process.cmdexec.Error(ret, ret, str(self), |
stdout, stderr,) |
return stdout | |