Skip to content

Conversation

@ki4070ma
Copy link
Collaborator

@ki4070ma ki4070ma commented May 9, 2019

For #373

Results

Verified with Python2/3 and emulator(AndroidP) on 7c53fd3

  • Python2/Python3
➜ android git:(fix-test-ime-multiaction) ✗ python2 ime_tests.py test_activate_ime_engine (__main__.IMETests) ... ok test_active_ime_engine (__main__.IMETests) ... ok test_available_ime_engines (__main__.IMETests) ... ok test_deactivate_ime_engine (__main__.IMETests) ... ok test_is_ime_active (__main__.IMETests) ... ok ---------------------------------------------------------------------- Ran 5 tests in 144.501s OK ➜ android git:(fix-test-ime-multiaction) ✗ python3 ime_tests.py test_activate_ime_engine (__main__.IMETests) ... ok test_active_ime_engine (__main__.IMETests) ... ok test_available_ime_engines (__main__.IMETests) ... ok test_deactivate_ime_engine (__main__.IMETests) ... ok test_is_ime_active (__main__.IMETests) ... ok ---------------------------------------------------------------------- Ran 5 tests in 131.105s OK ➜ android git:(fix-test-ime-multiaction) ✗ python2 multi_action_tests.py test_actions_with_waits (__main__.MultiActionTests) ... ok test_driver_multi_tap (__main__.MultiActionTests) ... ok test_parallel_actions (__main__.MultiActionTests) ... ok ---------------------------------------------------------------------- Ran 3 tests in 115.003s OK ➜ android git:(fix-test-ime-multiaction) ✗ python3 multi_action_tests.py test_actions_with_waits (__main__.MultiActionTests) ... ok test_driver_multi_tap (__main__.MultiActionTests) ... ok test_parallel_actions (__main__.MultiActionTests) ... ok ---------------------------------------------------------------------- Ran 3 tests in 115.334s OK 
SLEEPY_TIME = 3


def is_py3():
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rather rely on the behaviour instead of the version number?

def test_active_ime_engine(self):
self.assertIsInstance(self.driver.active_ime_engine, unicode)
expected = str if is_py3() else unicode
self.assertIsInstance(self.driver.active_ime_engine, expected)
Copy link
Contributor

Choose a reason for hiding this comment

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

try: basestring except NameError: basestring = str isinstance(s, basestring) 
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, it's cool.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

^ unfortunately, below exception occurs on py2, so current impl is revised.

UnboundLocalError: local variable 'basestring' referenced before assignment 
self._touch_actions.append(copy.deepcopy(touch_action))
except TypeError:
# For python3
self._touch_actions.append(copy.copy(touch_action))
Copy link
Contributor

Choose a reason for hiding this comment

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

is deepcopy not present in py3?

Copy link
Collaborator Author

@ki4070ma ki4070ma May 11, 2019

Choose a reason for hiding this comment

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

No, py3 has deepcopy, but deepcopy doesn't work for own class(e.g. TouchAction) in py3.

https://stackoverflow.com/questions/32593035/why-does-deepcopy-fail-when-copying-a-complex-object

In that case, __deepcopy__ has to be implemented by ourselves.

e.g. at TouchAction

 def __deepcopy__(self, memodict={}): new_obj = TouchAction(self._driver) for action in self._actions: new_obj._add_action(action['action'], action['options']) return new_obj 

At least, I have to consider current impl again since copy is not equal to deepcopy.
Steps are as below.

  1. Check how current deepcopy works. If no problem, I'd like to remove it.
  2. If need to keep deepcopy, I'll implement own __deepcopy__
Copy link
Contributor

Choose a reason for hiding this comment

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

we just have to decide if shallow copy is enough for such case. In case it is not enough then I would rather suggest implementing deepcopy

Copy link
Collaborator Author

@ki4070ma ki4070ma May 12, 2019

Choose a reason for hiding this comment

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

Sorry for my missing check, but here deepcopy doesn't work also in python2.
I've checked python2 behavior after adding try-catch.
With my previous codes, shallow copy worked in both py2 and py3.

Summary

positions = [(100, 200), (100, 400), (100, 200)] self.driver.tap(positions) 

log by print(actions) at json_wire_gestures@muti_action.py

[[{'action': 'press', 'options': {'x': 100, 'y': 200}}, {'action': 'release', 'options': {}}], [{'action': 'press', 'options': {'x': 100, 'y': 400}}, {'action': 'release', 'options': {}}], [{'action': 'press', 'options': {'x': 100, 'y': 200}}, {'action': 'release', 'options': {}}]] 

Any comments to my checks are welcome.

self.assertIsInstance(self.driver.active_ime_engine, unicode)
try:
expected = basestring
except NameError:
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment here about why this except is needed

SLEEPY_TIME = 1

LATIN_IME = u'com.android.inputmethod.latin/.LatinIME'
LATIN_IME = 'com.google.android.inputmethod.latin/com.android.inputmethod.latin.LatinIME'
Copy link
Member

Choose a reason for hiding this comment

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

here depends on Android OS versions

So, what about updateing to like below?

ANDROID_LATIN = 'com.android.inputmethod.latin/.LatinIME' GOOGLE_LATIN = 'com.google.android.inputmethod.latin/com.android.inputmethod.latin.LatinIME' def test_available_ime_engines(self): engines = self.driver.available_ime_engines self.assertTrue(ANDROID_LATIN in engines or GOOGLE_LATIN in engines)

def test_active_ime_engine(self):
self.assertIsInstance(self.driver.active_ime_engine, unicode)
try:
Copy link
Member

Choose a reason for hiding this comment

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

You also can modify like:

engines = self.driver.available_ime_engines self.assertTrue(self.driver.active_ime_engine in engines) 

instead of adding except.

Copy link
Collaborator Author

@ki4070ma ki4070ma May 12, 2019

Choose a reason for hiding this comment

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

Thanks. Though I tried to keep current verification, your idea is better.

  • (Before) Check if type is expected(basestring, str)
  • (After) Check if the value is within available_ime_engines.
@ki4070ma ki4070ma merged commit 710d1bc into appium:master May 13, 2019
@ki4070ma ki4070ma deleted the fix-test-ime-multiaction branch May 13, 2019 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants