Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test step to cibuildwheel. #21

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

carlosperate
Copy link

@carlosperate carlosperate commented Nov 24, 2023

Looking into adding tests (issue #19), and it looks like we can run a test step in cibuildwheel after each wheel is built, simple! 🥳
https://cibuildwheel.readthedocs.io/en/v2.16.2/options/#testing

So I've added pyusb as a test requirement and it runs python test.py.

  • Is that the best current way to test the wheels?
  • Is there something else this should do?

I was planning to add this as part of PR #20, but unfortunately the tests are failing on Linux, so I didn't want that to be a blocker for that PR.

This PR is running on top of the main branch without any other modifications, to test the current wheels, which I assume should be working.

Test result from my fork: https://github.com/carlosperate/libusb-package/actions/runs/6975861223/job/18983558875

Building cp37-manylinux_x86_64 wheel
CPython 3.7 manylinux x86_64
...
  Collecting pyusb
    Downloading pyusb-1.2.1-py3-none-any.whl (58 kB)
       ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 58.4/58.4 kB 4.8 MB/s eta 0:00:00
  Installing collected packages: pyusb
  Successfully installed pyusb-1.2.1
      + mkdir -p /tmp/tmp.G43sXfIgjj/test_cwd
      + sh -c 'python /project/test.py'
  Path to included library: /tmp/tmp.G43sXfIgjj/venv/lib/python3.7/site-packages/libusb_package/libusb-1.0.so
  Unable to load libusb backend!

libusb-package/test.py

Lines 13 to 17 in 7a62b64

# 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)

def find_library(candidate: str) -> Optional[str]:
"""@brief Look for a package resource starting with the provided candidate name.
This function effectively implements the `find_library` callback used by pyusb's backends.
However, it is general enough to be used for any code that needs a libusb library.
@retval str Path to the contained library matching the candidate name.
@retval None No library matching the candidate name is contained in libusb_package.
"""
lib_path = get_library_path()
if not lib_path:
# There is no library included in our installation, fall back to ctypes' find_library.
return ctypes.util.find_library(candidate)
lib_name = lib_path.name
if lib_name.startswith(candidate) \
or ((platform.system() == "Linux") and lib_name.startswith("lib" + candidate)):
return str(lib_path)
# We don't have a matching library.
return None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant