<s> import utils <EOL> import usb . backend <EOL> from usb . core import find <EOL> from usb . _debug import methodtrace <EOL> import usb . util <EOL> import unittest <EOL> import devinfo <EOL> class _DeviceDescriptor ( object ) : <EOL> def __init__ ( self , idVendor , idProduct ) : <EOL> self . bLength = <NUM_LIT> <EOL> self . bDescriptorType = usb . util . DESC_TYPE_DEVICE <EOL> self . bcdUSB = <NUM_LIT> <EOL> self . idVendor = idVendor <EOL> self . idProduct = idProduct <EOL> self . bcdDevice = <NUM_LIT> <EOL> self . iManufacturer = <NUM_LIT:0> <EOL> self . iProduct = <NUM_LIT:0> <EOL> self . iSerialNumber = <NUM_LIT:0> <EOL> self . bNumConfigurations = <NUM_LIT:0> <EOL> self . bMaxPacketSize0 = <NUM_LIT:64> <EOL> self . bDeviceClass = <NUM_LIT> <EOL> self . bDeviceSubClass = <NUM_LIT> <EOL> self . bDeviceProtocol = <NUM_LIT> <EOL> self . bus = <NUM_LIT:1> <EOL> self . address = <NUM_LIT:1> <EOL> self . port_number = None <EOL> self . port_numbers = None <EOL> self . speed = None <EOL> class _MyBackend ( usb . backend . IBackend ) : <EOL> def __init__ ( self ) : <EOL> self . devices = [ _DeviceDescriptor ( devinfo . ID_VENDOR , p ) for p in range ( <NUM_LIT:4> ) ] <EOL> def enumerate_devices ( self ) : <EOL> return range ( len ( self . devices ) ) <EOL> def get_device_descriptor ( self , dev ) : <EOL> return self . devices [ dev ] <EOL> class FindTest ( unittest . TestCase ) : <EOL> @ methodtrace ( utils . logger ) <EOL> def test_find ( self ) : <EOL> b = _MyBackend ( ) <EOL> self . assertEqual ( find ( backend = b , idVendor = <NUM_LIT:1> ) , None ) <EOL> self . assertNotEqual ( find ( backend = b , idProduct = <NUM_LIT:1> ) , None ) <EOL> self . assertEqual ( len ( tuple ( find ( find_all = True , backend = b ) ) ) , len ( b . devices ) ) <EOL> self . assertEqual ( len ( tuple ( find ( find_all = True , backend = b , idProduct = <NUM_LIT:1> ) ) ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( tuple ( find ( find_all = True , backend = b , idVendor = <NUM_LIT:1> ) ) ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( <EOL> len ( tuple ( find ( <EOL> find_all = True , <EOL> backend = b , <EOL> custom_match = lambda d : d . idProduct == <NUM_LIT:1> ) ) ) , <EOL> <NUM_LIT:1> ) <EOL> self . assertEqual ( <EOL> len ( tuple ( <EOL> find ( <EOL> find_all = True , <EOL> backend = b , <EOL> custom_match = lambda d : d . idVendor == devinfo . ID_VENDOR , <EOL> idProduct = <NUM_LIT:1> ) ) ) , <EOL> <NUM_LIT:1> ) <EOL> def get_suite ( ) : <EOL> suite = unittest . TestSuite ( ) <EOL> suite . addTest ( unittest . defaultTestLoader . loadTestsFromTestCase ( FindTest ) ) <EOL> return suite <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> utils . run_tests ( get_suite ( ) ) </s>
