OLD | NEW |
1 #!/usr/bin/python -tt | 1 #!/usr/bin/python -tt |
2 | 2 |
3 """Unit tests for bmpblk_utility. | 3 """Unit tests for bmpblk_utility. |
4 """ | 4 """ |
5 | 5 |
6 import os | 6 import os |
7 import sys | 7 import sys |
8 import subprocess | 8 import subprocess |
9 import unittest | 9 import unittest |
10 | 10 |
11 def runprog(*args): | 11 def runprog(*args): |
12 """Runs specified program and args, returns (exitcode, stdout, stderr).""" | 12 """Runs specified program and args, returns (exitcode, stdout, stderr).""" |
13 p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 13 p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
14 out, err = p.communicate() | 14 out, err = p.communicate() |
15 return (p.returncode, out, err) | 15 return (p.returncode, out, err) |
16 | 16 |
17 | 17 |
18 class TestBmpBlock(unittest.TestCase): | 18 class TestBmpBlock(unittest.TestCase): |
19 | 19 |
20 def testNoArgs(self): | 20 def testNoArgs(self): |
21 """Running with no args should print usage and fail.""" | 21 """Running with no args should print usage and fail.""" |
22 rc, out, err = runprog(prog) | 22 rc, out, err = runprog(prog) |
23 self.assertNotEqual(0, rc) | 23 self.assertNotEqual(0, rc) |
24 self.assertTrue(out.count("Usage:")) | 24 self.assertTrue(err.count("missing BMPBLOCK name")) |
| 25 self.assertTrue(out.count("bmpblk_utility")) |
25 | 26 |
26 def testMissingBmp(self): | 27 def testMissingBmp(self): |
27 """Missing a bmp specified in the yaml is an error.""" | 28 """Missing a bmp specified in the yaml is an error.""" |
28 rc, out, err = runprog(prog, '-c', '-C', 'case_nobmp.yaml', 'FOO') | 29 rc, out, err = runprog(prog, '-c', 'case_nobmp.yaml', 'FOO') |
29 self.assertNotEqual(0, rc) | 30 self.assertNotEqual(0, rc) |
30 self.assertTrue(err.count("No such file or directory")) | 31 self.assertTrue(err.count("No such file or directory")) |
31 | 32 |
32 def testInvalidBmp(self): | 33 def testInvalidBmp(self): |
33 """A .bmp file that isn't really a BMP should fail.""" | 34 """A .bmp file that isn't really a BMP should fail.""" |
34 rc, out, err = runprog(prog, '-c', '-C', 'case_badbmp.yaml', 'FOO') | 35 rc, out, err = runprog(prog, '-c', 'case_badbmp.yaml', 'FOO') |
35 self.assertNotEqual(0, rc) | 36 self.assertNotEqual(0, rc) |
36 self.assertTrue(err.count("Unsupported image format")) | 37 self.assertTrue(err.count("Unsupported image format")) |
37 | 38 |
38 | 39 |
39 # Run these tests | 40 # Run these tests |
40 if __name__ == '__main__': | 41 if __name__ == '__main__': |
41 varname = 'BMPBLK' | 42 varname = 'BMPBLK' |
42 if varname not in os.environ: | 43 if varname not in os.environ: |
43 print('You must specify the path to bmpblk_utility in the $%s ' | 44 print('You must specify the path to bmpblk_utility in the $%s ' |
44 'environment variable.' % varname) | 45 'environment variable.' % varname) |
45 sys.exit(1) | 46 sys.exit(1) |
46 prog = os.environ[varname] | 47 prog = os.environ[varname] |
47 print "Testing prog...", prog | 48 print "Testing prog...", prog |
48 unittest.main() | 49 unittest.main() |
49 | 50 |
OLD | NEW |