Skip to content

driver.push_file(destination_path, source_path) feature - #270

Merged
KazuCocoa merged 6 commits into
appium:masterfrom
JavonDavis:feature_push_file
Nov 21, 2018
Merged

driver.push_file(destination_path, source_path) feature#270
KazuCocoa merged 6 commits into
appium:masterfrom
JavonDavis:feature_push_file

Conversation

@JavonDavis

@JavonDavis JavonDavis commented Nov 16, 2018

Copy link
Copy Markdown
Contributor

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

@jsf-clabot

jsf-clabot commented Nov 16, 2018

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@mykola-mokhnach

Copy link
Copy Markdown
Contributor

Did you test the PR for both Python 2 and Python3?
I remember there was an issue while base-64 encoding a string there. See #267 for more details.

Comment thread appium/webdriver/webdriver.py Outdated
Comment thread appium/webdriver/webdriver.py Outdated
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we check if the file exists first?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should, either that or catch the exception and provide something meaningful as a user facing error

@JavonDavis JavonDavis Nov 19, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 jlipps left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for this, @JavonDavis, it's a great contribution! I made some additional comments that should hopefully be pretty easy to resolve.

Comment thread appium/webdriver/webdriver.py Outdated
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:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should, either that or catch the exception and provide something meaningful as a user facing error

Comment thread test/functional/android/push_file_tests.py Outdated
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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use if bool(source_path):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure there's a real benefit to converting to a boolean for the check?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the current state of the code (with the slightly more informative error message). Thanks.

'automationName': 'UIAutomator2'
}

return desired_caps

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we use newline at end of file as per PEP8?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
@JavonDavis

Copy link
Copy Markdown
Contributor Author

Did you test the PR for both Python 2 and Python3?
I remember there was an issue while base-64 encoding a string there. See #267 for more details.

Hey @mykola-mokhnach thanks for the review and I actually ran into that issue while I was working on this, encoding with base64.b64encode(data).decode('utf-8') seemed to work well across both the Python versions I tested with (2.7 and 3.7)

@JavonDavis

Copy link
Copy Markdown
Contributor Author

Thanks so much for this, @JavonDavis, it's a great contribution! I made some additional comments that should hopefully be pretty easy to resolve.

@jlipps Sure no problem! Thanks for the review 👍 I've made some changes based on the comments

Comment thread appium/webdriver/webdriver.py Outdated
'path': path,
}
return self.execute(Command.PULL_FILE, data)['value']
return base64.b64decode(self.execute(Command.PULL_FILE, data)['value'])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say we should not do this, since it is going to break the backward compatibility.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right I overlooked this, it's removed

Comment thread appium/webdriver/webdriver.py Outdated
- 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add more detailed description of this argument

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the new description a little better?

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:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the current state of the code (with the slightly more informative error message). Thanks.

@KazuCocoa

Copy link
Copy Markdown
Member

Thanks! Will merge this.

@KazuCocoa
KazuCocoa merged commit b6795db into appium:master Nov 21, 2018
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.

6 participants