-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Properly search native lib dir in ctypes, fixes #1770 #1772
Conversation
This was now tested by me for ARMv7/python3 with a larger SDL2 app, and by the original bug reporter for ARM64 as confirmed here: #1770 (comment) Based on this I am confident to recommend an inclusion at the very least based on functionality, of course code quality remains to be judged 😄 happy for any sort of feedback! |
pythonforandroid/recipes/python3/patches/fix-ctypes-util-find-library.patch
Outdated
Show resolved
Hide resolved
pythonforandroid/recipes/python3/patches/fix-ctypes-util-find-library.patch
Outdated
Show resolved
Hide resolved
pythonforandroid/recipes/python3/patches/fix-ctypes-util-find-library.patch
Outdated
Show resolved
Hide resolved
pythonforandroid/recipes/python3/patches/fix-ctypes-util-find-library.patch
Outdated
Show resolved
Hide resolved
pythonforandroid/recipes/python3/patches/fix-ctypes-util-find-library.patch
Outdated
Show resolved
Hide resolved
For what it's worth I tested the regex version and it appears to work fine! I also tested the regex itself on various test patterns on command line, I just wasn't sure how to ship a test for it in a non-awkward way but if you have an idea I'd be happy to do so. (Otherwise, at least take this as some sort of indication that the regex pattern isn't complete untested bollocks 😂 ) |
Yes I was wondering the same for the unit tests actually. It's pretty annoying because the function is probably simple enough to test, but it's in a patch file which makes it not easy testable. |
Okay, added a comment & tested & deployed it again to check that the patch still works! |
pythonforandroid/recipes/python3/patches/fix-ctypes-util-find-library.patch
Outdated
Show resolved
Hide resolved
Thanks for you efforts! I'll try to test it on Sunday and merge if it doesn't introduce regression on armv7 |
Ouch, I've just tested it and I found a regression with services.
|
Oh yeah, that's bad @ services! As I said in chat I'll follow your suggestion of moving it into the |
@AndreMiras done!! works for me so far, can you check out whether it works for you? |
activity = MagicMock() | ||
activity.getApplicationContext().getPackageName = ( | ||
lambda: "com.example.testpackage" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's fine to use lambda, but mock also has a built'in feature to do what you're doing here:
activity.getApplicationContext().getPackageName.return_value = "com.example.testpackage"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh neat! don't think it'd be actually shorter here though, so should I change it? not sure if lambda is considered ugly here 😬 I really haven't seen much mock'ing code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lambda is completely fine 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway with the magic of MagicMock
you don't have to define this. So you could skip these lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's skipped now in the revamped test except in the one where I actually check for it
return activity_class | ||
elif name == "android.content.pm.PackageManager": | ||
manager_class = MagicMock() | ||
manager_class.GET_SHARED_LIBRARY_FILES = 1024 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mocking explicitly is like documenting. Would the test fail if you remove that line? If not then it means it's not mandatory to prove the point of the interface you're unit testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a check for this now in the updated test (the only part still involving a small if
😬 lol)
import sys | ||
import tempfile | ||
|
||
sys.modules["jnius"] = MagicMock() # fake jnius used later |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I promise this is my last wish, but could you remove this line and patch it explicitly when we need it. At at method level with the decorator, e.g. @mock.patch.dict('sys.modules', jnius=MagicMock())
🙏
I really prefer when things are as local as possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for another great contribution!
Tested on armv7 and it still works good, merging
This will change
ctypes.util.find_library()
to properly query & search native lib dir, which should fix #1770Ran fine for me but I tested with an ARMv7 app. I asked the original reporter for an ARM64 test