OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Unit tests for cros_build_lib.""" | 7 """Unit tests for cros_build_lib.""" |
8 | 8 |
| 9 import os |
| 10 import tempfile |
9 import unittest | 11 import unittest |
10 | 12 |
11 import cros_build_lib | 13 import cros_build_lib |
12 | 14 |
13 class CrosBuildLibTest(unittest.TestCase): | 15 class CrosBuildLibTest(unittest.TestCase): |
14 """Test class for cros_build_lib.""" | 16 """Test class for cros_build_lib.""" |
15 | 17 |
16 def testRunCommandSimple(self): | 18 def testRunCommandSimple(self): |
17 """Test that RunCommand can run a simple successful command.""" | 19 """Test that RunCommand can run a simple successful command.""" |
18 result = cros_build_lib.RunCommand(['ls'], | 20 result = cros_build_lib.RunCommand(['ls'], |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 def testRunCommandCaptureOutput(self): | 82 def testRunCommandCaptureOutput(self): |
81 """Test that RunCommand can capture stdout if a command succeeds.""" | 83 """Test that RunCommand can capture stdout if a command succeeds.""" |
82 | 84 |
83 result = cros_build_lib.RunCommand(['echo', '-n', 'Hi'], | 85 result = cros_build_lib.RunCommand(['echo', '-n', 'Hi'], |
84 # Keep the test quiet options | 86 # Keep the test quiet options |
85 print_cmd=False, | 87 print_cmd=False, |
86 redirect_stdout=True, | 88 redirect_stdout=True, |
87 redirect_stderr=True) | 89 redirect_stderr=True) |
88 self.assertEqual(result, 'Hi') | 90 self.assertEqual(result, 'Hi') |
89 | 91 |
| 92 def testRunCommandLogToFile(self): |
| 93 """Test that RunCommand can log output to a file correctly.""" |
| 94 log_file = tempfile.mktemp() |
| 95 cros_build_lib.RunCommand(['echo', '-n', 'Hi'], |
| 96 # Keep the test quiet options |
| 97 print_cmd=False, |
| 98 # Test specific options |
| 99 log_to_file=log_file) |
| 100 log_fh = open(log_file) |
| 101 log_data = log_fh.read() |
| 102 self.assertEquals('Hi', log_data) |
| 103 log_fh.close() |
| 104 os.remove(log_file) |
| 105 |
90 | 106 |
91 if __name__ == '__main__': | 107 if __name__ == '__main__': |
92 unittest.main() | 108 unittest.main() |
OLD | NEW |