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

Side by Side Diff: native_client_sdk/src/tools/tests/getos_test.py

Issue 720233003: [NaCl SDK] Convert python scripts from optparse to argparse. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
OLDNEW
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
11 11
12 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) 12 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
13 TOOLS_DIR = os.path.dirname(SCRIPT_DIR) 13 TOOLS_DIR = os.path.dirname(SCRIPT_DIR)
14 CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(TOOLS_DIR))) 14 CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(TOOLS_DIR)))
15 MOCK_DIR = os.path.join(CHROME_SRC, "third_party", "pymock") 15 MOCK_DIR = os.path.join(CHROME_SRC, 'third_party', 'pymock')
16 16
17 # For the mock library 17 # For the mock library
18 sys.path.append(MOCK_DIR) 18 sys.path.append(MOCK_DIR)
19 import mock 19 import mock
20 20
21 # For getos, the module under test 21 # For getos, the module under test
22 sys.path.append(TOOLS_DIR) 22 sys.path.append(TOOLS_DIR)
23 import getos 23 import getos
24 import oshelpers 24 import oshelpers
25 25
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 platform = getos.GetPlatform() 96 platform = getos.GetPlatform()
97 # Since the unix implementation of GetNaClArch will run objdump on the 97 # Since the unix implementation of GetNaClArch will run objdump on the
98 # chrome binary, and we want to be able to run this test without chrome 98 # chrome binary, and we want to be able to run this test without chrome
99 # installed we mock the GetChromePath call to return a known system binary, 99 # installed we mock the GetChromePath call to return a known system binary,
100 # which objdump will work with. 100 # which objdump will work with.
101 with mock.patch('getos.GetChromePath') as mock_chrome_path: 101 with mock.patch('getos.GetChromePath') as mock_chrome_path:
102 mock_chrome_path.return_value = '/bin/ls' 102 mock_chrome_path.return_value = '/bin/ls'
103 arch = getos.GetNaClArch(platform) 103 arch = getos.GetNaClArch(platform)
104 self.assertIn(arch, ('x86_64', 'x86_32', 'arm')) 104 self.assertIn(arch, ('x86_64', 'x86_32', 'arm'))
105 105
106 def testMainInvalidArgs(self):
107 with self.assertRaises(SystemExit):
108 with mock.patch('sys.stderr'):
109 getos.main('--foo')
110
111 @mock.patch('sys.stdout', mock.Mock())
112 @mock.patch('getos.GetPlatform')
113 def testMainNoArgs(self, mock_get_platform):
114 mock_get_platform.return_value = 'platform'
115 getos.main([])
116
117 @mock.patch('sys.stdout', mock.Mock())
118 @mock.patch('getos.GetSystemArch')
119 def testMainArgsParsing(self, mock_system_arch):
120 mock_system_arch.return_value = 'dummy'
121 getos.main(['--arch'])
122 mock_system_arch.assert_called()
123
106 124
107 class TestGetosWithTempdir(TestCaseExtended): 125 class TestGetosWithTempdir(TestCaseExtended):
108 def setUp(self): 126 def setUp(self):
109 self.tempdir = tempfile.mkdtemp("_sdktest") 127 self.tempdir = tempfile.mkdtemp("_sdktest")
110 self.patch = mock.patch.dict('os.environ', 128 self.patch = mock.patch.dict('os.environ',
111 {'NACL_SDK_ROOT': self.tempdir}) 129 {'NACL_SDK_ROOT': self.tempdir})
112 self.patch.start() 130 self.patch.start()
113 131
114 def tearDown(self): 132 def tearDown(self):
115 shutil.rmtree(self.tempdir) 133 shutil.rmtree(self.tempdir)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 required_version = (17, 50) 176 required_version = (17, 50)
159 self.assertRaisesRegexp( 177 self.assertRaisesRegexp(
160 getos.Error, 178 getos.Error,
161 r'SDK version too old \(current: 16.100, required: 17.50\)', 179 r'SDK version too old \(current: 16.100, required: 17.50\)',
162 getos.CheckVersion, 180 getos.CheckVersion,
163 required_version) 181 required_version)
164 182
165 183
166 if __name__ == '__main__': 184 if __name__ == '__main__':
167 unittest.main() 185 unittest.main()
OLDNEW
« no previous file with comments | « native_client_sdk/src/tools/tests/fix_deps_test.py ('k') | native_client_sdk/src/tools/tests/httpd_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698