Skip to content

Commit 10ae8c3

Browse files
committed
updates for python 3
- removed unnecessary inheritance from object - removed unnecessary u prefix for strings - sorted some imports - converted strings into f-strings - simplified a conditional
1 parent ab13d72 commit 10ae8c3

43 files changed

Lines changed: 76 additions & 76 deletions

Some content is hidden

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

script/release.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def get_current_version():
3636
current = (
3737
io.open(os.path.join(os.path.dirname('__file__'), 'appium', 'version.py'), encoding='utf-8').read().rstrip()
3838
)
39-
print('The current version is {}, type a new one'.format(MESSAGE_YELLOW.format(current)))
39+
print(f'The current version is {MESSAGE_YELLOW.format(current)}, type a new one')
4040
return current
4141

4242

@@ -51,72 +51,72 @@ def get_new_version():
5151

5252
def update_version_file(version):
5353
new_version = VERSION_FORMAT.format(version)
54-
with open(VERSION_FILE_PATH, 'w') as f:
54+
with open(VERSION_FILE_PATH, 'w', encoding="utf-8") as f:
5555
f.write(new_version)
5656

5757

5858
def call_bash_script(cmd):
5959
if os.environ.get('DRY_RUN') is not None:
60-
print('{} Calls: {}'.format(MESSAGE_RED.format('[DRY_RUN]'), cmd))
60+
print(f"{MESSAGE_RED.format('[DRY_RUN]')} Calls: {cmd}")
6161
else:
6262
os.system(cmd)
6363

6464

6565
def commit_version_code(new_version_num):
66-
call_bash_script('git commit {} -m "Bump {}"'.format(VERSION_FILE_PATH, new_version_num))
66+
call_bash_script(f'git commit {VERSION_FILE_PATH} -m "Bump {new_version_num}"')
6767

6868

6969
def tag_and_generate_changelog(new_version_num):
70-
call_bash_script('git tag "v{}"'.format(new_version_num))
71-
call_bash_script('gitchangelog > {}'.format(CHANGELOG_PATH))
72-
call_bash_script('git commit {} -m "Update changelog for {}"'.format(CHANGELOG_PATH, new_version_num))
70+
call_bash_script(f'git tag "v{new_version_num}"')
71+
call_bash_script(f'gitchangelog > {CHANGELOG_PATH}')
72+
call_bash_script(f'git commit {CHANGELOG_PATH} -m "Update changelog for {new_version_num}"')
7373

7474

7575
def upload_sdist(new_version_num):
76-
push_file = 'dist/Appium-Python-Client-{}.tar.gz'.format(new_version_num)
76+
push_file = f'dist/Appium-Python-Client-{new_version_num}.tar.gz'
7777
try:
78-
call_bash_script('twine upload "{}"'.format(push_file))
78+
call_bash_script(f'twine upload "{push_file}"')
7979
except Exception as e:
8080
print(
81-
'Failed to upload {} to pypi. '
82-
'Please fix the original error and push it again later. Original error: {}'.format(push_file, e)
81+
f'Failed to upload {push_file} to pypi. '
82+
f'Please fix the original error and push it again later. Original error: {e}'
8383
)
8484

8585

8686
def push_changes_to_master(new_version_num):
8787
call_bash_script('git push origin master')
88-
call_bash_script('git push origin "v{}"'.format(new_version_num))
88+
call_bash_script(f'git push origin "v{new_version_num}"')
8989

9090

9191
def ensure_publication(new_version_num):
9292
if os.environ.get('DRY_RUN') is not None:
93-
print('Run with {} mode.'.format(MESSAGE_RED.format('[DRY_RUN]')))
93+
print(f"Run with {MESSAGE_RED.format('[DRY_RUN]')} mode.")
9494

95-
print('Are you sure to release as {}?[y/n]'.format(MESSAGE_YELLOW.format(new_version_num)))
95+
print(f'Are you sure to release as {MESSAGE_YELLOW.format(new_version_num)}?[y/n]')
9696
for line in sys.stdin:
9797
if line.rstrip().lower() == 'y':
9898
return
99-
exit('Canceled release process.')
99+
sys.exit('Canceled release process.')
100100

101101

102102
def build_sdist():
103-
call_bash_script('{} setup.py sdist'.format(sys.executable))
103+
call_bash_script(f'{sys.executable} setup.py sdist')
104104

105105

106106
def validate_release_env():
107107
if os.system('which twine') != 0:
108-
exit("Please get twine via 'pip install twine'")
108+
sys.exit("Please get twine via 'pip install twine'")
109109
if os.system('which gitchangelog') != 0:
110-
exit(
110+
sys.exit(
111111
"Please get twine via 'pip install gitchangelog' or 'pip install git+git://github.com/vaab/gitchangelog.git' for Python 3.7"
112112
)
113113

114114

115115
def build() -> None:
116116
shutil.rmtree(BUILT_APPIUM_DIR_PATH, ignore_errors=True)
117-
status, output = subprocess.getstatusoutput('{} setup.py install'.format(os.getenv('PYTHON_BIN_PATH')))
117+
status, output = subprocess.getstatusoutput(f"{os.getenv('PYTHON_BIN_PATH')} setup.py install")
118118
if status != 0:
119-
exit(f'Failed to build the package:\n{output}')
119+
sys.exit(f'Failed to build the package:\n{output}')
120120

121121

122122
def get_py_files_in_dir(root_dir: str) -> List[str]:
@@ -144,7 +144,7 @@ def assert_files_count_in_package() -> None:
144144
if diff:
145145
print(f"{BUILT_APPIUM_DIR_PATH} has {diff} files than {APPIUM_DIR_PATH}")
146146

147-
exit(
147+
sys.exit(
148148
f"Python files in '{BUILT_APPIUM_DIR_PATH}' may differ from '{APPIUM_DIR_PATH}'. "
149149
"Please make sure setup.py is configured properly."
150150
)

test/functional/android/applications_tests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ def test_app_management(self) -> None:
6161

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

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

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

7474
def test_reset(self) -> None:
7575
self.driver.reset()

test/functional/android/chrome_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from .helper.desired_capabilities import get_desired_capabilities
2121

2222

23-
class TestChrome(object):
23+
class TestChrome():
2424
def setup_method(self) -> None:
2525
caps = get_desired_capabilities()
2626
caps['browserName'] = 'Chrome'

test/functional/android/context_switching_tests.py

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

2525

2626
@pytest.mark.skip(reason="Need to fix broken test")
27-
class TestContextSwitching(object):
27+
class TestContextSwitching():
2828
def setup_method(self) -> None:
2929
caps = desired_capabilities.get_desired_capabilities('selendroid-test-app.apk')
3030
self.driver = webdriver.Remote(SERVER_URL_BASE, options=AppiumOptions().load_capabilities(caps))

test/functional/android/remote_fs_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_push_pull_file(self) -> None:
3232
assert data == data_ret
3333

3434
def test_pull_folder(self) -> None:
35-
data = bytes('random string data {}'.format(random.randint(0, 1000)), 'utf-8')
35+
data = bytes(f'random string data {random.randint(0, 1000)}', 'utf-8')
3636
dest_dir = '/data/local/tmp/'
3737

3838
for filename in ['1.txt', '2.txt']:

test/functional/android/search_context/find_by_image_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from test.helpers.constants import SERVER_URL_BASE
2626

2727

28-
class TestFindByImage(object):
28+
class TestFindByImage():
2929
def setup_method(self) -> None:
3030
caps = desired_capabilities.get_desired_capabilities('ApiDemos-debug.apk.zip')
3131
self.driver = webdriver.Remote(SERVER_URL_BASE, options=AppiumOptions().load_capabilities(caps))

test/functional/android/touch_action_tests.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ def test_drag_and_drop(self) -> None:
131131
el = wait_for_element(self.driver, AppiumBy.ACCESSIBILITY_ID, 'Drag and Drop')
132132
action.tap(el).perform()
133133

134-
dd3 = wait_for_element(self.driver, AppiumBy.ID, '{}:id/drag_dot_3'.format(APIDEMO_PKG_NAME))
135-
dd2 = self.driver.find_element(by=AppiumBy.ID, value='{}:id/drag_dot_2'.format(APIDEMO_PKG_NAME))
134+
dd3 = wait_for_element(self.driver, AppiumBy.ID, f'{APIDEMO_PKG_NAME}:id/drag_dot_3')
135+
dd2 = self.driver.find_element(by=AppiumBy.ID, value=f'{APIDEMO_PKG_NAME}:id/drag_dot_2')
136136

137137
# dnd is stimulated by longpress-move_to-release
138138
action.long_press(dd3).move_to(dd2).release().perform()
139139

140-
el = wait_for_element(self.driver, AppiumBy.ID, '{}:id/drag_result_text'.format(APIDEMO_PKG_NAME))
140+
el = wait_for_element(self.driver, AppiumBy.ID, f'{APIDEMO_PKG_NAME}:id/drag_result_text')
141141
assert 'Dropped!' in el.text
142142

143143
def test_driver_drag_and_drop(self) -> None:
@@ -147,12 +147,12 @@ def test_driver_drag_and_drop(self) -> None:
147147
el = wait_for_element(self.driver, AppiumBy.ACCESSIBILITY_ID, 'Drag and Drop')
148148
action.tap(el).perform()
149149

150-
dd3 = wait_for_element(self.driver, AppiumBy.ID, '{}:id/drag_dot_3'.format(APIDEMO_PKG_NAME))
151-
dd2 = self.driver.find_element(by=AppiumBy.ID, value='{}:id/drag_dot_2'.format(APIDEMO_PKG_NAME))
150+
dd3 = wait_for_element(self.driver, AppiumBy.ID, f'{APIDEMO_PKG_NAME}:id/drag_dot_3')
151+
dd2 = self.driver.find_element(by=AppiumBy.ID, value=f'{APIDEMO_PKG_NAME}:id/drag_dot_2')
152152

153153
self.driver.drag_and_drop(dd3, dd2)
154154

155-
el = wait_for_element(self.driver, AppiumBy.ID, '{}:id/drag_result_text'.format(APIDEMO_PKG_NAME))
155+
el = wait_for_element(self.driver, AppiumBy.ID, f'{APIDEMO_PKG_NAME}:id/drag_result_text')
156156
assert 'Dropped!' in el.text
157157

158158
def test_driver_swipe(self) -> None:

test/functional/android/webelement_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_send_keys(self) -> None:
4545
for text in ['App', 'Activity', 'Custom Title']:
4646
wait_for_element(self.driver, AppiumBy.XPATH, f"//android.widget.TextView[@text='{text}']").click()
4747

48-
el = wait_for_element(self.driver, AppiumBy.ID, '{}:id/left_text_edit'.format(APIDEMO_PKG_NAME))
48+
el = wait_for_element(self.driver, AppiumBy.ID, f'{APIDEMO_PKG_NAME}:id/left_text_edit')
4949
el.send_keys(' text')
5050

5151
assert 'Left is best text' == el.text

test/functional/ios/helper/desired_capabilities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def iphone_device_name() -> str:
7373
prefix = 'iPhone 12'
7474
if PytestXdistWorker.NUMBER == PytestXdistWorker.gw(0):
7575
return f'{prefix} - 8100'
76-
elif PytestXdistWorker.NUMBER == PytestXdistWorker.gw(1):
76+
if PytestXdistWorker.NUMBER == PytestXdistWorker.gw(1):
7777
return f'{prefix} - 8101'
7878

7979
return prefix

test/functional/ios/helper/test_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from . import desired_capabilities
2424

2525

26-
class BaseTestCase(object):
26+
class BaseTestCase():
2727
def setup_method(self) -> None:
2828
desired_caps = desired_capabilities.get_desired_capabilities('UICatalog.app.zip')
2929
self.driver = webdriver.Remote(SERVER_URL_BASE, options=XCUITestOptions().load_capabilities(desired_caps))

0 commit comments

Comments
 (0)