1 #! /usr/bin/env python 2 # Copyright 2017 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 pickle 7 import sys 8 import unittest 9 10 from devil.android import device_errors 11 12 13 class DeviceErrorsTest(unittest.TestCase): 14 15 def assertIsPicklable(self, original): 16 pickled = pickle.dumps(original) 17 reconstructed = pickle.loads(pickled) 18 self.assertEquals(original, reconstructed) 19 20 def testPicklable_AdbCommandFailedError(self): 21 original = device_errors.AdbCommandFailedError( 22 ['these', 'are', 'adb', 'args'], 'adb failure output', status=':(', 23 device_serial='0123456789abcdef') 24 self.assertIsPicklable(original) 25 26 def testPicklable_AdbShellCommandFailedError(self): 27 original = device_errors.AdbShellCommandFailedError( 28 'foo', 'erroneous foo output', '1', device_serial='0123456789abcdef') 29 self.assertIsPicklable(original) 30 31 def testPicklable_CommandFailedError(self): 32 original = device_errors.CommandFailedError( 33 'sample command failed') 34 self.assertIsPicklable(original) 35 36 def testPicklable_CommandTimeoutError(self): 37 original = device_errors.CommandTimeoutError( 38 'My fake command timed out :(') 39 self.assertIsPicklable(original) 40 41 def testPicklable_DeviceChargingError(self): 42 original = device_errors.DeviceChargingError( 43 'Fake device failed to charge') 44 self.assertIsPicklable(original) 45 46 def testPicklable_DeviceUnreachableError(self): 47 original = device_errors.DeviceUnreachableError 48 self.assertIsPicklable(original) 49 50 def testPicklable_FastbootCommandFailedError(self): 51 original = device_errors.FastbootCommandFailedError( 52 ['these', 'are', 'fastboot', 'args'], 'fastboot failure output', 53 status=':(', device_serial='0123456789abcdef') 54 self.assertIsPicklable(original) 55 56 def testPicklable_MultipleDevicesError(self): 57 # TODO(jbudorick): Implement this after implementing a stable DeviceUtils 58 # fake. https://github.com/catapult-project/catapult/issues/3145 59 pass 60 61 def testPicklable_NoAdbError(self): 62 original = device_errors.NoAdbError() 63 self.assertIsPicklable(original) 64 65 def testPicklable_NoDevicesError(self): 66 original = device_errors.NoDevicesError() 67 self.assertIsPicklable(original) 68 69 70 71 if __name__ == '__main__': 72 sys.exit(unittest.main()) 73