-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
BUG: Move ctypes ImportError catching to appropriate place #8898
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
Changes from 1 commit
e273fb5
69143e7
c9fe3ba
b29ae31
bb56070
3af4fe5
4e2ab70
bd3011e
9b19671
0e4942a
82bebd2
647a75e
e75a486
06b3a82
2652a1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
8000
|
@@ -6729,24 +6729,21 @@ def test_null_inside_ustring_array_is_truthy(self): | |
|
||
|
||
class TestCTypes(TestCase): | ||
def setUp(self): | ||
self.test_arr = np.array([[1, 2, 3], [4, 5, 6]]) | ||
|
||
def test_ctypes_is_available(self): | ||
_ctypes = np.array(self.test_arr).ctypes | ||
test_arr = np.array([[1, 2, 3], [4, 5, 6]]) | ||
|
||
self.assertEqual(ctypes, _ctypes._ctypes) | ||
assert_equal(_ctypes._arr.shape, (2, 3)) | ||
assert_array_equal(_ctypes._arr, self.test_arr) | ||
self.assertEqual(ctypes, test_arr.ctypes._ctypes) | ||
assert_equal(test_arr.shape, (2, 3)) | ||
|
||
def test_ctypes_is_not_available(self): | ||
_internal.ctypes = None | ||
try: | ||
_ctypes = np.array(self.test_arr).ctypes | ||
test_arr = np.array([[1, 2, 3], [4, 5, 6]]) | ||
|
||
self.assertIsInstance(_ctypes._ctypes, _internal._missing_ctypes) | ||
assert_equal(_ctypes._arr.shape, (2, 3)) | ||
assert_array_equal(_ctypes._arr, self.test_arr) | ||
self.assertIsInstance( | ||
test_arr.ctypes._ctypes, _internal._missing_ctypes) | ||
assert_equal(test_arr.shape, (2, 3)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the confusion here, updating in the next commit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great, thanks |
||
finally: | ||
_internal.ctypes = ctypes | ||
|
||
|
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.
Debatable whether testing implementation details like this (and the one above) makes any sense
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.
If you feel strongly, I'll remove it. I think its a good check to keep. For instance, if someone decides to add an "import ctypes" statement into one of these methods in the future, this assertion will catch that. Otherwise, the test will continue to pass.
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.
Yeah, my concernt is that that's somewhat artificial, and doesn't really catch us doing
import ctypes
anywhere else - these tests wouldn't catch the bug that caused you to patch this in the first place, for instance.I don't feel strongly about it, but would appreciate input from someone else on a better way to test this.
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.
Fair enough. Will wait for additional input.
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'm almost tempted to spin off a new python interpreter without ctypes to run the test, to ensure it can't break anything else
You might also be able to get your
sys.modules
hackery to work if you try to put everything back together again, but also a little risky.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.
Hey Eric,
I tried again with the sys.modules hackery, and trying to put things back together again with the try/finally block. Unfortunately, other tests continue to fail. I guess this is because tests are run in parallel. With the current setup (setting ctypes = None), we will have similar cross-test side effects, but I guess we are getting lucky in that it isn't causing any errant failures.
By "spin off a new python interpreter", are you suggesting to execute the test with python's subprocess?
Eg (?):
def some_test(self):
self.assertEqual(0, subprocess.call(sys.executable, "-c", test_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.
Yes, that is what I mean. I'm not actually sure that's a good idea though, and I don't think you should risk wasting time trying it until someone else weighs in.