Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 import os | |
| 7 import sys | |
| 8 import unittest | |
| 9 | |
| 10 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) | |
| 11 SRC_DIR = os.path.dirname(SCRIPT_DIR) | |
| 12 | |
| 13 sys.path.append(os.path.join(SRC_DIR, 'third_party', 'pymock')) | |
| 14 | |
| 15 import mock | |
| 16 | |
| 17 # TODO(sbc): Make gyp_chromium more testable by putting the code in | |
| 18 # a .py file. | |
| 19 gyp_chromium = __import__('gyp_chromium') | |
|
scottmg
2015/02/03 02:09:18
there is a .py because it's required on windows fo
Sam Clegg
2015/02/03 02:10:30
Oh yeah! That is funny/strange. Not importable
| |
| 20 | |
| 21 | |
| 22 class TestGetOutputDirectory(unittest.TestCase): | |
| 23 @mock.patch('os.environ', {}) | |
| 24 @mock.patch('sys.argv', [__file__]) | |
| 25 def testDefaultValue(self): | |
| 26 self.assertEqual(gyp_chromium.GetOutputDirectory(), 'out') | |
| 27 | |
| 28 @mock.patch('os.environ', {'GYP_GENERATOR_FLAGS': 'output_dir=envfoo'}) | |
| 29 @mock.patch('sys.argv', [__file__]) | |
| 30 def testEnvironment(self): | |
| 31 self.assertEqual(gyp_chromium.GetOutputDirectory(), 'envfoo') | |
| 32 | |
| 33 @mock.patch('os.environ', {'GYP_GENERATOR_FLAGS': 'output_dir=envfoo'}) | |
| 34 @mock.patch('sys.argv', [__file__, '-Goutput_dir=cmdfoo']) | |
| 35 def testGFlagOverridesEnv(self): | |
| 36 self.assertEqual(gyp_chromium.GetOutputDirectory(), 'cmdfoo') | |
| 37 | |
| 38 @mock.patch('os.environ', {}) | |
| 39 @mock.patch('sys.argv', [__file__, '-G', 'output_dir=foo']) | |
| 40 def testGFlagWithSpace(self): | |
| 41 self.assertEqual(gyp_chromium.GetOutputDirectory(), 'foo') | |
| 42 | |
| 43 | |
| 44 class TestGetGypVars(unittest.TestCase): | |
| 45 @mock.patch('os.environ', {}) | |
| 46 def testDefault(self): | |
| 47 self.assertEqual(gyp_chromium.GetGypVars([]), {}) | |
| 48 | |
| 49 @mock.patch('os.environ', {}) | |
| 50 @mock.patch('sys.argv', [__file__, '-D', 'foo=bar']) | |
| 51 def testDFlags(self): | |
| 52 self.assertEqual(gyp_chromium.GetGypVars([]), {'foo': 'bar'}) | |
| 53 | |
| 54 @mock.patch('os.environ', {}) | |
| 55 @mock.patch('sys.argv', [__file__, '-D', 'foo']) | |
| 56 def testDFlagsNoValue(self): | |
| 57 self.assertEqual(gyp_chromium.GetGypVars([]), {'foo': '1'}) | |
| 58 | |
| 59 @mock.patch('os.environ', {}) | |
| 60 @mock.patch('sys.argv', [__file__, '-D', 'foo=bar', '-Dbaz']) | |
| 61 def testDFlagMulti(self): | |
| 62 self.assertEqual(gyp_chromium.GetGypVars([]), {'foo': 'bar', 'baz': '1'}) | |
| 63 | |
| 64 | |
| 65 if __name__ == '__main__': | |
| 66 unittest.main() | |
| OLD | NEW |