| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import os | 6 import os |
| 7 import shutil | 7 import shutil |
| 8 import sys | 8 import sys |
| 9 import tempfile | 9 import tempfile |
| 10 import unittest | 10 import unittest |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 def testGetSystemArch(self): | 65 def testGetSystemArch(self): |
| 66 """returns a valid architecture.""" | 66 """returns a valid architecture.""" |
| 67 arch = getos.GetSystemArch(getos.GetPlatform()) | 67 arch = getos.GetSystemArch(getos.GetPlatform()) |
| 68 self.assertIn(arch, ('x86_64', 'x86_32', 'arm')) | 68 self.assertIn(arch, ('x86_64', 'x86_32', 'arm')) |
| 69 | 69 |
| 70 def testGetChromePathEnv(self): | 70 def testGetChromePathEnv(self): |
| 71 """honors CHROME_PATH environment.""" | 71 """honors CHROME_PATH environment.""" |
| 72 with mock.patch.dict('os.environ', {'CHROME_PATH': '/dummy/file'}): | 72 with mock.patch.dict('os.environ', {'CHROME_PATH': '/dummy/file'}): |
| 73 expect = "Invalid CHROME_PATH.*/dummy/file" | 73 expect = "Invalid CHROME_PATH.*/dummy/file" |
| 74 platform = getos.GetPlatform() |
| 74 if hasattr(self, 'assertRaisesRegexp'): | 75 if hasattr(self, 'assertRaisesRegexp'): |
| 75 with self.assertRaisesRegexp(getos.Error, expect): | 76 with self.assertRaisesRegexp(getos.Error, expect): |
| 76 getos.GetChromePath() | 77 getos.GetChromePath(platform) |
| 77 else: | 78 else: |
| 78 # TODO(sbc): remove this path once we switch to python2.7 everywhere | 79 # TODO(sbc): remove this path once we switch to python2.7 everywhere |
| 79 self.assertRaises(getos.Error, getos.GetChromePath) | 80 self.assertRaises(getos.Error, getos.GetChromePath, platform) |
| 80 | 81 |
| 81 def testGetChromePathCheckExists(self): | 82 def testGetChromePathCheckExists(self): |
| 82 """checks that existence of explicitly CHROME_PATH is checked.""" | 83 """checks that existence of explicitly CHROME_PATH is checked.""" |
| 83 mock_location = '/bin/ls' | 84 mock_location = '/bin/ls' |
| 84 if getos.GetPlatform() == 'win': | 85 platform = getos.GetPlatform() |
| 86 if platform == 'win': |
| 85 mock_location = 'c:\\nowhere' | 87 mock_location = 'c:\\nowhere' |
| 86 with mock.patch.dict('os.environ', {'CHROME_PATH': mock_location}): | 88 with mock.patch.dict('os.environ', {'CHROME_PATH': mock_location}): |
| 87 with mock.patch('os.path.exists') as mock_exists: | 89 with mock.patch('os.path.exists') as mock_exists: |
| 88 chrome = getos.GetChromePath() | 90 chrome = getos.GetChromePath(platform) |
| 89 self.assertEqual(chrome, mock_location) | 91 self.assertEqual(chrome, mock_location) |
| 90 mock_exists.assert_called_with(chrome) | 92 mock_exists.assert_called_with(chrome) |
| 91 | 93 |
| 92 def testGetHelperPath(self): | 94 def testGetHelperPath(self): |
| 93 """GetHelperPath checks that helper exists.""" | 95 """GetHelperPath checks that helper exists.""" |
| 94 platform = getos.GetPlatform() | 96 platform = getos.GetPlatform() |
| 95 # The helper is only needed on linux. On other platforms | 97 # The helper is only needed on linux. On other platforms |
| 96 # GetHelperPath() simply return empty string. | 98 # GetHelperPath() simply return empty string. |
| 97 if platform == 'linux': | 99 if platform == 'linux': |
| 98 with mock.patch('os.path.exists') as mock_exists: | 100 with mock.patch('os.path.exists') as mock_exists: |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 with open(os.path.join(self.tempdir, 'README'), 'w') as out: | 148 with open(os.path.join(self.tempdir, 'README'), 'w') as out: |
| 147 out.write('Version: %s\n' % expected_version[0]) | 149 out.write('Version: %s\n' % expected_version[0]) |
| 148 out.write('Chrome Revision: %s\n' % expected_version[1]) | 150 out.write('Chrome Revision: %s\n' % expected_version[1]) |
| 149 | 151 |
| 150 version = getos.GetSDKVersion() | 152 version = getos.GetSDKVersion() |
| 151 self.assertEqual(version, expected_version) | 153 self.assertEqual(version, expected_version) |
| 152 | 154 |
| 153 | 155 |
| 154 if __name__ == '__main__': | 156 if __name__ == '__main__': |
| 155 unittest.main() | 157 unittest.main() |
| OLD | NEW |