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 30 matching lines...) Expand all Loading... |
41 self.patch1.start() | 41 self.patch1.start() |
42 self.patch2 = mock.patch.object(oshelpers, 'FindExeInPath', | 42 self.patch2 = mock.patch.object(oshelpers, 'FindExeInPath', |
43 return_value='/bin/ls') | 43 return_value='/bin/ls') |
44 self.patch2.start() | 44 self.patch2.start() |
45 | 45 |
46 def tearDown(self): | 46 def tearDown(self): |
47 self.patch1.stop() | 47 self.patch1.stop() |
48 self.patch2.stop() | 48 self.patch2.stop() |
49 | 49 |
50 def testGetSDKPath(self): | 50 def testGetSDKPath(self): |
51 """honors enironment variable.""" | 51 """honors environment variable.""" |
52 with mock.patch.dict('os.environ', {'NACL_SDK_ROOT': 'dummy'}): | 52 with mock.patch.dict('os.environ', {'NACL_SDK_ROOT': 'dummy'}): |
53 self.assertEqual(getos.GetSDKPath(), 'dummy') | 53 self.assertEqual(getos.GetSDKPath(), 'dummy') |
54 | 54 |
55 def testGetSDKPathDefault(self): | 55 def testGetSDKPathDefault(self): |
56 """defaults to relative path.""" | 56 """defaults to relative path.""" |
57 del os.environ['NACL_SDK_ROOT'] | 57 del os.environ['NACL_SDK_ROOT'] |
58 self.assertEqual(getos.GetSDKPath(), os.path.dirname(TOOLS_DIR)) | 58 self.assertEqual(getos.GetSDKPath(), os.path.dirname(TOOLS_DIR)) |
59 | 59 |
60 def testGetPlatform(self): | 60 def testGetPlatform(self): |
61 """returns a valid platform.""" | 61 """returns a valid platform.""" |
62 platform = getos.GetPlatform() | 62 platform = getos.GetPlatform() |
63 self.assertIn(platform, ('mac', 'linux', 'win')) | 63 self.assertIn(platform, ('mac', 'linux', 'win')) |
64 | 64 |
65 def testGetSystemArch(self): | 65 def testGetSystemArch(self): |
66 """returns a valid architecuture.""" | 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 if hasattr(self, 'assertRaisesRegexp'): | 74 if hasattr(self, 'assertRaisesRegexp'): |
75 with self.assertRaisesRegexp(getos.Error, expect): | 75 with self.assertRaisesRegexp(getos.Error, expect): |
76 getos.GetChromePath() | 76 getos.GetChromePath() |
77 else: | 77 else: |
78 # TODO(sbc): remove this path once we switch to python2.7 everywhere | 78 # TODO(sbc): remove this path once we switch to python2.7 everywhere |
79 self.assertRaises(getos.Error, getos.GetChromePath) | 79 self.assertRaises(getos.Error, getos.GetChromePath) |
80 | 80 |
81 def testGetChromePathCheckExists(self): | 81 def testGetChromePathCheckExists(self): |
82 """checks that existence of explictly CHROME_PATH is checked.""" | 82 """checks that existence of explicitly CHROME_PATH is checked.""" |
83 mock_location = '/bin/ls' | 83 mock_location = '/bin/ls' |
84 if getos.GetPlatform() == 'win': | 84 if getos.GetPlatform() == 'win': |
85 mock_location = 'c:\\nowhere' | 85 mock_location = 'c:\\nowhere' |
86 with mock.patch.dict('os.environ', {'CHROME_PATH': mock_location}): | 86 with mock.patch.dict('os.environ', {'CHROME_PATH': mock_location}): |
87 with mock.patch('os.path.exists') as mock_exists: | 87 with mock.patch('os.path.exists') as mock_exists: |
88 chrome = getos.GetChromePath() | 88 chrome = getos.GetChromePath() |
89 self.assertEqual(chrome, mock_location) | 89 self.assertEqual(chrome, mock_location) |
90 mock_exists.assert_called_with(chrome) | 90 mock_exists.assert_called_with(chrome) |
91 | 91 |
92 def testGetHelperPath(self): | 92 def testGetHelperPath(self): |
(...skipping 17 matching lines...) Expand all Loading... |
110 mock_exists.assert_called_with(irt) | 110 mock_exists.assert_called_with(irt) |
111 | 111 |
112 def testGetLoaderPath(self): | 112 def testGetLoaderPath(self): |
113 """checks that loader exists.""" | 113 """checks that loader exists.""" |
114 platform = getos.GetPlatform() | 114 platform = getos.GetPlatform() |
115 with mock.patch('os.path.exists') as mock_exists: | 115 with mock.patch('os.path.exists') as mock_exists: |
116 loader = getos.GetLoaderPath(platform) | 116 loader = getos.GetLoaderPath(platform) |
117 mock_exists.assert_called_with(loader) | 117 mock_exists.assert_called_with(loader) |
118 | 118 |
119 def testGetNaClArch(self): | 119 def testGetNaClArch(self): |
120 """returns a valid architecuture.""" | 120 """returns a valid architecture.""" |
121 platform = getos.GetPlatform() | 121 platform = getos.GetPlatform() |
122 # Since the unix implementation of GetNaClArch will run objdump on the | 122 # Since the unix implementation of GetNaClArch will run objdump on the |
123 # chrome binary, and we want to be able to run this test without chrome | 123 # chrome binary, and we want to be able to run this test without chrome |
124 # installed we mock the GetChromePath call to return a known system binary, | 124 # installed we mock the GetChromePath call to return a known system binary, |
125 # which objdump will work with. | 125 # which objdump will work with. |
126 with mock.patch('getos.GetChromePath') as mock_chrome_path: | 126 with mock.patch('getos.GetChromePath') as mock_chrome_path: |
127 mock_chrome_path.return_value = '/bin/ls' | 127 mock_chrome_path.return_value = '/bin/ls' |
128 arch = getos.GetNaClArch(platform) | 128 arch = getos.GetNaClArch(platform) |
129 self.assertIn(arch, ('x86_64', 'x86_32', 'arm')) | 129 self.assertIn(arch, ('x86_64', 'x86_32', 'arm')) |
130 | 130 |
(...skipping 15 matching lines...) Expand all Loading... |
146 with open(os.path.join(self.tempdir, 'README'), 'w') as out: | 146 with open(os.path.join(self.tempdir, 'README'), 'w') as out: |
147 out.write('Version: %s\n' % expected_version[0]) | 147 out.write('Version: %s\n' % expected_version[0]) |
148 out.write('Revision: %s\n' % expected_version[1]) | 148 out.write('Revision: %s\n' % expected_version[1]) |
149 | 149 |
150 version = getos.GetSDKVersion() | 150 version = getos.GetSDKVersion() |
151 self.assertEqual(version, expected_version) | 151 self.assertEqual(version, expected_version) |
152 | 152 |
153 | 153 |
154 if __name__ == '__main__': | 154 if __name__ == '__main__': |
155 unittest.main() | 155 unittest.main() |
OLD | NEW |