-
Notifications
You must be signed in to change notification settings - Fork 69
Potential fix for 'exec' failure case #1
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
Conversation
anwilli5
commented
Oct 9, 2014
- Adding more robust code to handle the case where the exec call within fails. Now, spawn will raise an exception if this happens.
- Adding a test to ensure this exception is raised when an invalid binary is run
…hin spawn fails. Now, spawn will raise an exception if this happens. - Adding a test to ensure this exception is raised when an invalid binary is run
tests/test_invalid_binary.py
Outdated
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 don't think you need to use the low-level os.open
interface here - you should just be able to open a regular file object in binary mode - with open(fullpath, 'wb') as f:
Thanks for this, and especially for writing a test to go with it. |
pexpect#1 with the exception of the generic exec OSError handling - waiting on thoughts on how best to implement this.
I'd prefer to send it separately as the first few bytes, that way we're not relying on the way Python formats error messages. We're already using the struct module, so doing |
…is now the one returned from the child process exception
Thanks for the feedback - my python dev experience isn't too extensive, so I'm still learning the best ways of doing things. :) |
tests/test_invalid_binary.py
Outdated
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.
Theoretically, some infintesimal fraction of the time, this could accidentally generate a valid executable and do something random on your computer. I expect that's massively unlikely, but I might hardcode some nonsense bytes so it's always the same.
You're welcome. There's just a couple more little things I spotted with the test, then I think this is good to go. |
tests/test_invalid_binary.py
Outdated
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. I think b'\x00\x00'
should work on both Python versions.
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 wouldn't work on Python 2.5 or older, but I'm not interested in supporting that)
Thanks! Merging this now. |
Potential fix for 'exec' failure case
Hmmm, tests are failing on my machine, with |
Weird... Yes, the tests pass for me: Just as a sanity check, is the latest working directory in your PYTHONPATH? |
Ah, you're right, it was testing against an older version. D'oh. Normally py.test automatically adds the working directory to sys.path - I don't know why it's not at the moment. |
Got it: if the tests are a package, i.e. with an |