OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 """ | 6 """ |
7 Unit tests for the contents of shared_prefs.py (mostly SharedPrefs). | 7 Unit tests for the contents of shared_prefs.py (mostly SharedPrefs). |
8 """ | 8 """ |
9 | 9 |
10 import logging | 10 import logging |
11 import os | |
12 import sys | 11 import sys |
13 import unittest | 12 import unittest |
14 | 13 |
| 14 from devil import devil_env |
15 from devil.android import device_utils | 15 from devil.android import device_utils |
16 from devil.android.sdk import shared_prefs | 16 from devil.android.sdk import shared_prefs |
17 from pylib import constants | |
18 | 17 |
19 sys.path.append(os.path.join( | 18 sys.path.append(devil_env.config.pymock_path) |
20 constants.DIR_SOURCE_ROOT, 'third_party', 'pymock')) | |
21 import mock # pylint: disable=import-error | 19 import mock # pylint: disable=import-error |
22 | 20 |
23 | 21 |
24 def MockDeviceWithFiles(files=None): | 22 def MockDeviceWithFiles(files=None): |
25 if files is None: | 23 if files is None: |
26 files = {} | 24 files = {} |
27 | 25 |
28 def file_exists(path): | 26 def file_exists(path): |
29 return path in files | 27 return path in files |
30 | 28 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 158 |
161 self.assertEquals(self.device.WriteFile.call_args_list, []) # did not write | 159 self.assertEquals(self.device.WriteFile.call_args_list, []) # did not write |
162 with shared_prefs.SharedPrefs( | 160 with shared_prefs.SharedPrefs( |
163 self.device, 'com.some.package', 'prefs.xml') as prefs: | 161 self.device, 'com.some.package', 'prefs.xml') as prefs: |
164 # contents were not modified | 162 # contents were not modified |
165 self.assertEquals(prefs.AsDict(), self.expected_data) | 163 self.assertEquals(prefs.AsDict(), self.expected_data) |
166 | 164 |
167 if __name__ == '__main__': | 165 if __name__ == '__main__': |
168 logging.getLogger().setLevel(logging.DEBUG) | 166 logging.getLogger().setLevel(logging.DEBUG) |
169 unittest.main(verbosity=2) | 167 unittest.main(verbosity=2) |
OLD | NEW |