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

Side by Side Diff: devil/devil/android/battery_utils_test.py

Issue 1771263002: [devil] Detect if device is not charging properly. (Closed) Base URL: git@github.com:catapult-project/catapult.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « devil/devil/android/battery_utils.py ('k') | devil/devil/android/device_errors.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 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 battery_utils.py 7 Unit tests for the contents of battery_utils.py
8 """ 8 """
9 9
10 # pylint: disable=protected-access,unused-argument 10 # pylint: disable=protected-access,unused-argument
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 'test_package1': {'uid': '1000', 'data': [1.0]}, 239 'test_package1': {'uid': '1000', 'data': [1.0]},
240 'test_package2': {'uid': '1001', 'data': [2.0]} 240 'test_package2': {'uid': '1001', 'data': [2.0]}
241 } 241 }
242 } 242 }
243 self.assertEqual(data, check) 243 self.assertEqual(data, check)
244 244
245 245
246 class BatteryUtilsChargeDevice(BatteryUtilsTest): 246 class BatteryUtilsChargeDevice(BatteryUtilsTest):
247 247
248 @mock.patch('time.sleep', mock.Mock()) 248 @mock.patch('time.sleep', mock.Mock())
249 def testChargeDeviceToLevel(self): 249 def testChargeDeviceToLevel_pass(self):
250 with self.assertCalls( 250 with self.assertCalls(
251 (self.call.battery.SetCharging(True)), 251 (self.call.battery.SetCharging(True)),
252 (self.call.battery.GetBatteryInfo(), {'level': '50'}), 252 (self.call.battery.GetBatteryInfo(), {'level': '50'}),
253 (self.call.battery.GetBatteryInfo(), {'level': '100'})): 253 (self.call.battery.GetBatteryInfo(), {'level': '100'})):
254 self.battery.ChargeDeviceToLevel(95) 254 self.battery.ChargeDeviceToLevel(95)
255 255
256 @mock.patch('time.sleep', mock.Mock())
257 def testChargeDeviceToLevel_failureSame(self):
258 with self.assertCalls(
259 (self.call.battery.SetCharging(True)),
260 (self.call.battery.GetBatteryInfo(), {'level': '50'}),
261 (self.call.battery.GetBatteryInfo(), {'level': '50'}),
262
263 (self.call.battery.GetBatteryInfo(), {'level': '50'})):
264 with self.assertRaises(device_errors.DeviceChargingError):
265 old_max = battery_utils._MAX_CHARGE_ERROR
266 try:
267 battery_utils._MAX_CHARGE_ERROR = 2
268 self.battery.ChargeDeviceToLevel(95)
269 finally:
270 battery_utils._MAX_CHARGE_ERROR = old_max
271
272 @mock.patch('time.sleep', mock.Mock())
273 def testChargeDeviceToLevel_failureDischarge(self):
274 with self.assertCalls(
275 (self.call.battery.SetCharging(True)),
276 (self.call.battery.GetBatteryInfo(), {'level': '50'}),
277 (self.call.battery.GetBatteryInfo(), {'level': '49'}),
278 (self.call.battery.GetBatteryInfo(), {'level': '48'})):
279 with self.assertRaises(device_errors.DeviceChargingError):
280 old_max = battery_utils._MAX_CHARGE_ERROR
281 try:
282 battery_utils._MAX_CHARGE_ERROR = 2
283 self.battery.ChargeDeviceToLevel(95)
284 finally:
285 battery_utils._MAX_CHARGE_ERROR = old_max
286
256 287
257 class BatteryUtilsDischargeDevice(BatteryUtilsTest): 288 class BatteryUtilsDischargeDevice(BatteryUtilsTest):
258 289
259 @mock.patch('time.sleep', mock.Mock()) 290 @mock.patch('time.sleep', mock.Mock())
260 def testDischargeDevice_exact(self): 291 def testDischargeDevice_exact(self):
261 with self.assertCalls( 292 with self.assertCalls(
262 (self.call.battery.GetBatteryInfo(), {'level': '100'}), 293 (self.call.battery.GetBatteryInfo(), {'level': '100'}),
263 (self.call.battery._HardwareSetCharging(False)), 294 (self.call.battery._HardwareSetCharging(False)),
264 (self.call.battery._HardwareSetCharging(True)), 295 (self.call.battery._HardwareSetCharging(True)),
265 (self.call.battery.GetBatteryInfo(), {'level': '99'})): 296 (self.call.battery.GetBatteryInfo(), {'level': '99'})):
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 ['9,1000,l,pwi,uid,0.0327']), 667 ['9,1000,l,pwi,uid,0.0327']),
637 (self.call.device.RunShellCommand( 668 (self.call.device.RunShellCommand(
638 ['dumpsys', 'battery', 'reset'], check_return=True), [])): 669 ['dumpsys', 'battery', 'reset'], check_return=True), [])):
639 with self.assertRaises(device_errors.CommandFailedError): 670 with self.assertRaises(device_errors.CommandFailedError):
640 self.battery._ClearPowerData() 671 self.battery._ClearPowerData()
641 672
642 673
643 if __name__ == '__main__': 674 if __name__ == '__main__':
644 logging.getLogger().setLevel(logging.DEBUG) 675 logging.getLogger().setLevel(logging.DEBUG)
645 unittest.main(verbosity=2) 676 unittest.main(verbosity=2)
OLDNEW
« no previous file with comments | « devil/devil/android/battery_utils.py ('k') | devil/devil/android/device_errors.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698