-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_subwrap.py
52 lines (38 loc) · 1.54 KB
/
test_subwrap.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
import fudge
from fudge.inspector import arg
from nose.tools import *
import subwrap
def test_simple_run():
output1 = subwrap.run(['echo', 'hello'])
assert output1.std_out.strip() == 'hello'
@fudge.patch('subprocess.Popen')
def test_simple_run_with_fake(fake_popen):
fake_process = fake_popen.expects_call().returns_fake()
fake_process.expects('communicate').returns(('hello', ''))
fake_process.has_attr(returncode=0)
output = subwrap.run(['somecmd'])
assert output.std_out == 'hello'
@raises(subwrap.CommandError)
@fudge.patch('subprocess.Popen')
def test_default_exit_handle_with_fake(fake_popen):
fake_process = fake_popen.expects_call().returns_fake()
fake_process.expects('communicate').returns(('', ''))
fake_process.has_attr(returncode=1)
subwrap.run(['somecmd'])
@fudge.patch('subprocess.Popen')
def test_custom_exit_handle_with_fake(fake_popen):
fake_process = fake_popen.expects_call().returns_fake()
fake_process.expects('communicate').returns(('', ''))
fake_process.has_attr(returncode=1000)
def custom_handle(response):
assert response.return_code == 1000
subwrap.run(['somecmd'], exit_handle=custom_handle)
@fudge.patch('subprocess.Popen')
def test_pass_options(fake_popen):
any = arg.any
fake_process = (fake_popen.expects_call()
.with_args(any(), cwd="test", stderr=any(), stdout=any())
.returns_fake())
fake_process.expects('communicate').returns(('', ''))
fake_process.has_attr(returncode=0)
subwrap.run(['somecmd'], cwd="test")