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 # pylint: disable=protected-access | |
7 | |
8 import logging | |
9 import sys | |
10 import unittest | |
11 | |
12 from devil import devil_env | |
13 | |
14 _sys_path_before = list(sys.path) | |
15 with devil_env.SysPath(devil_env.PYMOCK_PATH): | |
16 _sys_path_with_pymock = list(sys.path) | |
17 import mock # pylint: disable=import-error | |
18 _sys_path_after = list(sys.path) | |
19 | |
20 class DevilEnvTest(unittest.TestCase): | |
21 | |
22 def testSysPath(self): | |
23 self.assertEquals(_sys_path_before, _sys_path_after) | |
24 self.assertEquals( | |
25 _sys_path_before + [devil_env.PYMOCK_PATH], | |
26 _sys_path_with_pymock) | |
27 | |
28 def testGetEnvironmentVariableConfig_configType(self): | |
29 with mock.patch('os.environ.get', | |
30 mock.Mock(side_effect=lambda _env_var: None)): | |
31 env_config = devil_env._GetEnvironmentVariableConfig() | |
32 self.assertEquals('BaseConfig', env_config.get('config_type')) | |
33 | |
34 def testGetEnvironmentVariableConfig_noEnv(self): | |
35 with mock.patch('os.environ.get', | |
36 mock.Mock(side_effect=lambda _env_var: None)): | |
37 env_config = devil_env._GetEnvironmentVariableConfig() | |
38 self.assertEquals({}, env_config.get('dependencies')) | |
39 | |
40 def testGetEnvironmentVariableConfig_adbPath(self): | |
41 def mock_environment(env_var): | |
42 return '/my/fake/adb/path' if env_var == 'ADB_PATH' else None | |
43 | |
44 with mock.patch('os.environ.get', | |
45 mock.Mock(side_effect=mock_environment)): | |
46 env_config = devil_env._GetEnvironmentVariableConfig() | |
47 self.assertEquals( | |
48 { | |
49 'adb': { | |
50 'file_info': { | |
51 'linux2_x86_64': { | |
52 'local_paths': ['/my/fake/adb/path'], | |
53 }, | |
54 }, | |
55 }, | |
56 }, | |
57 env_config.get('dependencies')) | |
58 | |
59 | |
60 if __name__ == '__main__': | |
61 logging.getLogger().setLevel(logging.DEBUG) | |
62 unittest.main(verbosity=2) | |
OLD | NEW |