aboutsummaryrefslogtreecommitdiff
path: root/catapult/devil/devil/android/device_errors_test.py
blob: 5fc9e2542ca6f50320ffae77babcafa52dbb8ecd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#! /usr/bin/env python
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import pickle
import sys
import unittest

from devil.android import device_errors


class DeviceErrorsTest(unittest.TestCase):
  def assertIsPicklable(self, original):
    pickled = pickle.dumps(original)
    reconstructed = pickle.loads(pickled)
    self.assertEquals(original, reconstructed)

  def testPicklable_AdbCommandFailedError(self):
    original = device_errors.AdbCommandFailedError(
        ['these', 'are', 'adb', 'args'],
        'adb failure output',
        status=':(',
        device_serial='0123456789abcdef')
    self.assertIsPicklable(original)

  def testPicklable_AdbShellCommandFailedError(self):
    original = device_errors.AdbShellCommandFailedError(
        'foo', 'erroneous foo output', '1', device_serial='0123456789abcdef')
    self.assertIsPicklable(original)

  def testPicklable_CommandFailedError(self):
    original = device_errors.CommandFailedError('sample command failed')
    self.assertIsPicklable(original)

  def testPicklable_CommandTimeoutError(self):
    original = device_errors.CommandTimeoutError('My fake command timed out :(')
    self.assertIsPicklable(original)

  def testPicklable_DeviceChargingError(self):
    original = device_errors.DeviceChargingError('Fake device failed to charge')
    self.assertIsPicklable(original)

  def testPicklable_DeviceUnreachableError(self):
    original = device_errors.DeviceUnreachableError
    self.assertIsPicklable(original)

  def testPicklable_FastbootCommandFailedError(self):
    original = device_errors.FastbootCommandFailedError(
        ['these', 'are', 'fastboot', 'args'],
        'fastboot failure output',
        status=':(',
        device_serial='0123456789abcdef')
    self.assertIsPicklable(original)

  def testPicklable_MultipleDevicesError(self):
    # TODO(jbudorick): Implement this after implementing a stable DeviceUtils
    # fake. https://github.com/catapult-project/catapult/issues/3145
    pass

  def testPicklable_NoAdbError(self):
    original = device_errors.NoAdbError()
    self.assertIsPicklable(original)

  def testPicklable_NoDevicesError(self):
    original = device_errors.NoDevicesError()
    self.assertIsPicklable(original)


if __name__ == '__main__':
  sys.exit(unittest.main())