| 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 mox |
| 9 import os | 10 import os |
| 10 import tempfile | 11 import tempfile |
| 11 import unittest | 12 import unittest |
| 12 | 13 |
| 13 import cros_build_lib | 14 import cros_build_lib |
| 14 | 15 |
| 15 class CrosBuildLibTest(unittest.TestCase): | 16 class CrosBuildLibTest(mox.MoxTestBase): |
| 16 """Test class for cros_build_lib.""" | 17 """Test class for cros_build_lib.""" |
| 17 | 18 |
| 18 def testRunCommandSimple(self): | 19 def testRunCommandSimple(self): |
| 19 """Test that RunCommand can run a simple successful command.""" | 20 """Test that RunCommand can run a simple successful command.""" |
| 20 result = cros_build_lib.RunCommand(['ls'], | 21 result = cros_build_lib.RunCommand(['ls'], |
| 21 # Keep the test quiet options | 22 # Keep the test quiet options |
| 22 print_cmd=False, | 23 print_cmd=False, |
| 23 redirect_stdout=True, | 24 redirect_stdout=True, |
| 24 redirect_stderr=True, | 25 redirect_stderr=True, |
| 25 # Test specific options | 26 # Test specific options |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 # Keep the test quiet options | 97 # Keep the test quiet options |
| 97 print_cmd=False, | 98 print_cmd=False, |
| 98 # Test specific options | 99 # Test specific options |
| 99 log_to_file=log_file) | 100 log_to_file=log_file) |
| 100 log_fh = open(log_file) | 101 log_fh = open(log_file) |
| 101 log_data = log_fh.read() | 102 log_data = log_fh.read() |
| 102 self.assertEquals('Hi', log_data) | 103 self.assertEquals('Hi', log_data) |
| 103 log_fh.close() | 104 log_fh.close() |
| 104 os.remove(log_file) | 105 os.remove(log_file) |
| 105 | 106 |
| 107 def testGetCrosUtilsPathInChroot(self): |
| 108 """Tests whether we can get crosutils from chroot.""" |
| 109 self.mox.StubOutWithMock(cros_build_lib, 'IsInsideChroot') |
| 110 crosutils_path_src = '/home/' + os.getenv('USER') + 'trunk/src/scripts' |
| 111 crosutils_path_installed = '/usr/lib/crosutils' |
| 112 |
| 113 cros_build_lib.IsInsideChroot().MultipleTimes().AndReturn(True) |
| 114 |
| 115 self.mox.ReplayAll() |
| 116 self.assertTrue(cros_build_lib.GetCrosUtilsPath(from_source=True), |
| 117 crosutils_path_src) |
| 118 self.assertTrue(cros_build_lib.GetCrosUtilsPath(from_source=False), |
| 119 crosutils_path_installed) |
| 120 self.mox.VerifyAll() |
| 121 |
| 122 def testGetCrosUtilsPathInChroot(self): |
| 123 """Tests whether we can get crosutils from outside chroot.""" |
| 124 self.mox.StubOutWithMock(cros_build_lib, 'IsInsideChroot') |
| 125 path = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..') |
| 126 cros_build_lib.IsInsideChroot().MultipleTimes().AndReturn(False) |
| 127 |
| 128 self.mox.ReplayAll() |
| 129 self.assertTrue(cros_build_lib.GetCrosUtilsPath(), path) |
| 130 self.mox.VerifyAll() |
| 131 |
| 106 | 132 |
| 107 if __name__ == '__main__': | 133 if __name__ == '__main__': |
| 108 unittest.main() | 134 unittest.main() |
| OLD | NEW |