Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Side by Side Diff: lib/cros_build_lib_unittest.py

Issue 6579048: Reintroduce RunCommand cleanup and unit tests. Fixed previous issue, and (Closed) Base URL: http://git.chromium.org/git/crosutils.git@master
Patch Set: Remove bogus whitespace. Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« lib/cros_build_lib.py ('K') | « lib/cros_build_lib.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 """Unit tests for cros_build_lib."""
8
9 import unittest
10
11 import cros_build_lib
12
13 class CrosBuildLibTest(unittest.TestCase):
14 """Test class for cros_build_lib."""
15
16 def testRunCommandSimple(self):
17 """Test that RunCommand can run a simple successful command."""
18 result = cros_build_lib.RunCommand(['ls'],
19 # Keep the test quiet options
20 print_cmd=False,
21 redirect_stdout=True,
22 redirect_stderr=True,
23 # Test specific options
24 exit_code=True)
25 self.assertEqual(result, 0)
26
27 def testRunCommandError(self):
28 """Test that RunCommand can return an error code for a failed command."""
29 result = cros_build_lib.RunCommand(['ls', '/nosuchdir'],
30 # Keep the test quiet options
31 print_cmd=False,
32 redirect_stdout=True,
33 redirect_stderr=True,
34 # Test specific options
35 exit_code=True)
36 self.assertNotEqual(result, 0)
37 self.assertEquals(type(result), int)
38
39 def testRunCommandErrorRetries(self):
40 """Test that RunCommand can retry a failed command that always fails."""
41
42 # We don't actually check that it's retrying, just exercise the code path.
43 result = cros_build_lib.RunCommand(['ls', '/nosuchdir'],
44 # Keep the test quiet options
45 print_cmd=False,
46 redirect_stdout=True,
47 redirect_stderr=True,
48 # Test specific options
49 num_retries=2,
50 error_ok=True,
51 exit_code=True)
52 self.assertNotEqual(result, 0)
53 self.assertEquals(type(result), int)
54
55 def testRunCommandErrorException(self):
56 """Test that RunCommand can throw an exception when a command fails."""
57
58 function = lambda : cros_build_lib.RunCommand(['ls', '/nosuchdir'],
59 # Keep the test quiet options
60 print_cmd=False,
61 redirect_stdout=True,
62 redirect_stderr=True)
63 self.assertRaises(cros_build_lib.RunCommandException, function)
64
65 def testRunCommandErrorCodeNoException(self):
66 """Test that RunCommand doesn't throw an exception with exit_code."""
67
68 result = cros_build_lib.RunCommand(['ls', '/nosuchdir'],
69 # Keep the test quiet options
70 print_cmd=False,
71 redirect_stdout=True,
72 redirect_stderr=True,
73 # Test specific options
74 exit_code=True)
75 # We are really testing that it doesn't throw an exception if exit_code
76 # if true.
77 self.assertNotEqual(result, 0)
78 self.assertEquals(type(result), int)
79
80 def testRunCommandCaptureOutput(self):
81 """Test that RunCommand can capture stdout if a command succeeds."""
82
83 result = cros_build_lib.RunCommand(['echo', '-n', 'Hi'],
84 # Keep the test quiet options
85 print_cmd=False,
86 redirect_stdout=True,
87 redirect_stderr=True)
88 self.assertEqual(result, 'Hi')
89
90
91 if __name__ == '__main__':
92 unittest.main()
OLDNEW
« lib/cros_build_lib.py ('K') | « lib/cros_build_lib.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698