forked from cirosantilli/python-cheat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_main.py
More file actions
executable file
·61 lines (51 loc) · 1.35 KB
/
test_main.py
File metadata and controls
executable file
·61 lines (51 loc) · 1.35 KB
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
#!/usr/bin/env python
import subprocess
##just args
process = subprocess.Popen(
['python','main.py','a','b'],
shell = False,
stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
universal_newlines = True
)
stdout, stderr = process.communicate()
exit_status = process.wait()
assert stdout == 'a\na2\nb\nb2\n'
#input order is used:
process = subprocess.Popen(
['python','main.py','b','a'],
shell = False,
stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
universal_newlines = True
)
stdout, stderr = process.communicate()
exit_status = process.wait()
assert stdout == 'b\nb2\na\na2\n'
##just stdin
process = subprocess.Popen(
['python','main.py'],
shell = False,
stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
universal_newlines = True
)
stdout, stderr = process.communicate('c\nc2\n')
exit_status = process.wait()
assert stdout == 'c\nc2\n'
##stdin and args
#only args are used, so don't do this.
process = subprocess.Popen(
['python','main.py','a','b'],
shell = False,
stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
universal_newlines = True
)
stdout, stderr = process.communicate('c\nc2\n')
exit_status = process.wait()
assert stdout == 'a\na2\nb\nb2\n'