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

Side by Side Diff: native_client_sdk/src/tools/tests/nacl_config_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 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 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 sys 7 import sys
8 import unittest 8 import unittest
9 9
10 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) 10 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
11 TOOLS_DIR = os.path.dirname(SCRIPT_DIR) 11 TOOLS_DIR = os.path.dirname(SCRIPT_DIR)
12 CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(TOOLS_DIR))) 12 CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(TOOLS_DIR)))
13 MOCK_DIR = os.path.join(CHROME_SRC, "third_party", "pymock") 13 MOCK_DIR = os.path.join(CHROME_SRC, 'third_party', 'pymock')
14 14
15 # For the mock library 15 # For the mock library
16 sys.path.append(MOCK_DIR) 16 sys.path.append(MOCK_DIR)
17 import mock 17 import mock
18 18
19 # For nacl_config, the module under test 19 # For nacl_config, the module under test
20 sys.path.append(TOOLS_DIR) 20 sys.path.append(TOOLS_DIR)
21 import nacl_config 21 import nacl_config
22 22
23 23
24 class TestNaclConfig(unittest.TestCase): 24 class TestNaclConfig(unittest.TestCase):
25 def setUp(self): 25 def setUp(self):
26 self.patches = [] 26 self.patches = []
27 27
28 get_sdk_path = self.AddAndStartPatch('getos.GetSDKPath') 28 get_sdk_path = self.AddAndStartPatch('getos.GetSDKPath')
29 get_sdk_path.return_value = '/sdk_root' 29 get_sdk_path.return_value = '/sdk_root'
30 30
31 get_platform = self.AddAndStartPatch('getos.GetPlatform') 31 get_platform = self.AddAndStartPatch('getos.GetPlatform')
32 get_platform.return_value = 'mac' 32 get_platform.return_value = 'mac'
33 33
34 def tearDown(self): 34 def tearDown(self):
35 for patch in self.patches: 35 for patch in self.patches:
36 patch.stop() 36 patch.stop()
37 37
38 def AddAndStartPatch(self, name): 38 def AddAndStartPatch(self, name):
39 patch = mock.patch(name) 39 patch = mock.patch(name)
40 self.patches.append(patch) 40 self.patches.append(patch)
41 return patch.start() 41 return patch.start()
42 42
43 @mock.patch('nacl_config.GetCFlags')
44 def testMainArgParsing(self, mock_get_cflags):
45 mock_get_cflags.return_value = 'flags'
46 with mock.patch('sys.stdout'):
47 nacl_config.main(['--cflags'])
48 mock_get_cflags.assert_called()
49
43 def testCFlags(self): 50 def testCFlags(self):
44 cases = { 51 cases = {
45 'newlib': '-I/sdk_root/include -I/sdk_root/include/newlib', 52 'newlib': '-I/sdk_root/include -I/sdk_root/include/newlib',
46 'glibc': '-I/sdk_root/include -I/sdk_root/include/glibc', 53 'glibc': '-I/sdk_root/include -I/sdk_root/include/glibc',
47 'pnacl': '-I/sdk_root/include -I/sdk_root/include/pnacl', 54 'pnacl': '-I/sdk_root/include -I/sdk_root/include/pnacl',
48 'win': '-I/sdk_root/include -I/sdk_root/include/win', 55 'win': '-I/sdk_root/include -I/sdk_root/include/win',
49 'mac': '-I/sdk_root/include -I/sdk_root/include/mac', 56 'mac': '-I/sdk_root/include -I/sdk_root/include/mac',
50 'linux': '-I/sdk_root/include -I/sdk_root/include/linux' 57 'linux': '-I/sdk_root/include -I/sdk_root/include/linux'
51 } 58 }
52 for toolchain, expected in cases.iteritems(): 59 for toolchain, expected in cases.iteritems():
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 # We always use the same gdb (it supports multiple toolchains/architectures) 138 # We always use the same gdb (it supports multiple toolchains/architectures)
132 expected = '/sdk_root/toolchain/mac_x86_newlib/bin/x86_64-nacl-gdb' 139 expected = '/sdk_root/toolchain/mac_x86_newlib/bin/x86_64-nacl-gdb'
133 for toolchain in ('newlib', 'glibc', 'pnacl'): 140 for toolchain in ('newlib', 'glibc', 'pnacl'):
134 for arch in ('x86_32', 'x86_64', 'arm'): 141 for arch in ('x86_32', 'x86_64', 'arm'):
135 self.assertEqual(expected, 142 self.assertEqual(expected,
136 nacl_config.GetToolPath(toolchain, arch, 'gdb')) 143 nacl_config.GetToolPath(toolchain, arch, 'gdb'))
137 144
138 145
139 if __name__ == '__main__': 146 if __name__ == '__main__':
140 unittest.main() 147 unittest.main()
OLDNEW
« no previous file with comments | « native_client_sdk/src/tools/tests/httpd_test.py ('k') | native_client_sdk/src/tools/tests/sel_ldr_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698