Skip to content

Commit

Permalink
test.py: test get_library_path(); a few improvements and fixes.
Browse files Browse the repository at this point in the history
- Fix show_devices() output.
- Use get_libusb1_backend() call for show_devices().
- Print less device info for find().
  • Loading branch information
flit committed Nov 10, 2021
1 parent 909435f commit 2b25a7d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,28 @@
import usb.backend.libusb1

def main():
# Test get_library_path().
path = libusb_package.get_library_path()
print(f"Path to included library: {path}")

# Test find_library().
libusb1_backend = usb.backend.libusb1.get_backend(find_library=libusb_package.find_library)
if not libusb1_backend:
print("Unable to load libusb backend!")
sys.exit(1)
print(f"libusb1_backend = {libusb1_backend}")

# Use pyusb directly with the loaded backend.
# Test get_libusb1_backend().
print("usb.core.show_devices output:")
usb.core.show_devices(backend=libusb1_backend)
print(usb.core.show_devices(backend=libusb_package.get_libusb1_backend()))

# Try out the find() wrapper.
print("libusb_package.find output:")
for dev in libusb_package.find(find_all=True):
print(dev)
try:
print(f"{dev.idVendor:04x}:{dev.idProduct:04x}: {dev.manufacturer} {dev.product} ({dev.serial_number})")
except Exception as err:
print(f"{dev.idVendor:04x}:{dev.idProduct:04x}: error reading strings ({err})")

if __name__ == "__main__":
main()
Expand Down

0 comments on commit 2b25a7d

Please sign in to comment.