Skip to content

Commit 2b25a7d

Browse files
committed
test.py: test get_library_path(); a few improvements and fixes.
- Fix show_devices() output. - Use get_libusb1_backend() call for show_devices(). - Print less device info for find().
1 parent 909435f commit 2b25a7d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

test.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,28 @@
66
import usb.backend.libusb1
77

88
def main():
9+
# Test get_library_path().
10+
path = libusb_package.get_library_path()
11+
print(f"Path to included library: {path}")
12+
13+
# Test find_library().
914
libusb1_backend = usb.backend.libusb1.get_backend(find_library=libusb_package.find_library)
1015
if not libusb1_backend:
1116
print("Unable to load libusb backend!")
1217
sys.exit(1)
1318
print(f"libusb1_backend = {libusb1_backend}")
1419

15-
# Use pyusb directly with the loaded backend.
20+
# Test get_libusb1_backend().
1621
print("usb.core.show_devices output:")
17-
usb.core.show_devices(backend=libusb1_backend)
22+
print(usb.core.show_devices(backend=libusb_package.get_libusb1_backend()))
1823

1924
# Try out the find() wrapper.
2025
print("libusb_package.find output:")
2126
for dev in libusb_package.find(find_all=True):
22-
print(dev)
27+
try:
28+
print(f"{dev.idVendor:04x}:{dev.idProduct:04x}: {dev.manufacturer} {dev.product} ({dev.serial_number})")
29+
except Exception as err:
30+
print(f"{dev.idVendor:04x}:{dev.idProduct:04x}: error reading strings ({err})")
2331

2432
if __name__ == "__main__":
2533
main()

0 commit comments

Comments
 (0)