Skip to content

Commit 4a833f2

Browse files
authored
chore: Fix mypy errors under test folder (appium#487)
* Fix mypy errors under test folder * Add mypy check for test folder to pre-commit * Add mypy check to ci
1 parent 69396f9 commit 4a833f2

43 files changed

Lines changed: 177 additions & 151 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pre-commit-config.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@
1212
rev: 'v0.761'
1313
hooks:
1414
- id: mypy
15-
files: ^appium/
16-
entry: mypy appium/
15+
entry: mypy appium/ test/
1716
pass_filenames: false

appium/webdriver/extensions/action_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def drag_and_drop(self, origin_el: WebElement, destination_el: WebElement) -> T:
6666
action.long_press(origin_el).move_to(destination_el).release().perform()
6767
return self
6868

69-
def tap(self, positions: List[Tuple], duration: Optional[int] = None) -> T:
69+
def tap(self, positions: List[Tuple[int, int]], duration: Optional[int] = None) -> T:
7070
"""Taps on an particular place with up to five fingers, holding for a
7171
certain time
7272

appium/webdriver/extensions/applications.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,16 @@ class for more details.
172172
}
173173
return self.execute(Command.QUERY_APP_STATE, data)['value']
174174

175-
def app_strings(self, language: str = None, string_file: str = None) -> str:
175+
def app_strings(self, language: str = None, string_file: str = None) -> Dict[str, str]:
176176
"""Returns the application strings from the device for the specified
177177
language.
178178
179179
Args:
180180
language (str): strings language code
181181
string_file (str): the name of the string file to query
182+
183+
Returns:
184+
Dict[str, str]: The key is string id and the value is the content.
182185
"""
183186
data = {}
184187
if language is not None:

ci.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ if [[ $? -ne 0 ]] ; then
3535
fi
3636

3737
(
38-
python -m mypy appium
38+
python -m mypy appium test
3939
)
4040
if [[ $? -ne 0 ]] ; then
4141
EXIT_STATUS=1

test/functional/android/activities_tests.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@
1919

2020

2121
class ActivitiesTests(BaseTestCase):
22-
def test_current_activity(self):
22+
def test_current_activity(self) -> None:
2323
activity = self.driver.current_activity
2424
self.assertEqual('.ApiDemos', activity)
2525

26-
def test_start_activity_this_app(self):
26+
def test_start_activity_this_app(self) -> None:
2727
self.driver.start_activity(APIDEMO_PKG_NAME, ".ApiDemos")
2828
self._assert_activity_contains('Demos')
2929

3030
self.driver.start_activity(APIDEMO_PKG_NAME, ".accessibility.AccessibilityNodeProviderActivity")
3131
self._assert_activity_contains('Node')
3232

33-
def test_start_activity_other_app(self):
33+
def test_start_activity_other_app(self) -> None:
3434
self.driver.start_activity(APIDEMO_PKG_NAME, ".ApiDemos")
3535
self._assert_activity_contains('Demos')
3636

3737
self.driver.start_activity("com.android.calculator2", ".Calculator")
3838
self._assert_activity_contains('Calculator')
3939

40-
def _assert_activity_contains(self, activity):
40+
def _assert_activity_contains(self, activity: str) -> None:
4141
current = self.driver.current_activity
4242
self.assertTrue(activity in current)
4343

test/functional/android/applications_tests.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,33 @@
2323

2424
class ApplicationsTests(BaseTestCase):
2525

26-
def test_background_app(self):
26+
def test_background_app(self) -> None:
2727
self.driver.background_app(1)
2828
sleep(3)
2929
self.driver.launch_app()
3030

31-
def test_is_app_installed(self):
31+
def test_is_app_installed(self) -> None:
3232
self.assertFalse(self.driver.is_app_installed('sdfsdf'))
3333
self.assertTrue(self.driver.is_app_installed(APIDEMO_PKG_NAME))
3434

35-
def test_install_app(self):
35+
def test_install_app(self) -> None:
3636
self.skipTest('This causes the server to crash. no idea why')
3737
self.assertFalse(self.driver.is_app_installed('io.selendroid.testapp'))
3838
self.driver.install_app('/Users/isaac/code/python-client/test/apps/selendroid-test-app.apk')
3939
self.assertTrue(self.driver.is_app_installed('io.selendroid.testapp'))
4040

41-
def test_remove_app(self):
41+
def test_remove_app(self) -> None:
4242
self.assertTrue(self.driver.is_app_installed(APIDEMO_PKG_NAME))
4343
self.driver.remove_app(APIDEMO_PKG_NAME)
4444
self.assertFalse(self.driver.is_app_installed(APIDEMO_PKG_NAME))
4545

46-
def test_close_and_launch_app(self):
46+
def test_close_and_launch_app(self) -> None:
4747
self.driver.close_app()
4848
self.driver.launch_app()
4949
activity = self.driver.current_activity
5050
self.assertEqual('.ApiDemos', activity)
5151

52-
def test_app_management(self):
52+
def test_app_management(self) -> None:
5353
app_id = self.driver.current_package
5454
self.assertEqual(self.driver.query_app_state(app_id),
5555
ApplicationState.RUNNING_IN_FOREGROUND)
@@ -60,19 +60,19 @@ def test_app_management(self):
6060
self.assertEqual(self.driver.query_app_state(app_id),
6161
ApplicationState.RUNNING_IN_FOREGROUND)
6262

63-
def test_app_strings(self):
63+
def test_app_strings(self) -> None:
6464
strings = self.driver.app_strings()
6565
self.assertEqual(u'You can\'t wipe my data, you are a monkey!', strings[u'monkey_wipe_data'])
6666

67-
def test_app_strings_with_language(self):
67+
def test_app_strings_with_language(self) -> None:
6868
strings = self.driver.app_strings('en')
6969
self.assertEqual(u'You can\'t wipe my data, you are a monkey!', strings[u'monkey_wipe_data'])
7070

71-
def test_app_strings_with_language_and_file(self):
71+
def test_app_strings_with_language_and_file(self) -> None:
7272
strings = self.driver.app_strings('en', 'some_file')
7373
self.assertEqual(u'You can\'t wipe my data, you are a monkey!', strings[u'monkey_wipe_data'])
7474

75-
def test_reset(self):
75+
def test_reset(self) -> None:
7676
self.driver.reset()
7777
self.assertTrue(self.driver.is_app_installed(APIDEMO_PKG_NAME))
7878

test/functional/android/chrome_tests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020

2121

2222
class ChromeTests(unittest.TestCase):
23-
def setUp(self):
23+
def setUp(self) -> None:
2424
caps = get_desired_capabilities()
2525
caps['browserName'] = 'Chrome'
2626
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', caps)
2727

28-
def tearDown(self):
28+
def tearDown(self) -> None:
2929
self.driver.quit()
3030

31-
def test_find_single_element(self):
31+
def test_find_single_element(self) -> None:
3232
self.driver.get('http://10.0.2.2:4723/test/guinea-pig')
3333
self.driver.find_element_by_link_text('i am a link').click()
3434

test/functional/android/common_tests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030

3131
class CommonTests(BaseTestCase):
3232

33-
def test_current_package(self):
33+
def test_current_package(self) -> None:
3434
self.assertEqual(APIDEMO_PKG_NAME, self.driver.current_package)
3535

36-
def test_end_test_coverage(self):
36+
def test_end_test_coverage(self) -> None:
3737
self.skipTest('Not sure how to set this up to run')
3838
self.driver.end_test_coverage(intent='android.intent.action.MAIN', path='')
3939
sleep(5)
4040

41-
def test_open_notifications(self):
41+
def test_open_notifications(self) -> None:
4242
if is_ci():
4343
# TODO Due to unexpected dialog, "System UI isn't responding"
4444
self.skipTest('Need to fix flaky test during running on CI.')

test/functional/android/context_switching_tests.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,37 @@
2424

2525
@pytest.mark.skip(reason="Need to fix broken test")
2626
class ContextSwitchingTests(unittest.TestCase):
27-
def setUp(self):
27+
def setUp(self) -> None:
2828
desired_caps = desired_capabilities.get_desired_capabilities('selendroid-test-app.apk')
2929
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
3030

31-
def test_contexts_list(self):
31+
def tearDown(self) -> None:
32+
self.driver.quit()
33+
34+
def test_contexts_list(self) -> None:
3235
self._enter_webview()
3336
contexts = self.driver.contexts
3437
self.assertEqual(2, len(contexts))
3538

36-
def test_move_to_correct_context(self):
39+
def test_move_to_correct_context(self) -> None:
3740
self._enter_webview()
3841
self.assertEqual('WEBVIEW_io.selendroid.testapp', self.driver.current_context)
3942

40-
def test_actually_in_webview(self):
43+
def test_actually_in_webview(self) -> None:
4144
self._enter_webview()
4245
self.driver.find_element_by_css_selector('input[type=submit]').click()
4346
el = self.driver.find_element_by_xpath("//h1[contains(., 'This is my way')]")
4447
self.assertIsNot(None, el)
4548

46-
def test_move_back_to_native_context(self):
49+
def test_move_back_to_native_context(self) -> None:
4750
self._enter_webview()
4851
self.driver.switch_to.context(None)
4952
self.assertEqual('NATIVE_APP', self.driver.current_context)
5053

51-
def test_set_invalid_context(self):
54+
def test_set_invalid_context(self) -> None:
5255
self.assertRaises(NoSuchContextException, self.driver.switch_to.context, 'invalid name')
5356

54-
def tearDown(self):
55-
self.driver.quit()
56-
57-
def _enter_webview(self):
57+
def _enter_webview(self) -> None:
5858
btn = self.driver.find_element_by_name('buttonStartWebviewCD')
5959
btn.click()
6060
self.driver.switch_to.context('WEBVIEW')

test/functional/android/device_time_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
class DeviceTimeTests(BaseTestCase):
24-
def test_device_time(self):
24+
def test_device_time(self) -> None:
2525
date_time = self.driver.device_time
2626
# convert to date ought to work
2727
parse(date_time)

0 commit comments

Comments
 (0)