diff --git a/appium/saucetestcase.py b/appium/saucetestcase.py index a2e94aba..754146fb 100644 --- a/appium/saucetestcase.py +++ b/appium/saucetestcase.py @@ -19,7 +19,7 @@ import os import sys import unittest -from typing import Any, Callable, List +from typing import Callable, List from sauceclient import SauceClient diff --git a/appium/webdriver/appium_service.py b/appium/webdriver/appium_service.py index 7683782a..d2aedadb 100644 --- a/appium/webdriver/appium_service.py +++ b/appium/webdriver/appium_service.py @@ -50,8 +50,7 @@ def poll_url(host: str, port: int, path: str, timeout_ms: int) -> bool: while time.time() < time_started_sec + timeout_ms / 1000.0: try: conn = urllib3.PoolManager(timeout=1.0) - resp = conn.request('HEAD', 'http://{host}:{port}{path}'.format( - host=host, port=port, path=path)) + resp = conn.request('HEAD', f'http://{host}:{port}{path}') if resp.status < 400: return True except Exception: @@ -67,7 +66,7 @@ class AppiumServiceError(RuntimeError): T = TypeVar('T', bound='AppiumService') -class AppiumService(object): +class AppiumService: def __init__(self) -> None: self._process: Optional[sp.Popen] = None self._cmd: Optional[List] = None @@ -169,13 +168,12 @@ def start(self, **kwargs: Any) -> sp.Popen: port = self._parse_port(args) error_msg: Optional[str] = None if not self.is_running or (timeout_ms > 0 and not poll_url(host, port, STATUS_URL, timeout_ms)): - error_msg = 'Appium has failed to start on {}:{} within {}ms timeout'\ - .format(host, port, timeout_ms) + error_msg = f'Appium has failed to start on {host}:{port} within {timeout_ms}ms timeout' if error_msg is not None: if stderr == sp.PIPE: err_output = self._process.stderr.read() if err_output: - error_msg += '\nOriginal error: {}'.format(str(err_output)) + error_msg += f'\nOriginal error: {str(err_output)}' self.stop() raise AppiumServiceError(error_msg) return self._process diff --git a/appium/webdriver/applicationstate.py b/appium/webdriver/applicationstate.py index e3c255ae..0658b264 100644 --- a/appium/webdriver/applicationstate.py +++ b/appium/webdriver/applicationstate.py @@ -13,7 +13,7 @@ # limitations under the License. -class ApplicationState(object): +class ApplicationState: NOT_INSTALLED = 0 NOT_RUNNING = 1 RUNNING_IN_BACKGROUND_SUSPENDED = 2 diff --git a/appium/webdriver/clipboard_content_type.py b/appium/webdriver/clipboard_content_type.py index 67aac351..7c1211b3 100644 --- a/appium/webdriver/clipboard_content_type.py +++ b/appium/webdriver/clipboard_content_type.py @@ -13,7 +13,7 @@ # limitations under the License. -class ClipboardContentType(object): +class ClipboardContentType: PLAINTEXT = 'plaintext' IMAGE = 'image' URL = 'url' diff --git a/appium/webdriver/common/multi_action.py b/appium/webdriver/common/multi_action.py index f3326534..e6a84cfe 100644 --- a/appium/webdriver/common/multi_action.py +++ b/appium/webdriver/common/multi_action.py @@ -31,7 +31,7 @@ T = TypeVar('T', bound='MultiAction') -class MultiAction(object): +class MultiAction: def __init__(self, driver: 'WebDriver', element: Optional['WebElement'] = None) -> None: self._driver = driver self._element = element diff --git a/appium/webdriver/common/touch_action.py b/appium/webdriver/common/touch_action.py index a8fb299d..a9544063 100644 --- a/appium/webdriver/common/touch_action.py +++ b/appium/webdriver/common/touch_action.py @@ -35,7 +35,7 @@ T = TypeVar('T', bound='TouchAction') -class TouchAction(object): +class TouchAction: def __init__(self, driver: Optional['WebDriver'] = None): self._driver = driver diff --git a/appium/webdriver/connectiontype.py b/appium/webdriver/connectiontype.py index 5a408ba5..7d477680 100644 --- a/appium/webdriver/connectiontype.py +++ b/appium/webdriver/connectiontype.py @@ -26,7 +26,7 @@ """ -class ConnectionType(object): +class ConnectionType: NO_CONNECTION = 0 AIRPLANE_MODE = 1 WIFI_ONLY = 2 diff --git a/appium/webdriver/extensions/android/display.py b/appium/webdriver/extensions/android/display.py index 73ac1ccb..f07c0875 100644 --- a/appium/webdriver/extensions/android/display.py +++ b/appium/webdriver/extensions/android/display.py @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import TypeVar - from selenium import webdriver from appium.webdriver.mobilecommand import MobileCommand as Command diff --git a/appium/webdriver/extensions/android/gsm.py b/appium/webdriver/extensions/android/gsm.py index df4ea95e..325ff573 100644 --- a/appium/webdriver/extensions/android/gsm.py +++ b/appium/webdriver/extensions/android/gsm.py @@ -21,14 +21,14 @@ from appium.webdriver.mobilecommand import MobileCommand as Command -class GsmCallActions(object): +class GsmCallActions: CALL = 'call' ACCEPT = 'accept' CANCEL = 'cancel' HOLD = 'hold' -class GsmSignalStrength(object): +class GsmSignalStrength: NONE_OR_UNKNOWN = 0 POOR = 1 MODERATE = 2 @@ -36,7 +36,7 @@ class GsmSignalStrength(object): GREAT = 4 -class GsmVoiceState(object): +class GsmVoiceState: UNREGISTERED = 'unregistered' HOME = 'home' ROAMING = 'roaming' @@ -66,8 +66,8 @@ def make_gsm_call(self, phone_number: str, action: str) -> T: """ constants = extract_const_attributes(GsmCallActions) if action not in constants.values(): - logger.warning('{} is unknown. Consider using one of {} constants. (e.g. {}.CALL)'.format( - action, list(constants.keys()), GsmCallActions.__name__)) + logger.warning( + f'{action} is unknown. Consider using one of {list(constants.keys())} constants. (e.g. {GsmCallActions.__name__}.CALL)') self.execute(Command.MAKE_GSM_CALL, {'phoneNumber': phone_number, 'action': action}) return self @@ -85,8 +85,8 @@ def set_gsm_signal(self, strength: int) -> T: """ constants = extract_const_attributes(GsmSignalStrength) if strength not in constants.values(): - logger.warning('{} is out of range. Consider using one of {} constants. (e.g. {}.GOOD)'.format( - strength, list(constants.keys()), GsmSignalStrength.__name__)) + logger.warning( + f'{strength} is out of range. Consider using one of {list(constants.keys())} constants. (e.g. {GsmSignalStrength.__name__}.GOOD)') self.execute(Command.SET_GSM_SIGNAL, {'signalStrength': strength, 'signalStrengh': strength}) return self @@ -104,8 +104,8 @@ def set_gsm_voice(self, state: str) -> T: """ constants = extract_const_attributes(GsmVoiceState) if state not in constants.values(): - logger.warning('{} is unknown. Consider using one of {} constants. (e.g. {}.HOME)'.format( - state, list(constants.keys()), GsmVoiceState.__name__)) + logger.warning( + f'{state} is unknown. Consider using one of {list(constants.keys())} constants. (e.g. {GsmVoiceState.__name__}.HOME)') self.execute(Command.SET_GSM_VOICE, {'state': state}) return self diff --git a/appium/webdriver/extensions/android/network.py b/appium/webdriver/extensions/android/network.py index 99c71763..4f874687 100644 --- a/appium/webdriver/extensions/android/network.py +++ b/appium/webdriver/extensions/android/network.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Any, TypeVar +from typing import TypeVar from selenium import webdriver @@ -23,7 +23,7 @@ T = TypeVar('T', bound='Network') -class NetSpeed(object): +class NetSpeed: GSM = 'gsm' # GSM/CSD (up: 14.4(kbps), down: 14.4(kbps)) SCSD = 'scsd' # HSCSD (up: 14.4, down: 57.6) GPRS = 'gprs' # GPRS (up: 28.8, down: 57.6) @@ -98,8 +98,8 @@ def set_network_speed(self, speed_type: str) -> T: """ constants = extract_const_attributes(NetSpeed) if speed_type not in constants.values(): - logger.warning('{} is unknown. Consider using one of {} constants. (e.g. {}.LTE)'.format( - speed_type, list(constants.keys()), NetSpeed.__name__)) + logger.warning( + f'{speed_type} is unknown. Consider using one of {list(constants.keys())} constants. (e.g. {NetSpeed.__name__}.LTE)') self.execute(Command.SET_NETWORK_SPEED, {'netspeed': speed_type}) return self diff --git a/appium/webdriver/extensions/clipboard.py b/appium/webdriver/extensions/clipboard.py index e4f7bc71..02e3f522 100644 --- a/appium/webdriver/extensions/clipboard.py +++ b/appium/webdriver/extensions/clipboard.py @@ -13,7 +13,7 @@ # limitations under the License. import base64 -from typing import Any, Dict, Optional, TypeVar +from typing import Optional, TypeVar from selenium import webdriver diff --git a/appium/webdriver/extensions/execute_driver.py b/appium/webdriver/extensions/execute_driver.py index f6c00fb0..3b3778c3 100644 --- a/appium/webdriver/extensions/execute_driver.py +++ b/appium/webdriver/extensions/execute_driver.py @@ -44,7 +44,7 @@ def execute_driver(self, script: str, script_type: str = 'webdriverio', timeout_ WebDriverException: If something error happenes in the script. The message has the original error message. """ - class Result(object): + class Result: def __init__(self, response: Dict): self.result = response['result'] diff --git a/appium/webdriver/extensions/location.py b/appium/webdriver/extensions/location.py index 054cf44e..4af21de9 100644 --- a/appium/webdriver/extensions/location.py +++ b/appium/webdriver/extensions/location.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Dict, Optional, TypeVar, Union +from typing import Dict, TypeVar, Union from selenium import webdriver diff --git a/appium/webdriver/extensions/remote_fs.py b/appium/webdriver/extensions/remote_fs.py index dd256a7a..4f8ff871 100644 --- a/appium/webdriver/extensions/remote_fs.py +++ b/appium/webdriver/extensions/remote_fs.py @@ -74,7 +74,7 @@ def push_file(self, destination_path: str, with open(source_path, 'rb') as f: file_data = f.read() except IOError: - message = 'source_path {} could not be found. Are you sure the file exists?'.format(source_path) + message = f'source_path "{source_path}" could not be found. Are you sure the file exists?' raise InvalidArgumentException(message) base64data = base64.b64encode(file_data).decode('utf-8') diff --git a/appium/webdriver/extensions/search_context/base_search_context.py b/appium/webdriver/extensions/search_context/base_search_context.py index 404aa62a..317069f0 100644 --- a/appium/webdriver/extensions/search_context/base_search_context.py +++ b/appium/webdriver/extensions/search_context/base_search_context.py @@ -14,13 +14,13 @@ # pylint: disable=abstract-method -from typing import TYPE_CHECKING, Dict, List, Optional, Union +from typing import TYPE_CHECKING, Dict, List, Union if TYPE_CHECKING: from appium.webdriver.webelement import WebElement -class BaseSearchContext(object): +class BaseSearchContext: """Used by each search context. Dummy find_element/s are for preventing pylint error""" def find_element(self, by: str, value: Union[str, Dict] = None) -> 'WebElement': diff --git a/appium/webdriver/mobilecommand.py b/appium/webdriver/mobilecommand.py index f6d90679..b0bd8c4d 100644 --- a/appium/webdriver/mobilecommand.py +++ b/appium/webdriver/mobilecommand.py @@ -13,7 +13,7 @@ # limitations under the License. -class MobileCommand(object): +class MobileCommand: # Common GET_SESSION = 'getSession' GET_ALL_SESSIONS = 'getAllSessions' diff --git a/appium/webdriver/webdriver.py b/appium/webdriver/webdriver.py index 13e9619f..3a0512bc 100644 --- a/appium/webdriver/webdriver.py +++ b/appium/webdriver/webdriver.py @@ -193,12 +193,7 @@ def _update_command_executor(self, keep_alive: bool) -> None: hostname = self.capabilities[direct_host] port = self.capabilities[direct_port] path = self.capabilities[direct_path] - executor = '{scheme}://{hostname}:{port}{path}'.format( - scheme=protocol, - hostname=hostname, - port=port, - path=path - ) + executor = f'{protocol}://{hostname}:{port}{path}' logger.info('Updated request endpoint to %s', executor) # Override command executor diff --git a/test/functional/android/common_tests.py b/test/functional/android/common_tests.py index cf5ea791..04fb63e8 100644 --- a/test/functional/android/common_tests.py +++ b/test/functional/android/common_tests.py @@ -44,7 +44,7 @@ def test_open_notifications(self): self.skipTest('Need to fix flaky test during running on CI.') for word in ['App', 'Notification', 'Status Bar', ':-|']: wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR, - 'new UiSelector().text("{}")'.format(word)).click() + f'new UiSelector().text("{word}")').click() self.driver.open_notifications() sleep(1) diff --git a/test/functional/android/ime_tests.py b/test/functional/android/ime_tests.py index 86bf7449..6cac0e73 100644 --- a/test/functional/android/ime_tests.py +++ b/test/functional/android/ime_tests.py @@ -37,7 +37,6 @@ def test_active_ime_engine(self): def test_activate_ime_engine(self): engines = self.driver.available_ime_engines - active_engine = self.driver.active_ime_engine self.driver.activate_ime_engine(engines[-1]) self.assertEqual(self.driver.active_ime_engine, engines[-1]) diff --git a/test/functional/android/log_event_tests.py b/test/functional/android/log_event_tests.py index 8067e9f7..a64ff9a0 100644 --- a/test/functional/android/log_event_tests.py +++ b/test/functional/android/log_event_tests.py @@ -23,7 +23,7 @@ def test_log_event(self): vendor = 'appium' event = 'funEvent' self.driver.log_event(vendor, event) - assert '{}:{}'.format(vendor, event) in self.driver.get_events().keys() + assert f'{vendor}:{event}' in self.driver.get_events().keys() if __name__ == '__main__': diff --git a/test/functional/android/webelement_tests.py b/test/functional/android/webelement_tests.py index 1a16473b..b936ffc4 100644 --- a/test/functional/android/webelement_tests.py +++ b/test/functional/android/webelement_tests.py @@ -47,7 +47,7 @@ def test_set_text(self): def test_send_keys(self): for text in ['App', 'Activity', 'Custom Title']: wait_for_element(self.driver, MobileBy.XPATH, - "//android.widget.TextView[@text='{}']".format(text)).click() + f"//android.widget.TextView[@text='{text}']").click() el = wait_for_element(self.driver, MobileBy.ID, '{}:id/left_text_edit'.format(APIDEMO_PKG_NAME)) el.send_keys(' text') diff --git a/test/functional/ios/helper/desired_capabilities.py b/test/functional/ios/helper/desired_capabilities.py index 7a98f61a..12dc982a 100644 --- a/test/functional/ios/helper/desired_capabilities.py +++ b/test/functional/ios/helper/desired_capabilities.py @@ -41,7 +41,7 @@ def get_desired_capabilities(app=None): return desired_caps -class PytestXdistWorker(object): +class PytestXdistWorker: NUMBER = os.getenv('PYTEST_XDIST_WORKER') COUNT = os.getenv('PYTEST_XDIST_WORKER_COUNT') # Return 2 if `-n 2` is passed @@ -53,7 +53,7 @@ def gw(number): if number >= PytestXdistWorker.COUNT: return 'gw0' - return 'gw{}'.format(number) + return f'gw{number}' # If you run tests with pytest-xdist, you can run tests in parallel. diff --git a/test/functional/ios/webdriver_tests.py b/test/functional/ios/webdriver_tests.py index 51c7bc58..3d0f113f 100644 --- a/test/functional/ios/webdriver_tests.py +++ b/test/functional/ios/webdriver_tests.py @@ -36,7 +36,7 @@ def test_all_sessions(self): desired_caps['deviceName'] = 'iPhone Xs Max' desired_caps['wdaLocalPort'] = port - class session_counts_is_two(object): + class session_counts_is_two: TIMEOUT = 10 def __call__(self, driver): diff --git a/test/functional/test_helper.py b/test/functional/test_helper.py index a531d053..ee6b6daf 100644 --- a/test/functional/test_helper.py +++ b/test/functional/test_helper.py @@ -20,8 +20,7 @@ def get_available_from_port_range(from_port, to_port): finally: sock.close() - raise NoAvailablePortError('No available port between {} and {}'.format( - from_port, to_port)) + raise NoAvailablePortError(f'No available port between {from_port} and {to_port}') def is_ci(): diff --git a/test/unit/helper/test_helper.py b/test/unit/helper/test_helper.py index f7ff3ca0..4c1b2d07 100644 --- a/test/unit/helper/test_helper.py +++ b/test/unit/helper/test_helper.py @@ -28,7 +28,7 @@ def appium_command(command): Returns: str: A string of command URL """ - return '{}{}'.format(SERVER_URL_BASE, command) + return f'{SERVER_URL_BASE}{command}' def android_w3c_driver():