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

Side by Side Diff: native_client_sdk/src/build_tools/tests/easy_template_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 cStringIO 6 import cStringIO
7 import difflib 7 import difflib
8 import os 8 import os
9 import sys 9 import sys
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)
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')
13 BUILD_TOOLS_DIR = os.path.dirname(SCRIPT_DIR) 16 BUILD_TOOLS_DIR = os.path.dirname(SCRIPT_DIR)
14 17
15 sys.path.append(BUILD_TOOLS_DIR) 18 sys.path.append(BUILD_TOOLS_DIR)
19 sys.path.append(MOCK_DIR)
20
16 import easy_template 21 import easy_template
22 import mock
23
24 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
17 25
18 class EasyTemplateTestCase(unittest.TestCase): 26 class EasyTemplateTestCase(unittest.TestCase):
19 def _RunTest(self, template, expected, template_dict): 27 def _RunTest(self, template, expected, template_dict):
20 src = cStringIO.StringIO(template) 28 src = cStringIO.StringIO(template)
21 dst = cStringIO.StringIO() 29 dst = cStringIO.StringIO()
22 easy_template.RunTemplate(src, dst, template_dict) 30 easy_template.RunTemplate(src, dst, template_dict)
23 if dst.getvalue() != expected: 31 if dst.getvalue() != expected:
24 expected_lines = expected.splitlines(1) 32 expected_lines = expected.splitlines(1)
25 actual_lines = dst.getvalue().splitlines(1) 33 actual_lines = dst.getvalue().splitlines(1)
26 diff = ''.join(difflib.unified_diff( 34 diff = ''.join(difflib.unified_diff(
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 {'name': 'name', 'type': 'std::string'}, 117 {'name': 'name', 'type': 'std::string'},
110 {'name': 'problems', 'type': 'array', 'basetype': 'int', 'size': 99}]}) 118 {'name': 'problems', 'type': 'array', 'basetype': 'int', 'size': 99}]})
111 119
112 def testModulo(self): 120 def testModulo(self):
113 self._RunTest('No expression %', 'No expression %', {}) 121 self._RunTest('No expression %', 'No expression %', {})
114 self._RunTest('% before {{3 + 4}}', '% before 7', {}) 122 self._RunTest('% before {{3 + 4}}', '% before 7', {})
115 self._RunTest('{{2**8}} % after', '256 % after', {}) 123 self._RunTest('{{2**8}} % after', '256 % after', {})
116 self._RunTest('inside {{8 % 3}}', 'inside 2', {}) 124 self._RunTest('inside {{8 % 3}}', 'inside 2', {})
117 self._RunTest('Everywhere % {{8 % 3}} %', 'Everywhere % 2 %', {}) 125 self._RunTest('Everywhere % {{8 % 3}} %', 'Everywhere % 2 %', {})
118 126
127 @mock.patch('easy_template.TemplateToPython')
128 @mock.patch('sys.stdout', mock.Mock())
129 def testMainArgParsing(self, mock_template_to_python):
130 easy_template.main([__file__])
131 mock_template_to_python.assert_called()
132
119 133
120 if __name__ == '__main__': 134 if __name__ == '__main__':
121 unittest.main() 135 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698