forked from nhoffman/argparse-bash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·57 lines (39 loc) · 1.34 KB
/
test.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
#!/usr/bin/env python
"""Test output of various incantations of example.sh
"""
import unittest
import subprocess
from textwrap import dedent
def run(*args):
cmd = ['./example.sh'] + list(args)
if hasattr(subprocess, 'check_output'):
# python 2.7+
output = subprocess.check_output(cmd, universal_newlines=True).strip()
else:
# python 2.6
output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0].strip()
return output
def strip(val):
return dedent(val).strip()
class TestEverything(unittest.TestCase):
def test01(self):
output = run('infile', 'outfile')
expected = strip("""
required infile: infile
required outfile: outfile
the answer: 42
do the thing? no, do not do it
arg with multiple values: []
""")
self.assertEqual(output, expected)
def test02(self):
output = run('infile', 'outfile', '-m', 'one fish', 'two fish')
self.assertTrue('arg with multiple values: [one fish] [two fish]' in output)
def test03(self):
output = run('infile', 'outfile', '-d')
self.assertTrue('yes, do it' in output)
def test04(self):
output = run('infile', 'outfile', '-a', '0')
self.assertTrue('the answer: 0' in output)
if __name__ == '__main__':
unittest.main()