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

Side by Side Diff: build/android/devil/android/sdk/shared_prefs_test.py

Issue 1315743004: [Android] Add a custom pylintrc for build/android/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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 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 11 import os
12 import sys 12 import sys
13 import unittest 13 import unittest
14 14
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 17 from pylib import constants
18 18
19 sys.path.append(os.path.join( 19 sys.path.append(os.path.join(
20 constants.DIR_SOURCE_ROOT, 'third_party', 'pymock')) 20 constants.DIR_SOURCE_ROOT, 'third_party', 'pymock'))
21 import mock 21 import mock # pylint: disable=import-error
22 22
23 23
24 def MockDeviceWithFiles(files=None): 24 def MockDeviceWithFiles(files=None):
25 if files is None: 25 if files is None:
26 files = {} 26 files = {}
27 27
28 def file_exists(path): 28 def file_exists(path):
29 return path in files 29 return path in files
30 30
31 # pylint: disable=unused-argument
31 def write_file(path, contents, **_kwargs): 32 def write_file(path, contents, **_kwargs):
32 files[path] = contents 33 files[path] = contents
33 34
35 # pylint: disable=unused-argument
34 def read_file(path, **_kwargs): 36 def read_file(path, **_kwargs):
35 return files[path] 37 return files[path]
36 38
37 device = mock.MagicMock(spec=device_utils.DeviceUtils) 39 device = mock.MagicMock(spec=device_utils.DeviceUtils)
38 device.FileExists = mock.Mock(side_effect=file_exists) 40 device.FileExists = mock.Mock(side_effect=file_exists)
39 device.WriteFile = mock.Mock(side_effect=write_file) 41 device.WriteFile = mock.Mock(side_effect=write_file)
40 device.ReadFile = mock.Mock(side_effect=read_file) 42 device.ReadFile = mock.Mock(side_effect=read_file)
41 return device 43 return device
42 44
43 45
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 162
161 self.assertEquals(self.device.WriteFile.call_args_list, []) # did not write 163 self.assertEquals(self.device.WriteFile.call_args_list, []) # did not write
162 with shared_prefs.SharedPrefs( 164 with shared_prefs.SharedPrefs(
163 self.device, 'com.some.package', 'prefs.xml') as prefs: 165 self.device, 'com.some.package', 'prefs.xml') as prefs:
164 # contents were not modified 166 # contents were not modified
165 self.assertEquals(prefs.AsDict(), self.expected_data) 167 self.assertEquals(prefs.AsDict(), self.expected_data)
166 168
167 if __name__ == '__main__': 169 if __name__ == '__main__':
168 logging.getLogger().setLevel(logging.DEBUG) 170 logging.getLogger().setLevel(logging.DEBUG)
169 unittest.main(verbosity=2) 171 unittest.main(verbosity=2)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698