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

Side by Side Diff: native_client_sdk/src/tools/tests/create_nmf_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 6 years, 1 month 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 import json 5 import json
6 import os 6 import os
7 import posixpath 7 import posixpath
8 import shutil 8 import shutil
9 import subprocess 9 import subprocess
10 import sys 10 import sys
11 import tempfile 11 import tempfile
12 import unittest 12 import unittest
13 13
14 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) 14 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
15 TOOLS_DIR = os.path.dirname(SCRIPT_DIR) 15 TOOLS_DIR = os.path.dirname(SCRIPT_DIR)
16 DATA_DIR = os.path.join(TOOLS_DIR, 'lib', 'tests', 'data') 16 DATA_DIR = os.path.join(TOOLS_DIR, 'lib', 'tests', 'data')
17 BUILD_TOOLS_DIR = os.path.join(os.path.dirname(TOOLS_DIR), 'build_tools')
17 CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(TOOLS_DIR))) 18 CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(TOOLS_DIR)))
18 MOCK_DIR = os.path.join(CHROME_SRC, 'third_party', 'pymock') 19 MOCK_DIR = os.path.join(CHROME_SRC, 'third_party', 'pymock')
19 20
20 # For the mock library 21 # For the mock library
21 sys.path.append(MOCK_DIR) 22 sys.path.append(MOCK_DIR)
22 sys.path.append(TOOLS_DIR) 23 sys.path.append(TOOLS_DIR)
24 sys.path.append(BUILD_TOOLS_DIR)
23 25
24 import build_paths 26 import build_paths
25 import create_nmf 27 import create_nmf
26 import getos 28 import getos
27 import mock 29 from mock import patch, Mock
28 30
29 TOOLCHAIN_OUT = os.path.join(build_paths.OUT_DIR, 'sdk_tests', 'toolchain') 31 TOOLCHAIN_OUT = os.path.join(build_paths.OUT_DIR, 'sdk_tests', 'toolchain')
30 NACL_X86_GLIBC_TOOLCHAIN = os.path.join(TOOLCHAIN_OUT, 32 NACL_X86_GLIBC_TOOLCHAIN = os.path.join(TOOLCHAIN_OUT,
31 '%s_x86' % getos.GetPlatform(), 33 '%s_x86' % getos.GetPlatform(),
32 'nacl_x86_glibc') 34 'nacl_x86_glibc')
33 35
34 PosixRelPath = create_nmf.PosixRelPath 36 PosixRelPath = create_nmf.PosixRelPath
35 37
36 38
37 def StripSo(name): 39 def StripSo(name):
(...skipping 21 matching lines...) Expand all
59 start = os.path.sep + 'foo' 61 start = os.path.sep + 'foo'
60 self.assertEqual(PosixRelPath(path, start), 'bar/baz.blah') 62 self.assertEqual(PosixRelPath(path, start), 'bar/baz.blah')
61 63
62 64
63 class TestDefaultLibpath(unittest.TestCase): 65 class TestDefaultLibpath(unittest.TestCase):
64 def testWithoutNaClSDKRoot(self): 66 def testWithoutNaClSDKRoot(self):
65 """GetDefaultLibPath wihtout NACL_SDK_ROOT set 67 """GetDefaultLibPath wihtout NACL_SDK_ROOT set
66 68
67 In the absence of NACL_SDK_ROOT GetDefaultLibPath should 69 In the absence of NACL_SDK_ROOT GetDefaultLibPath should
68 return the empty list.""" 70 return the empty list."""
69 with mock.patch.dict('os.environ', clear=True): 71 with patch.dict('os.environ', clear=True):
70 paths = create_nmf.GetDefaultLibPath('Debug') 72 paths = create_nmf.GetDefaultLibPath('Debug')
71 self.assertEqual(paths, []) 73 self.assertEqual(paths, [])
72 74
75 @patch('create_nmf.IsValidSDKRoot', Mock(return_value=True))
binji 2014/11/13 23:57:05 seems unrelated
Sam Clegg 2014/11/30 17:55:14 Done.
73 def testHonorNaClSDKRoot(self): 76 def testHonorNaClSDKRoot(self):
74 with mock.patch.dict('os.environ', {'NACL_SDK_ROOT': '/dummy/path'}): 77 with patch.dict('os.environ', {'NACL_SDK_ROOT': '/dummy/path'}):
75 paths = create_nmf.GetDefaultLibPath('Debug') 78 paths = create_nmf.GetDefaultLibPath('Debug')
76 for path in paths: 79 for path in paths:
77 self.assertTrue(path.startswith('/dummy/path')) 80 self.assertTrue(path.startswith('/dummy/path'))
78 81
82 @patch('create_nmf.IsValidSDKRoot', Mock(return_value=True))
79 def testIncludesNaClPorts(self): 83 def testIncludesNaClPorts(self):
80 with mock.patch.dict('os.environ', {'NACL_SDK_ROOT': '/dummy/path'}): 84 with patch.dict('os.environ', {'NACL_SDK_ROOT': '/dummy/path'}):
81 paths = create_nmf.GetDefaultLibPath('Debug') 85 paths = create_nmf.GetDefaultLibPath('Debug')
82 self.assertTrue(any(os.path.join('ports', 'lib') in p for p in paths), 86 self.assertTrue(any(os.path.join('ports', 'lib') in p for p in paths),
83 "naclports libpath missing: %s" % str(paths)) 87 "naclports libpath missing: %s" % str(paths))
84 88
85 89
86 class TestNmfUtils(unittest.TestCase): 90 class TestNmfUtils(unittest.TestCase):
87 """Tests for the main NmfUtils class in create_nmf.""" 91 """Tests for the main NmfUtils class in create_nmf."""
88 92
89 def setUp(self): 93 def setUp(self):
90 self.tempdir = None 94 self.tempdir = None
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 'optlevel': 0, 601 'optlevel': 0,
598 } 602 }
599 } 603 }
600 } 604 }
601 } 605 }
602 self.assertManifestEquals(nmf, expected_manifest) 606 self.assertManifestEquals(nmf, expected_manifest)
603 607
604 608
605 if __name__ == '__main__': 609 if __name__ == '__main__':
606 unittest.main() 610 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698