Skip to content

Commit 07097e1

Browse files
committed
formatting
1 parent 69e394c commit 07097e1

File tree

5 files changed

+31
-22
lines changed

5 files changed

+31
-22
lines changed

autoparaselenium/__init__.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@
77
from functools import partial, wraps
88
from typing import Iterable, List, Optional
99

10-
from autoparaselenium.browsers import chrome, firefox
1110
from autoparaselenium.browser_pool import BrowserPool
11+
from autoparaselenium.browsers import chrome, firefox
1212
from autoparaselenium.models import Conf, Extension
1313

14-
1514
_browser_pool: Optional[BrowserPool] = None
1615
all_ = [chrome, firefox]
1716

18-
_test_count = 0 # manual reference counting since threading borks with destructors
17+
_test_count = 0 # manual reference counting since threading borks with destructors
1918

2019

21-
def configure(*_, extensions: List[Extension] = [], headless=True, selenium_dir="drivers"):
20+
def configure(
21+
*_, extensions: List[Extension] = [], headless=True, selenium_dir="drivers"
22+
):
2223
global _browser_pool
2324

2425
if _browser_pool is not None:
@@ -37,7 +38,6 @@ def run_on(*browsers):
3738
if not browsers:
3839
raise TypeError("Please specify a browser or browser list to run on")
3940

40-
4141
if isinstance(browsers[0], Iterable):
4242
browsers = [*it.chain(*browsers)]
4343

@@ -70,25 +70,28 @@ def __wrap_test(browser, test):
7070
_test_count += 1
7171

7272
if _browser_pool is None:
73-
raise RuntimeError("Please call autoparaselenium.configure() before creating tests")
73+
raise RuntimeError(
74+
"Please call autoparaselenium.configure() before creating tests"
75+
)
7476

7577
def inner():
7678
global _test_count
7779

7880
try:
7981
_test_count -= 1
8082
driver = _browser_pool.acquire(browser)
81-
driver.get("data:,") # initialize driver website
83+
driver.get("data:,") # initialize driver website
8284
test(driver)
8385
finally:
8486
with suppress(Exception):
8587
_browser_pool.release(driver)
8688

8789
if _test_count == 0:
88-
time.sleep(0.10) # idk but seems like it needs a bit of time before you can close the pool
90+
time.sleep(
91+
0.10
92+
) # idk but seems like it needs a bit of time before you can close the pool
8993
_browser_pool.clean_up()
9094

91-
9295
inner.__name__ = f"{test.__name__}__{'chrome' if browser is chrome else 'firefox'}"
9396
inner.__doc__ = test.__doc__
9497

@@ -99,7 +102,7 @@ def __get_threads(args=sys.argv):
99102
if "--tests-per-worker" not in args:
100103
return 1
101104
tests_per_worker_idx = args.index("--tests-per-worker")
102-
next_arg = "".join(args[tests_per_worker_idx + 1: tests_per_worker_idx + 2])
105+
next_arg = "".join(args[tests_per_worker_idx + 1 : tests_per_worker_idx + 2])
103106
if next_arg == "auto":
104107
return os.cpu_count() // 2 + 1
105108
try:

autoparaselenium/browser_pool.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from concurrent.futures import ThreadPoolExecutor
22
from contextlib import suppress
3-
from threading import Lock
43
from queue import Queue
4+
from threading import Lock
55

66
from selenium import webdriver
77

8-
from autoparaselenium.models import Conf
98
from autoparaselenium.browsers import chrome, firefox
9+
from autoparaselenium.models import Conf
10+
1011

1112
class BrowserPool:
1213
def __init__(self, conf: Conf, threads: int):
@@ -23,27 +24,22 @@ def __init__(self, conf: Conf, threads: int):
2324
for driver in pool.map(self.__open_browser, [firefox] * threads):
2425
self._firefoxes.put(driver)
2526

26-
2727
def acquire(self, browser):
2828
return self.__get_queue(browser).get(browser)
2929

30-
3130
def release(self, driver):
3231
browser = chrome if isinstance(driver, webdriver.Chrome) else firefox
3332
self.__get_queue(browser).put(driver)
3433

35-
3634
def __get_queue(self, browser):
3735
return self._chromes if browser is chrome else self._firefoxes
3836

39-
4037
def __open_browser(self, browser):
4138
driver = browser.get_selenium(self._conf.selenium_dir, self._conf)
4239
with suppress(Exception):
4340
driver.switch_to.window("1")
4441
return driver
4542

46-
4743
def clean_up(self):
4844
for q in [self._chromes, self._firefoxes]:
4945
while not q.empty():

autoparaselenium/browsers/chrome.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ def setup_driver(pwd: Path) -> None:
9393
su.unzip,
9494
]
9595
for entry in (
96-
r.json()["milestones"][str(chrome_version)]
97-
["downloads"]["chromedriver"]
96+
r.json()["milestones"][str(chrome_version)]["downloads"][
97+
"chromedriver"
98+
]
9899
)
99100
}
100101
if (pwd / "chromedriver").exists():

autoparaselenium/models.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
from pathlib import Path
22
from typing import List, Optional
33

4+
45
class Extension:
5-
def __init__(self, *_, firefox: Optional[str]=None, chrome: Optional[str]=None):
6+
def __init__(self, *_, firefox: Optional[str] = None, chrome: Optional[str] = None):
67
self.firefox = firefox
78
self.chrome = chrome
89

910

1011
class Conf:
11-
def __init__(self, *_, extensions: List[Extension] = [], headless=True, selenium_dir="drivers"):
12+
def __init__(
13+
self,
14+
*_,
15+
extensions: List[Extension] = [],
16+
headless=True,
17+
selenium_dir="drivers",
18+
):
1219
self.extensions = extensions
1320
self.headless = headless
1421
self.selenium_dir = Path(selenium_dir)

autoparaselenium/setup_utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def setup_driver(platform_install, platform_drivers, pwd: Path) -> None:
4444
)
4545

4646

47-
def __download_and_extract(url: str, extract: Callable[[str, str], None], pwd: Path) -> None:
47+
def __download_and_extract(
48+
url: str, extract: Callable[[str, str], None], pwd: Path
49+
) -> None:
4850
download(url, pwd / "temp")
4951
extract(pwd / "temp", pwd)

0 commit comments

Comments
 (0)