driver.push_file(destination_path, source_path) feature - #270
Conversation
|
Did you test the PR for both Python 2 and Python3? |
| Specify either `base64data` or `source_path`, if both specified default to `source_path` | ||
| :Args: | ||
| - path - the path on the device | ||
| - destination_path - the path on the device |
There was a problem hiding this comment.
I'd rather add more advanced docstrinmg here, since several formatting options are available there. Check https://github.com/appium/java-client/blob/f527be18735f8a60b4f6244f03a1b9954c23a60f/src/main/java/io/appium/java_client/InteractsWithFiles.java#L44
and
for more details
There was a problem hiding this comment.
Sure I update the formatting to the reStructured text format, let me know if that one's good. Originally I was just going along with the format I saw in the rest of the file to stay consistent but now I'm noticing some other functions use this format as well.
| if source_path is None and base64data is None: | ||
| raise InvalidArgumentException('Must either present base64 data or a source path on local system') | ||
|
|
||
| if source_path is not None: |
There was a problem hiding this comment.
should we check if the file exists first?
There was a problem hiding this comment.
i think we should, either that or catch the exception and provide something meaningful as a user facing error
There was a problem hiding this comment.
The error that it threw was in this is FileNotFoundError: [Errno 2] No such file or directory: '{filename}', I'm not sure the message I'm presenting now is much different source_path {} could not be found. Are you sure the file exists? Is there a better way to do this or this should be good enough?
jlipps
left a comment
There was a problem hiding this comment.
Thanks so much for this, @JavonDavis, it's a great contribution! I made some additional comments that should hopefully be pretty easy to resolve.
| if source_path is None and base64data is None: | ||
| raise InvalidArgumentException('Must either present base64 data or a source path on local system') | ||
|
|
||
| if source_path is not None: |
There was a problem hiding this comment.
i think we should, either that or catch the exception and provide something meaningful as a user facing error
| if source_path is None and base64data is None: | ||
| raise InvalidArgumentException('Must either present base64 data or a source path on local system') | ||
|
|
||
| if source_path is not None: |
There was a problem hiding this comment.
You could use if bool(source_path):
There was a problem hiding this comment.
Not sure there's a real benefit to converting to a boolean for the check?
There was a problem hiding this comment.
I like the current state of the code (with the slightly more informative error message). Thanks.
| 'automationName': 'UIAutomator2' | ||
| } | ||
|
|
||
| return desired_caps |
There was a problem hiding this comment.
Do we use newline at end of file as per PEP8?
There was a problem hiding this comment.
It passes the pep8 check locally and I didn't make any change at the end of this file just really the addition of UIAutomator2
There was a problem hiding this comment.
python -m autopep8 -r --global-config .config-pep8 -d . runs on CI. I've relaxed the check for max-line-length, only. Is it enough for pep8?
(If I missed something, I'd like to add the check on CI)
There was a problem hiding this comment.
@KazuCocoa I think the relaxed 120 max line length is pretty good
* changed docstring format * Catch error thrown if file not present and present user with a better message
Hey @mykola-mokhnach thanks for the review and I actually ran into that issue while I was working on this, encoding with |
@jlipps Sure no problem! Thanks for the review 👍 I've made some changes based on the comments |
| 'path': path, | ||
| } | ||
| return self.execute(Command.PULL_FILE, data)['value'] | ||
| return base64.b64decode(self.execute(Command.PULL_FILE, data)['value']) |
There was a problem hiding this comment.
I would say we should not do this, since it is going to break the backward compatibility.
There was a problem hiding this comment.
You're right I overlooked this, it's removed
| - path - the path on the device | ||
| - base64data - data, encoded as Base64, to be written to the file | ||
| Specify either `base64data` or `source_path`, if both specified default to `source_path` | ||
| :param destination_path: the path on the device/simulator |
There was a problem hiding this comment.
Please add more detailed description of this argument
There was a problem hiding this comment.
Is the new description a little better?
…cstring description for `destination_path`
| if source_path is None and base64data is None: | ||
| raise InvalidArgumentException('Must either present base64 data or a source path on local system') | ||
|
|
||
| if source_path is not None: |
There was a problem hiding this comment.
I like the current state of the code (with the slightly more informative error message). Thanks.
|
Thanks! Will merge this. |
This PR aims to simplify pushing and retrieving files from the simulator and emulator. It provides an optional parameter source_path to the existing push_file function and does the base64 conversion on that file for users.
Fixes #269
To test:
/Users/javon/Projects/python-client/test/functional/android/push_file_tests.py
/Users/javon/Projects/python-client/test/functional/ios/push_file_tests.py