Skip to content

Commit 344953a

Browse files
authored
chore: Apply Black code formatter (appium#571)
* Applied black (length: 120, String skipped) * Updated related to ci * Update README
1 parent e51bcd2 commit 344953a

File tree

97 files changed

+706
-1007
lines changed

Some content is hidden

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

97 files changed

+706
-1007
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
- repo: https://github.com/pre-commit/mirrors-autopep8
2-
rev: v1.5.4
3-
hooks:
4-
- id: autopep8
5-
args: ["-a", "-i"]
61
- repo: https://github.com/pre-commit/mirrors-isort
72
rev: v4.3.21
83
hooks:
@@ -14,3 +9,8 @@
149
- id: mypy
1510
entry: mypy appium/ test/
1611
pass_filenames: false
12+
- repo: https://github.com/psf/black
13+
rev: 20.8b1
14+
hooks:
15+
- id: black
16+
args: [".", "-l", "120", "-S"]

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ check-all: ## Run all lint checks and unittest
99
isort: ## Run isort
1010
python -m isort $(ARGS) -rc .
1111

12-
.PHONY: autopep8
13-
autopep8: ## Run autopep8
14-
python -m autopep8 $(ARGS) -a -r -i .
12+
.PHONY: black
13+
black: ## Run black
14+
python -m black $(ARGS) . -l 120 -S
1515

1616
.PHONY: pylint
1717
pylint: ## Run pylint

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pre-commit = "~=2.6"
99
[packages]
1010
selenium = "~=3.141"
1111

12-
autopep8 = "~=1.5"
12+
black = "==20.8b1"
1313

1414
pytest = "~=6.0"
1515
pytest-cov = "~=2.10"

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
[![Build Status](https://travis-ci.org/appium/python-client.svg?branch=master)](https://travis-ci.org/appium/python-client)
77
[![Build Status](https://dev.azure.com/AppiumCI/Appium%20CI/_apis/build/status/appium.python-client?branchName=master)](https://dev.azure.com/AppiumCI/Appium%20CI/_build/latest?definitionId=56&branchName=master)
88

9+
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
10+
911
An extension library for adding [Selenium 3.0 draft](https://dvcs.w3.org/hg/webdriver/raw-file/tip/webdriver-spec.html) and [Mobile JSON Wire Protocol Specification draft](https://github.com/SeleniumHQ/mobile-spec/blob/master/spec-draft.md)
1012
functionality to the Python language bindings, for use with the mobile testing
1113
framework [Appium](https://appium.io).
@@ -139,7 +141,7 @@ https://appium.github.io/python-client-sphinx/ is detailed documentation
139141
## Development
140142

141143
- Code Style: [PEP-0008](https://www.python.org/dev/peps/pep-0008/)
142-
- Apply `autopep8`, `isort` and `mypy` as pre commit hook
144+
- Apply `black`, `isort` and `mypy` as pre commit hook
143145
- Run `make` command for development. See `make help` output for details
144146
- Docstring style: [Google Style](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html)
145147
- `gitchangelog` generates `CHANGELOG.rst`

appium/common/exceptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ class NoSuchContextException(InvalidSwitchToTargetException):
2424
print(driver.contexts)
2525
2626
"""
27+
2728
pass

appium/common/helper.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ def extract_const_attributes(cls: type) -> Dict[str, Any]:
2626
Returns:
2727
dict with constants attributes and values in the class
2828
"""
29-
return dict([(attr, value) for attr, value in vars(cls).items()
30-
if not callable(getattr(cls, attr)) and attr.isupper()])
29+
return dict(
30+
[(attr, value) for attr, value in vars(cls).items() if not callable(getattr(cls, attr)) and attr.isupper()]
31+
)
3132

3233

3334
def library_version() -> str:
34-
"""Return a version of this python library
35-
"""
35+
"""Return a version of this python library"""
3636

3737
return appium_version.version

appium/webdriver/appium_connection.py

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

2525

2626
class AppiumConnection(RemoteConnection):
27-
2827
@classmethod
2928
def get_remote_connection_headers(cls, parsed_url: 'ParseResult', keep_alive: bool = True) -> Dict[str, Any]:
3029
"""Override get_remote_connection_headers in RemoteConnection"""

appium/webdriver/appium_service.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,18 @@ def _get_node(self) -> str:
7272
if not hasattr(self, '_node_executable'):
7373
self._node_executable = find_executable('node')
7474
if self._node_executable is None:
75-
raise AppiumServiceError('NodeJS main executable cannot be found. ' +
76-
'Make sure it is installed and present in PATH')
75+
raise AppiumServiceError(
76+
'NodeJS main executable cannot be found. ' + 'Make sure it is installed and present in PATH'
77+
)
7778
return self._node_executable
7879

7980
def _get_npm(self) -> str:
8081
if not hasattr(self, '_npm_executable'):
8182
self._npm_executable = find_executable('npm.cmd' if sys.platform == 'win32' else 'npm')
8283
if self._npm_executable is None:
83-
raise AppiumServiceError('Node Package Manager executable cannot be found. ' +
84-
'Make sure it is installed and present in PATH')
84+
raise AppiumServiceError(
85+
'Node Package Manager executable cannot be found. ' + 'Make sure it is installed and present in PATH'
86+
)
8587
return self._npm_executable
8688

8789
def _get_main_script(self) -> Union[str, bytes]:
@@ -97,9 +99,8 @@ def _get_main_script(self) -> Union[str, bytes]:
9799
if not hasattr(self, '_main_script'):
98100
try:
99101
self._main_script = sp.check_output(
100-
[self._get_node(),
101-
'-e',
102-
'console.log(require.resolve("{}"))'.format(MAIN_SCRIPT_PATH)]).strip()
102+
[self._get_node(), '-e', 'console.log(require.resolve("{}"))'.format(MAIN_SCRIPT_PATH)]
103+
).strip()
103104
except sp.CalledProcessError as e:
104105
raise AppiumServiceError(e.output) from e
105106
return self._main_script
@@ -221,13 +222,13 @@ def is_listening(self) -> bool:
221222

222223

223224
if __name__ == '__main__':
224-
assert(find_executable('node') is not None)
225-
assert(find_executable('npm') is not None)
225+
assert find_executable('node') is not None
226+
assert find_executable('npm') is not None
226227
service = AppiumService()
227228
service.start(args=['--address', '127.0.0.1', '-p', str(DEFAULT_PORT)])
228229
# service.start(args=['--address', '127.0.0.1', '-p', '80'], timeout_ms=2000)
229230
assert service.is_running
230231
assert service.is_listening
231232
service.stop()
232-
assert(not service.is_running)
233-
assert(not service.is_listening)
233+
assert not service.is_running
234+
assert not service.is_listening

appium/webdriver/common/touch_action.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,17 @@
3636

3737

3838
class TouchAction:
39-
4039
def __init__(self, driver: Optional['WebDriver'] = None):
4140
self._driver = driver
4241
self._actions: List = []
4342

44-
def tap(self: T, element: Optional['WebElement'] = None, x: Optional[int]
45-
= None, y: Optional[int] = None, count: int = 1) -> T:
43+
def tap(
44+
self: T,
45+
element: Optional['WebElement'] = None,
46+
x: Optional[int] = None,
47+
y: Optional[int] = None,
48+
count: int = 1,
49+
) -> T:
4650
"""Perform a tap action on the element
4751
4852
Args:
@@ -59,8 +63,13 @@ def tap(self: T, element: Optional['WebElement'] = None, x: Optional[int]
5963

6064
return self
6165

62-
def press(self: T, el: Optional['WebElement'] = None, x: Optional[int] = None,
63-
y: Optional[int] = None, pressure: Optional[float] = None) -> T:
66+
def press(
67+
self: T,
68+
el: Optional['WebElement'] = None,
69+
x: Optional[int] = None,
70+
y: Optional[int] = None,
71+
pressure: Optional[float] = None,
72+
) -> T:
6473
"""Begin a chain with a press down action at a particular element or point
6574
6675
Args:
@@ -77,8 +86,13 @@ def press(self: T, el: Optional['WebElement'] = None, x: Optional[int] = None,
7786

7887
return self
7988

80-
def long_press(self: T, el: Optional['WebElement'] = None, x: Optional[int]
81-
= None, y: Optional[int] = None, duration: int = 1000) -> T:
89+
def long_press(
90+
self: T,
91+
el: Optional['WebElement'] = None,
92+
x: Optional[int] = None,
93+
y: Optional[int] = None,
94+
duration: int = 1000,
95+
) -> T:
8296
"""Begin a chain with a press down that lasts `duration` milliseconds
8397
8498
Args:
@@ -167,8 +181,14 @@ def _add_action(self, action: str, options: Dict) -> None:
167181
}
168182
self._actions.append(gesture)
169183

170-
def _get_opts(self, el: Optional['WebElement'] = None, x: Optional[int] = None, y: Optional[int] = None,
171-
duration: Optional[int] = None, pressure: Optional[float] = None) -> Dict[str, Union[int, float]]:
184+
def _get_opts(
185+
self,
186+
el: Optional['WebElement'] = None,
187+
x: Optional[int] = None,
188+
y: Optional[int] = None,
189+
duration: Optional[int] = None,
190+
pressure: Optional[float] = None,
191+
) -> Dict[str, Union[int, float]]:
172192
opts = {}
173193
if el is not None:
174194
opts['element'] = el.id

appium/webdriver/extensions/action_helpers.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929

3030
class ActionHelpers(webdriver.Remote):
31-
3231
def scroll(self: T, origin_el: WebElement, destination_el: WebElement, duration: Optional[int] = None) -> T:
3332
"""Scrolls from one element to another
3433
@@ -128,11 +127,7 @@ def swipe(self: T, start_x: int, start_y: int, end_x: int, end_y: int, duration:
128127
# `swipe` is something like press-wait-move_to-release, which the server
129128
# will translate into the correct action
130129
action = TouchAction(self)
131-
action \
132-
.press(x=start_x, y=start_y) \
133-
.wait(ms=duration) \
134-
.move_to(x=end_x, y=end_y) \
135-
.release()
130+
action.press(x=start_x, y=start_y).wait(ms=duration).move_to(x=end_x, y=end_y).release()
136131
action.perform()
137132
return self
138133

@@ -152,9 +147,6 @@ def flick(self: T, start_x: int, start_y: int, end_x: int, end_y: int) -> T:
152147
Union['WebDriver', 'ActionHelpers']: Self instance
153148
"""
154149
action = TouchAction(self)
155-
action \
156-
.press(x=start_x, y=start_y) \
157-
.move_to(x=end_x, y=end_y) \
158-
.release()
150+
action.press(x=start_x, y=start_y).move_to(x=end_x, y=end_y).release()
159151
action.perform()
160152
return self

0 commit comments

Comments
 (0)