-   Notifications  
You must be signed in to change notification settings  - Fork 573
 
Fix functional tests failed (android, ime/multi_action) #372
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
| SLEEPY_TIME = 3 | ||
|   |  ||
|   |  ||
| def is_py3(): | 
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.
Can we rather rely on the behaviour instead of the version number?
   test/functional/android/ime_tests.py  Outdated    
 | 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) | 
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.
try: basestring except NameError: basestring = str isinstance(s, basestring) 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, it's cool.
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.
^ 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)) | 
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.
is deepcopy not present in py3?
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.
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.
- Check how current 
deepcopyworks. If no problem, I'd like to remove it. - If need to keep deepcopy, I'll implement own 
__deepcopy__ 
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.
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
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.
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
- Here 
deepcopydoesn't work both in py2 and py3. - Replaced 
deepcopywithcopy- Verified 
test_driver_multi_tapworking- Test case passed and checked multi tap behavior on emulator.
 
 - Verified 
test_driver_multi_tapworking with objects with same value as below. Objects with same values are recognized as different one. 
 - Verified 
 
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.
   test/functional/android/ime_tests.py  Outdated    
 | self.assertIsInstance(self.driver.active_ime_engine, unicode) | ||
| try: | ||
| expected = basestring | ||
| except NameError: | 
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.
Please add a comment here about why this except is needed
   test/functional/android/ime_tests.py  Outdated    
 | SLEEPY_TIME = 1 | ||
|   |  ||
| LATIN_IME = u'com.android.inputmethod.latin/.LatinIME' | ||
| LATIN_IME = 'com.google.android.inputmethod.latin/com.android.inputmethod.latin.LatinIME' | 
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.
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)   test/functional/android/ime_tests.py  Outdated    
 |   |  ||
| def test_active_ime_engine(self): | ||
| self.assertIsInstance(self.driver.active_ime_engine, unicode) | ||
| try: | 
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.
You also can modify like:
engines = self.driver.available_ime_engines self.assertTrue(self.driver.active_ime_engine in engines) instead of adding except.
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. 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. 
For #373
Results
Verified with Python2/3 and emulator(AndroidP) on 7c53fd3