File: test_usb_transport.py

package info (click to toggle)
python-adb-shell 0.4.4-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 760 kB
  • sloc: python: 3,860; makefile: 191; sh: 124
file content (76 lines) | stat: -rw-r--r-- 1,954 bytes parent folder | download
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
72
73
74
75
76
"""Tests for the `UsbTransport` class."""

import unittest

from adb_shell.exceptions import TcpTimeoutException

try:
    from adb_shell.transport.usb_transport import UsbTransport
except (ImportError, OSError):
    UsbTransport = None

from . import patchers


# pylint: disable=missing-class-docstring, missing-function-docstring
@unittest.skipIf(UsbTransport is None, "UsbTransport could not be imported")
class TestUsbTransport(unittest.TestCase):
    def setUp(self):
        """Create a ``UsbTransport`` and do something...

        """
        self.transport = UsbTransport('TODO', 'TODO')

        if True:
            return

        with patchers.PATCH_CREATE_CONNECTION:
            self.transport.connect()

    def tearDown(self):
        """Close the USB connection."""
        self.transport.close()

    def test_connect_with_timeout(self):
        """TODO

        """
        if True:
            return

        self.transport.close()
        with patchers.PATCH_CREATE_CONNECTION:
            self.transport.connect(transport_timeout_s=1)
            self.assertTrue(True)

    def test_bulk_read(self):
        """TODO

        """
        if True:
            return

        # Provide the `recv` return values
        self.transport._connection._recv = b'TEST1TEST2'

        with patchers.PATCH_SELECT_SUCCESS:
            self.assertEqual(self.transport.bulk_read(5), b'TEST1')
            self.assertEqual(self.transport.bulk_read(5), b'TEST2')

        with patchers.PATCH_SELECT_FAIL:
            with self.assertRaises(TcpTimeoutException):
                self.transport.bulk_read(4)

    def test_bulk_write(self):
        """TODO

        """
        if True:
            return

        with patchers.PATCH_SELECT_SUCCESS:
            self.transport.bulk_write(b'TEST')

        with patchers.PATCH_SELECT_FAIL:
            with self.assertRaises(TcpTimeoutException):
                self.transport.bulk_write(b'FAIL')