Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*._*
*.log
*.log.*
_*/

*.pyc
*.egg-info
Expand All @@ -14,10 +15,12 @@ MANIFEST
build
dist

# Cache
.cache
__pycache__
.idea
.pytest_cache
.mypy_cache

# Virtual Environments
venv*
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@
hooks:
- id: isort
args: ["-rc", "."]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.761'
hooks:
- id: mypy
entry: mypy appium/ test/
pass_filenames: false
6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ language: python
dist: xenial

python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
# - "3.8-dev" # TODO Remove comment-out when pylint and astroid upgraded to the latest and py2 support dropped
- "3.8"

install:
- pip install tox-travis
Expand Down
13 changes: 7 additions & 6 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
pre-commit = "~=1.13"
pre-commit = "~=2.1"

[packages]
selenium = "~=3.141"

autopep8 = "~=1.5"

pytest = "~=4.0"
pytest = "~=5.3"
pytest-cov = "~=2.8"

tox = "~=3.14"
tox-travis = "~=0.12"

httpretty = "~=0.9"
python-dateutil = "~=2.8"
mock = "~=3.0"
mock = "~=4.0"

# TODO Update to the latest ver when py2 support dropped
pylint = "~=1.9"
astroid = "~=1.6"
pylint = "~=2.4"
astroid = "~=2.3"
isort = "~=4.3"

mypy = "==0.761"
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,18 @@ download and unarchive the source tarball (Appium-Python-Client-X.X.tar.gz).

- Style Guide: https://www.python.org/dev/peps/pep-0008/
- `autopep8` helps to format code automatically
```
```shell
$ python -m autopep8 -r --global-config .config-pep8 -i .
```
- `isort` helps to order imports automatically
```
```shell
$ python -m isort -rc .
```
- When you use newly 3rd party modules, add it to [.isort.cfg](.isort.cfg) to keep import order correct
- `mypy` helps to check explicit type declarations
```shell
$ python -m mypy appium
```
- Docstring style: Google Style
- Refer [link](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html)
- You can customise `CHANGELOG.rst` with commit messages following [.gitchangelog.rc](.gitchangelog.rc)
Expand Down
31 changes: 6 additions & 25 deletions appium/common/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,25 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from collections import OrderedDict
from typing import Any, Dict

from appium import version as appium_version


def appium_bytes(value, encoding):
"""Return a bytes-like object

Has _appium_ prefix to avoid overriding built-in bytes.

Args:
value (str): A value to convert
encoding (str): A encoding which will convert to

Returns:
str: A bytes-like object
"""

try:
return bytes(value, encoding) # Python 3
except TypeError:
return value # Python 2


def extract_const_attributes(cls):
def extract_const_attributes(cls: type) -> Dict[str, Any]:
"""Return dict with constants attributes and values in the class(e.g. {'VAL1': 1, 'VAL2': 2})

Args:
cls (type): Class to be extracted constants

Returns:
OrderedDict: dict with constants attributes and values in the class
dict: dict with constants attributes and values in the class
"""
return OrderedDict(
[(attr, value) for attr, value in vars(cls).items() if not callable(getattr(cls, attr)) and attr.isupper()])
return dict([(attr, value) for attr, value in vars(cls).items()
if not callable(getattr(cls, attr)) and attr.isupper()])


def library_version():
def library_version() -> str:
"""Return a version of this python library
"""

Expand Down
2 changes: 1 addition & 1 deletion appium/common/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import sys


def setup_logger(level=logging.NOTSET):
def setup_logger(level: int = logging.NOTSET) -> None:
logger.propagate = False
logger.setLevel(level)
handler = logging.StreamHandler(stream=sys.stderr)
Expand Down
13 changes: 7 additions & 6 deletions appium/saucetestcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import os
import sys
import unittest
from typing import Callable, List

from sauceclient import SauceClient

Expand All @@ -29,8 +30,8 @@
sauce = SauceClient(SAUCE_USERNAME, SAUCE_ACCESS_KEY)


def on_platforms(platforms):
def decorator(base_class):
def on_platforms(platforms: List[str]) -> Callable[[type], None]:
def decorator(base_class: type) -> None:
module = sys.modules[base_class.__module__].__dict__
for i, platform in enumerate(platforms):
name = "%s_%s" % (base_class.__name__, i + 1)
Expand All @@ -40,16 +41,16 @@ def decorator(base_class):


class SauceTestCase(unittest.TestCase):
def setUp(self):
self.desired_capabilities['name'] = self.id()
def setUp(self) -> None:
self.desired_capabilities['name'] = self.id() # type: ignore
sauce_url = "http://%s:%s@ondemand.saucelabs.com:80/wd/hub"
self.driver = webdriver.Remote(
desired_capabilities=self.desired_capabilities,
desired_capabilities=self.desired_capabilities, # type: ignore
command_executor=sauce_url % (SAUCE_USERNAME, SAUCE_ACCESS_KEY)
)
self.driver.implicitly_wait(30)

def tearDown(self):
def tearDown(self) -> None:
print("Link to your job: https://saucelabs.com/jobs/%s" % self.driver.session_id)
try:
if sys.exc_info() == (None, None, None):
Expand Down
6 changes: 5 additions & 1 deletion appium/webdriver/appium_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@
# limitations under the License.

import uuid
from typing import TYPE_CHECKING, Any, Dict

from selenium.webdriver.remote.remote_connection import RemoteConnection

from appium.common.helper import library_version

if TYPE_CHECKING:
from urllib.parse import ParseResult


class AppiumConnection(RemoteConnection):

@classmethod
def get_remote_connection_headers(cls, parsed_url, keep_alive=True):
def get_remote_connection_headers(cls, parsed_url: 'ParseResult', keep_alive: bool = True) -> Dict[str, Any]:
"""Override get_remote_connection_headers in RemoteConnection"""
headers = RemoteConnection.get_remote_connection_headers(parsed_url, keep_alive=keep_alive)
headers['User-Agent'] = 'appium/python {} ({})'.format(library_version(), headers['User-Agent'])
Expand Down
Loading